v1.60.3 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2024 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 19 Imported by: 12



Package echo provides functions to trace the labstack/echo package (


To start tracing requests, add the trace middleware to your echo router.

r := echo.New()

// Use the tracer middleware with your desired service name.

// Set up an endpoint.
r.GET("/hello", func(c echo.Context) error {
	return c.String(200, "hello world!")

// ...and listen for incoming requests

Example (SpanFromContext)

An example illustrating tracing a child operation within the main context.

// Create a new instance of echo
r := echo.New()

// Use the tracer middleware with your desired service name.

// 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

	return c.String(200, "ok!")




This section is empty.


This section is empty.


func Middleware

func Middleware(opts ...Option) echo.MiddlewareFunc

Middleware returns echo middleware which will trace incoming requests.


type IgnoreRequestFunc added in v1.40.0

type IgnoreRequestFunc func(c echo.Context) bool

IgnoreRequestFunc determines if tracing will be skipped for a request.

type Option

type Option func(*config)

Option represents an option that can be passed to Middleware.

func NoDebugStack added in v1.36.0

func NoDebugStack() Option

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

func WithAnalytics(on bool) Option

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate

func WithAnalyticsRate(rate float64) Option

WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.

func WithCustomTag added in v1.58.0

func WithCustomTag(key string, value interface{}) Option

WithCustomTag will attach the value to the span tagged by the key. Standard span tags cannot be replaced.

func WithErrorTranslator added in v1.56.0

func WithErrorTranslator(fn func(err error) (*echo.HTTPError, bool)) Option

WithErrorTranslator sets a function to translate Go errors into echo Errors. This is used for extracting the HTTP response status code.

func WithHeaderTags added in v1.53.0

func WithHeaderTags(headers []string) Option

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 added in v1.40.0

func WithIgnoreRequest(ignoreRequestFunc IgnoreRequestFunc) Option

WithIgnoreRequest sets a function which determines if tracing will be skipped for a given request.

func WithServiceName

func WithServiceName(name string) Option

WithServiceName sets the given service name for the system.

func WithStatusCheck added in v1.45.0

func WithStatusCheck(fn func(statusCode int) bool) Option

WithStatusCheck specifies a function fn which reports whether the passed statusCode should be considered an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL