dd-trace-go.v1: gopkg.in/DataDog/dd-trace-go.v1/contrib/labstack/echo Index | Examples | Files

package echo

import "gopkg.in/DataDog/dd-trace-go.v1/contrib/labstack/echo"

Package echo provides functions to trace the labstack/echo package (https://github.com/labstack/echo).

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

Code:

r := echo.New()

// Use the tracer middleware with your desired service name.
r.Use(Middleware(WithServiceName("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")

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

Code:

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

// Use the tracer middleware with your desired service name.
r.Use(Middleware(WithServiceName("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

Examples

Package Files

echotrace.go option.go

func Middleware Uses

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

Middleware returns echo middleware which will trace incoming requests.

type Option Uses

type Option func(*config)

Option represents an option that can be passed to Middleware.

func WithAnalytics Uses

func WithAnalytics(on bool) Option

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate Uses

func WithAnalyticsRate(rate float64) Option

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

func WithServiceName Uses

func WithServiceName(name string) Option

WithServiceName sets the given service name for the system.

Package echo imports 8 packages (graph). Updated 2020-12-23. Refresh now. Tools for package owners.