Documentation
¶
Overview ¶
Package pphttp instruments Go standard HTTP library.
This package instruments inbound requests handled by a http.ServeMux. Use NewServeMux to trace all handlers:
mux := pphttp.NewServeMux() mux.HandleFunc("/bar", outGoing)
Use WrapHandler or WrapHandlerFunc to select the handlers you want to track:
http.HandleFunc("/", pphttp.WrapHandlerFunc(index))
This package instruments outbound requests and add distributed tracing headers. Use WrapClient, WrapClientWithContext or DoClient.
client := pphttp.WrapClient(&http.Client{}) client.Get(external_url)
or
req, _ := http.NewRequestWithContext(ctx, "GET", url, nil) pphttp.DoClient(http.DefaultClient.Do, req)
Index ¶
- Constants
- func CollectUrlStat(tracer pinpoint.Tracer, url string, method string, status int)
- func DoClient(doFunc func(req *http.Request) (*http.Response, error), req *http.Request) (*http.Response, error)
- func EndHttpClientTracer(tracer pinpoint.Tracer, resp *http.Response, err error)
- func HandlerFuncName(f interface{}) string
- func NewHttpClientTracer(tracer pinpoint.Tracer, operationName string, req *http.Request) pinpoint.Tracer
- func NewHttpServerTracer(req *http.Request, operation string) (tracer pinpoint.Tracer)
- func NewServeMux() *serveMux
- func RecordClientHttpCookie(annotation pinpoint.Annotation, cookie Cookie)
- func RecordClientHttpRequestHeader(annotation pinpoint.Annotation, header Header)
- func RecordClientHttpResponseHeader(annotation pinpoint.Annotation, header Header)
- func RecordHttpHandlerError(tracer pinpoint.Tracer, err error)
- func RecordHttpServerResponse(tracer pinpoint.Tracer, status int, h http.Header)
- func WithHttpClientRecordRequestCookie(cookie []string) pinpoint.ConfigOption
- func WithHttpClientRecordRequestHeader(header []string) pinpoint.ConfigOption
- func WithHttpClientRecordRespondHeader(header []string) pinpoint.ConfigOption
- func WithHttpServerExcludeMethod(method []string) pinpoint.ConfigOption
- func WithHttpServerExcludeUrl(urlPath []string) pinpoint.ConfigOption
- func WithHttpServerRecordHandlerError(record bool) pinpoint.ConfigOption
- func WithHttpServerRecordRequestCookie(cookie []string) pinpoint.ConfigOption
- func WithHttpServerRecordRequestHeader(header []string) pinpoint.ConfigOption
- func WithHttpServerRecordRespondHeader(header []string) pinpoint.ConfigOption
- func WithHttpServerStatusCodeError(errors []string) pinpoint.ConfigOption
- func WrapClient(client *http.Client) *http.Client
- func WrapClientWithContext(ctx context.Context, client *http.Client) *http.Client
- func WrapHandle(agent pinpoint.Agent, handlerName string, pattern string, handler http.Handler) (string, http.Handler)
- func WrapHandleFunc(agent pinpoint.Agent, handlerName string, pattern string, ...) (string, func(http.ResponseWriter, *http.Request))
- func WrapHandler(handler http.Handler, serverName ...string) http.Handler
- func WrapHandlerFunc(handler func(http.ResponseWriter, *http.Request), serverName ...string) func(http.ResponseWriter, *http.Request)
- func WrapResponseWriter(w http.ResponseWriter, status *int) *responseWriter
- type Cookie
- type Header
Constants ¶
const ( CfgHttpServerStatusCodeErrors = "Http.Server.StatusCodeErrors" CfgHttpServerExcludeUrl = "Http.Server.ExcludeUrl" CfgHttpServerExcludeMethod = "Http.Server.ExcludeMethod" CfgHttpServerRecordRequestHeader = "Http.Server.RecordRequestHeader" CfgHttpServerRecordResponseHeader = "Http.Server.RecordResponseHeader" CfgHttpServerRecordRequestCookie = "Http.Server.RecordRequestCookie" CfgHttpServerRecordHandlerError = "Http.Server.RecordHandlerError" CfgHttpClientRecordRequestHeader = "Http.Client.RecordRequestHeader" CfgHttpClientRecordResponseHeader = "Http.Client.RecordResponseHeader" CfgHttpClientRecordRequestCookie = "Http.Client.RecordRequestCookie" )
Variables ¶
This section is empty.
Functions ¶
func CollectUrlStat ¶ added in v1.3.0
CollectUrlStat collects HTTP URL statistics.
func DoClient ¶
func DoClient(doFunc func(req *http.Request) (*http.Response, error), req *http.Request) (*http.Response, error)
DoClient instruments and executes a given doFunc. It is necessary to pass the context containing the pinpoint.Tracer to the http.Request.
req, _ := http.NewRequestWithContext(pinpoint.NewContext(context.Background(), tracer), "GET", url, nil) pphttp.DoClient(http.DefaultClient.Do, req)
func EndHttpClientTracer ¶
EndHttpClientTracer is deprecated.
func HandlerFuncName ¶
func HandlerFuncName(f interface{}) string
HandlerFuncName returns the name of handler function.
func NewHttpClientTracer ¶
func NewHttpClientTracer(tracer pinpoint.Tracer, operationName string, req *http.Request) pinpoint.Tracer
NewHttpClientTracer is deprecated. Use WrapClient or DoClient.
func NewHttpServerTracer ¶
NewHttpServerTracer returns a pinpoint.Tracer that instruments the request handler for http server. The tracer extracts the pinpoint header from the http request header, and then creates a span that initiates or continues the transaction.
func NewServeMux ¶
func NewServeMux() *serveMux
NewServeMux wraps http.NewServeMux and returns a http.ServeMux ready to instrument.
func RecordClientHttpCookie ¶
func RecordClientHttpCookie(annotation pinpoint.Annotation, cookie Cookie)
func RecordClientHttpRequestHeader ¶
func RecordClientHttpRequestHeader(annotation pinpoint.Annotation, header Header)
func RecordClientHttpResponseHeader ¶
func RecordClientHttpResponseHeader(annotation pinpoint.Annotation, header Header)
func RecordHttpHandlerError ¶ added in v1.4.4
func RecordHttpHandlerError(tracer pinpoint.Tracer, err error)
RecordHttpHandlerError records error returned by http handler.
func RecordHttpServerResponse ¶
RecordHttpServerResponse records http status and response header to span.
func WithHttpClientRecordRequestCookie ¶
func WithHttpClientRecordRequestCookie(cookie []string) pinpoint.ConfigOption
WithHttpClientRecordRequestCookie sets HTTP request cookies to be logged on the client side. If sets to HEADERS-ALL, it records all request cookies.
pphttp.WithHttpClientRecordRequestCookie([]string{"HEADERS-ALL"})
or
pphttp.WithHttpClientRecordRequestCookie([]string{"foo", "bar"})
func WithHttpClientRecordRequestHeader ¶
func WithHttpClientRecordRequestHeader(header []string) pinpoint.ConfigOption
WithHttpClientRecordRequestHeader sets HTTP request headers to be logged on the client side. If sets to HEADERS-ALL, it records all request headers.
pphttp.WithHttpClientRecordRequestHeader([]string{"HEADERS-ALL"})
or
pphttp.WithHttpClientRecordRequestHeader([]string{"foo", "bar"})
func WithHttpClientRecordRespondHeader ¶
func WithHttpClientRecordRespondHeader(header []string) pinpoint.ConfigOption
WithHttpClientRecordRespondHeader sets HTTP response headers to be logged on the client side. If sets to HEADERS-ALL, it records all response headers.
pphttp.WithHttpClientRecordRespondHeader([]string{"HEADERS-ALL"})
or
pphttp.WithHttpClientRecordRespondHeader([]string{"foo", "bar"})
func WithHttpServerExcludeMethod ¶
func WithHttpServerExcludeMethod(method []string) pinpoint.ConfigOption
WithHttpServerExcludeMethod sets HTTP Request methods to exclude from tracking.
pphttp.WithHttpServerExcludeMethod([]string{"put", "delete"})
func WithHttpServerExcludeUrl ¶
func WithHttpServerExcludeUrl(urlPath []string) pinpoint.ConfigOption
WithHttpServerExcludeUrl sets URLs to exclude from tracking. It supports ant style pattern. e.g. /aa/*.html, /??/exclude.html
pphttp.WithHttpServerExcludeUrl([]string{"/wrap_*", "/**/*.do"})
func WithHttpServerRecordHandlerError ¶ added in v1.4.4
func WithHttpServerRecordHandlerError(record bool) pinpoint.ConfigOption
WithHttpServerRecordHandlerError sets whether to record the error returned by http handler.
pphttp.WithHttpServerRecordHandlerError(false)
func WithHttpServerRecordRequestCookie ¶
func WithHttpServerRecordRequestCookie(cookie []string) pinpoint.ConfigOption
WithHttpServerRecordRequestCookie sets HTTP request cookies to be logged on the server side. If sets to HEADERS-ALL, it records all request cookies.
pphttp.WithHttpServerRecordRequestCookie([]string{"HEADERS-ALL"})
or
pphttp.WithHttpServerRecordRequestCookie([]string{"foo", "bar"})
func WithHttpServerRecordRequestHeader ¶
func WithHttpServerRecordRequestHeader(header []string) pinpoint.ConfigOption
WithHttpServerRecordRequestHeader sets HTTP request headers to be logged on the server side. If sets to HEADERS-ALL, it records all request headers.
pphttp.WithHttpServerRecordRequestHeader([]string{"HEADERS-ALL"})
or
pphttp.WithHttpServerRecordRequestHeader([]string{"foo", "bar"})
func WithHttpServerRecordRespondHeader ¶
func WithHttpServerRecordRespondHeader(header []string) pinpoint.ConfigOption
WithHttpServerRecordRespondHeader sets HTTP response headers to be logged on the server side. If sets to HEADERS-ALL, it records all response headers.
pphttp.WithHttpServerRecordRespondHeader([]string{"HEADERS-ALL"})
or
pphttp.WithHttpServerRecordRespondHeader([]string{"foo", "bar", "set-cookie"})
func WithHttpServerStatusCodeError ¶
func WithHttpServerStatusCodeError(errors []string) pinpoint.ConfigOption
WithHttpServerStatusCodeError sets HTTP status code with request failure.
pphttp.WithHttpServerStatusCodeError([]string{"5xx", "4xx", "302"})
func WrapClient ¶
WrapClient returns a new *http.Client ready to instrument. It is necessary to pass the context containing the pinpoint.Tracer to the http.Request.
req, _ := http.NewRequestWithContext(pinpoint.NewContext(context.Background(), tracer), "GET", url, nil) client := pphttp.WrapClient(&http.Client{}) client.Do(req)
func WrapClientWithContext ¶
WrapClientWithContext returns a new *http.Client ready to instrument. It is possible to trace only when the given context contains a pinpoint.Tracer.
client := pphttp.WrapClientWithContext(pinpoint.NewContext(context.Background(), tracer), &http.Client{}) client.Get(external_url)
func WrapHandle ¶
func WrapHandle(agent pinpoint.Agent, handlerName string, pattern string, handler http.Handler) (string, http.Handler)
WrapHandle is deprecated. Use WrapHandler.
func WrapHandleFunc ¶
func WrapHandleFunc(agent pinpoint.Agent, handlerName string, pattern string, handler func(http.ResponseWriter, *http.Request)) (string, func(http.ResponseWriter, *http.Request))
WrapHandleFunc is deprecated. Use WrapHandlerFunc.
func WrapHandler ¶
WrapHandler wraps the given http handler and adds the pinpoint.Tracer to the request's context. By using the pinpoint.FromContext function, this tracer can be obtained.
func WrapHandlerFunc ¶
func WrapHandlerFunc(handler func(http.ResponseWriter, *http.Request), serverName ...string) func(http.ResponseWriter, *http.Request)
WrapHandlerFunc wraps the given http handler function and adds the pinpoint.Tracer to the request's context. By using the pinpoint.FromContext function, this tracer can be obtained.
func WrapResponseWriter ¶
func WrapResponseWriter(w http.ResponseWriter, status *int) *responseWriter