Documentation
¶
Overview ¶
Package echo provides functions to trace the labstack/echo package (https://github.com/labstack/echo).
Example ¶
To start tracing requests, add the trace middleware to your echo router.
tracer.Start()
defer tracer.Stop()
r := echo.New()
// Use the tracer middleware with your desired service name.
r.Use(echotrace.Middleware(echotrace.WithService("my-web-app")))
// Set up an endpoint.
r.GET("/hello", func(c echo.Context) error {
return c.String(200, "hello world!")
})
// ...and listen for incoming requests
r.Start(":8080")
Example (SpanFromContext) ¶
An example illustrating tracing a child operation within the main context.
tracer.Start()
defer tracer.Stop()
// Create a new instance of echo
r := echo.New()
// Use the tracer middleware with your desired service name.
r.Use(echotrace.Middleware(echotrace.WithService("image-encoder")))
// Set up some endpoints.
r.GET("/image/encode", func(c echo.Context) error {
// create a child span to track an operation
span, _ := tracer.StartSpanFromContext(c.Request().Context(), "image.encode")
// encode an image ...
// finish the child span
span.Finish()
return c.String(200, "ok!")
})
Index ¶
- func Middleware(opts ...Option) echo.MiddlewareFuncdeprecated
- func OnAddRouteHandler(_ string, route echo.Route, _ echo.HandlerFunc, _ []echo.MiddlewareFunc)
- func Wrap(e *echo.Echo, opts ...Option) *echo.Echo
- type IgnoreRequestFunc
- type Option
- type OptionFn
- func NoDebugStack() OptionFn
- func WithAnalytics(on bool) OptionFn
- func WithAnalyticsRate(rate float64) OptionFn
- func WithCustomTag(key string, value interface{}) OptionFn
- func WithErrorCheck(errCheck func(error) bool) OptionFn
- func WithErrorTranslator(fn func(err error) (*echo.HTTPError, bool)) OptionFn
- func WithHeaderTags(headers []string) OptionFn
- func WithIgnoreRequest(ignoreRequestFunc IgnoreRequestFunc) OptionFn
- func WithService(name string) OptionFn
- func WithStatusCheck(fn func(statusCode int) bool) OptionFn
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Middleware
deprecated
func Middleware(opts ...Option) echo.MiddlewareFunc
Middleware returns echo middleware which will trace incoming requests.
Deprecated: Use of the Wrap function is recommended instead of directly calling echo.Echo.Use with this middleware function, as Wrap activates all available features automatically.
func OnAddRouteHandler ¶ added in v2.7.0
func OnAddRouteHandler(_ string, route echo.Route, _ echo.HandlerFunc, _ []echo.MiddlewareFunc)
OnAddRouteHandler is used as echo.Echo.OnAddRouteHandler value to automatically collect route information as it is being registered in the router, so they appear in the API Catalog even if they receives no traffic.
The collection can be disabled at runtime by setting `DD_API_SECURITY_ENDPOINT_COLLECTION_ENABLED` to a false-ey value.
func Wrap ¶ added in v2.7.0
Wrap configures the provided echo.Echo and returns it. This is a convenience function that calls echo.Echo.Use with the Middleware and overwrites echo.Echo.OnAddRouteHandler to OnAddRouteHandler. It is recommended to use this if you want to benefit from future tracer features that require additional properties to be configured without having to update your code.
Types ¶
type IgnoreRequestFunc ¶
IgnoreRequestFunc determines if tracing will be skipped for a request.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option describes options for the Echo.v4 integration.
type OptionFn ¶
type OptionFn func(*config)
OptionFn represents options applicable to Middleware.
func NoDebugStack ¶
func NoDebugStack() OptionFn
NoDebugStack prevents stack traces from being attached to spans finishing with an error. This is useful in situations where errors are frequent and performance is critical.
func WithAnalytics ¶
WithAnalytics enables Trace Analytics for all started spans.
func WithAnalyticsRate ¶
WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.
func WithCustomTag ¶
WithCustomTag will attach the value to the span tagged by the key. Standard span tags cannot be replaced.
func WithErrorCheck ¶
WithErrorCheck sets the func which determines if err would be ignored (if it returns true, the error is not tagged). This function also checks the errors created from the WithStatusCheck option.
func WithErrorTranslator ¶
WithErrorTranslator sets a function to translate Go errors into echo Errors. This is used for extracting the HTTP response status code.
func WithHeaderTags ¶
WithHeaderTags enables the integration to attach HTTP request headers as span tags. Warning: Using this feature can risk exposing sensitive data such as authorization tokens to Datadog. Special headers can not be sub-selected. E.g., an entire Cookie header would be transmitted, without the ability to choose specific Cookies.
func WithIgnoreRequest ¶
func WithIgnoreRequest(ignoreRequestFunc IgnoreRequestFunc) OptionFn
WithIgnoreRequest sets a function which determines if tracing will be skipped for a given request.
func WithService ¶
WithService sets the given service name for the system.
func WithStatusCheck ¶
WithStatusCheck specifies a function fn which reports whether the passed statusCode should be considered an error.