Skip to main content

Open-telemetry

Echo-opentelemetry is a middleware for Echo framework that provides OpenTelemetry instrumentation for HTTP requests. https://github.com/labstack/echo-opentelemetry

Open-telemetry is a set of open-source tools that provide instrumentation for cloud native applications.

Usage

Add OpenTelemetry middleware dependency with go modules

go get github.com/labstack/echo-opentelemetry

Use as an import statement

e.Use(echootel.NewMiddlewareWithConfig(echootel.Config{
ServerName: "my-server",
TracerProvider: tp,

//Skipper: nil,
//OnNextError: nil,
//OnExtractionError: nil,
//MeterProvider: nil,
//Propagators: nil,
//SpanStartOptions: nil,
//SpanStartAttributes: nil,
//SpanEndAttributes: nil,
//MetricAttributes: nil,
//Metrics: nil,
}))

For configuration options documentation see Config struct.

Add middleware in simplified form, by providing only the server name

e.Use(echootel.NewMiddleware("app.example.com"))

Add middleware with configuration options

e.Use(echootel.NewMiddlewareWithConfig(echootel.Config{
TracerProvider: tp,
}))

Retrieving the tracer from the Echo context

tp, err := echo.ContextGet[trace.Tracer](c, echootel.TracerKey)

Example

This example is exporting metrics and spans to stdout but you can use any exporter (OTLP etc). Read about OpenTelemetry exporters

example/main.go
loading...