Documentation ¶
Overview ¶
Package httptrace provides functionalities to trace HTTP requests that are commonly required and used across contrib/** integrations.
Index ¶
- func BeforeHandle(cfg *ServeConfig, w http.ResponseWriter, r *http.Request) (http.ResponseWriter, *http.Request, func(), bool)
- func FinishRequestSpan(s *tracer.Span, status int, opts ...tracer.FinishOption)
- func GetErrorCodesFromInput(s string) func(statusCode int) bool
- func HeaderTagsFromRequest(req *http.Request, headerTags instrumentation.HeaderTags) tracer.StartSpanOption
- func StartRequestSpan(r *http.Request, opts ...tracer.StartSpanOption) (*tracer.Span, context.Context)
- type ServeConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BeforeHandle ¶
func BeforeHandle(cfg *ServeConfig, w http.ResponseWriter, r *http.Request) (http.ResponseWriter, *http.Request, func(), bool)
BeforeHandle contains functionality that should be executed before a http.Handler runs. It returns the "traced" http.ResponseWriter and http.Request, an additional afterHandle function that should be executed after the Handler runs, and a handled bool that instructs if the request has been handled or not - in case it was handled, the original handler should not run.
func FinishRequestSpan ¶
func FinishRequestSpan(s *tracer.Span, status int, opts ...tracer.FinishOption)
FinishRequestSpan finishes the given HTTP request span and sets the expected response-related tags such as the status code. Any further span finish option can be added with opts.
func GetErrorCodesFromInput ¶
GetErrorCodesFromInput parses a comma-separated string s to determine which codes are to be considered errors Its purpose is to support the DD_TRACE_HTTP_SERVER_ERROR_STATUSES env var If error condition cannot be determined from s, `nil` is returned e.g, input of "100,200,300-400" returns a function that returns true on 100, 200, and all values between 300-400, inclusive any input that cannot be translated to integer values returns nil
func HeaderTagsFromRequest ¶
func HeaderTagsFromRequest(req *http.Request, headerTags instrumentation.HeaderTags) tracer.StartSpanOption
HeaderTagsFromRequest matches req headers to user-defined list of header tags and creates span tags based on the header tag target and the req header value
func StartRequestSpan ¶
func StartRequestSpan(r *http.Request, opts ...tracer.StartSpanOption) (*tracer.Span, context.Context)
StartRequestSpan starts an HTTP request span with the standard list of HTTP request span tags (http.method, http.url, http.useragent). Any further span start option can be added with opts.
Types ¶
type ServeConfig ¶
type ServeConfig struct { // Service specifies the service name to use. If left blank, the global service name // will be inherited. Service string // Resource optionally specifies the resource name for this request. Resource string // QueryParams should be true in order to append the URL query values to the "http.url" tag. QueryParams bool // Route is the request matched route if any, or is empty otherwise Route string // RouteParams specifies framework-specific route parameters (e.g. for route /user/:id coming // in as /user/123 we'll have {"id": "123"}). This field is optional and is used for monitoring // by AppSec. It is only taken into account when AppSec is enabled. RouteParams map[string]string // FinishOpts specifies any options to be used when finishing the request span. FinishOpts []tracer.FinishOption // SpanOpts specifies any options to be applied to the request starting span. SpanOpts []tracer.StartSpanOption }
ServeConfig specifies the tracing configuration when using TraceAndServe.