Echo OpenTelemetry middleware
Repo labstack/echo-otel, read from GitHub 1 min ago. labstack has not joined Take My Repo.
labstack/echo-otel is a public repo on GitHub by labstack. Echo OpenTelemetry middleware. It declares the MIT license on GitHub. It is written mainly in Go, has 16 stars and last changed on 2026-10-01. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-18.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
OpenTelemetry middleware for Echo framework.
This repository does not use semantic versioning. MAJOR version tracks which Echo version should be used. MINOR version tracks API changes (possibly backwards incompatible) and PATCH version is incremented for fixes.
| Echo | Module | Branch | Minimal Echo version |
|---|---|---|---|
| v5 | github.com/labstack/echo-otel/v5 |
main |
v5.2.1 |
| v4 | github.com/labstack/echo-otel/v4 |
v4 |
v4.15.4 |
This is the main branch, for Echo v5. github.com/labstack/echo-opentelemetry (v0.0.x, Echo v5) is the
previous name of this project and is deprecated.
Always include the MAJOR version suffix (/v5 or /v4) in go get and imports. Without it,
go get github.com/labstack/echo-otel fails.
Add OpenTelemetry middleware dependency with go modules
go get github.com/labstack/echo-otel/v5
Use as an import statement
import echootel "github.com/labstack/echo-otel/v5"
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
tracer, err := echo.ContextGet[trace.Tracer](c, echootel.TracerKey)
See example
The middleware resolves the response status code for returned errors with echo.ResolveResponseStatus: the status of
an already sent response, the StatusCode() of the returned error (for example echo.HTTPError), or 500. If you
use a custom HTTPErrorHandler that maps errors to other status codes, let the middleware run the error handler, so it
reports the status code that was actually sent:
e.Use(echootel.NewMiddlewareWithConfig(echootel.Config{ ServerName: "app.example.com", OnNextError: func(c *echo.Context, err error) { c.Echo().HTTPErrorHandler(c, err) }, }))
The error is still returned, so the error handler is called again; make it return early when the response is already
committed (resp, err := echo.UnwrapResponse(c.Response()); err == nil && resp.Committed). Echo's
ProblemDetailsHTTPErrorHandler (Echo v5.4.0+) does this; use the snippet above with it too, as it resolves the status
of ProblemErrorer errors and of *echo.ProblemError wrapped in another error differently.
go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho is deprecated and removed from
opentelemetry-go-contrib in favor of this library.
For Echo v5 use github.com/labstack/echo-otel/v5. For Echo v4 use github.com/labstack/echo-otel/v4, there is no
need to migrate to Echo v5 first.
Replace otelecho.Middleware("my-server", opts...) with echootel.NewMiddleware("my-server"), or with
echootel.NewMiddlewareWithConfig(echootel.Config{...}) when you use options.
The server name is used as server.address and server.port, so it must be a host name with an optional port,
for example api.example.com or api.example.com:8080 (otelecho accepted any string); NewMiddleware panics on an
invalid value such as :8080 (no host), Config.ToMiddleware returns an error, and an empty ServerName uses the
request Host:
| otelecho option | echootel.Config field |
|---|---|
otelecho.WithTracerProvider(tp) |
TracerProvider: tp |
otelecho.WithMeterProvider(mp) |
MeterProvider: mp |
otelecho.WithPropagators(p) |
Propagators: p |
otelecho.WithSkipper(s) |
Skipper: s |
otelecho.WithMetricAttributeFn(f) |
MetricAttributes (see below) |
otelecho.WithEchoMetricAttributeFn(f) |
MetricAttributes (see below) |
otelecho.WithOnError(f) |
OnNextError (and OnExtractionError for request extraction failures) |
Also note:
MetricAttributes replaces the default metric attributes (otelecho appended to them), so return
append(v.MetricAttributes(), extra...).c.Error(err)); echootel does not. See
Custom error handler for how to get the same behavior.go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho
to github.com/labstack/echo-otel/v5. Update dashboards and alerts that filter on it.echo.error span attribute is not set; use error.type and the span status instead.github.com/labstack/echo-opentelemetry (v0.0.x) is the previous name of this project. It is deprecated and receives
no more changes. Change the import path; the API is the same, except that a ServerName without a host is rejected
(see below):
import echootel "github.com/labstack/echo-otel/v5"
Telemetry changes compared to echo-opentelemetry v0.0.3:
github.com/labstack/echo-opentelemetry to
github.com/labstack/echo-otel/v5. Update dashboards and alerts that filter on it.error.type is no longer set for 4xx responses (it used to be *echo.HTTPError for a returned HTTPError, and
*echo.httpError for Echo's own errors such as echo.ErrNotFound).500) instead of *echo.HTTPError.c.String(500, ...)) now reports error.type.StatusCode() int method reports the status code for a 5xx response instead of its Go type.error.type is also added to metrics, see Errors.http.route and the span name are set when the middleware is added with Echo.Pre.fmt.Errorf("...: %w", err) reports the wrapped error's type (for example *net.OpError)
instead of *fmt.wrapError, and an ErrorType() string method in the error chain is used when present.error.type is now one of the span end attributes: a Config.SpanEndAttributes callback must append to the attr
argument, otherwise error.type is dropped (v0.0.3 set it separately).error.type (the code).server.address, server.port and http.request.method_original; their values come from
the request and would make metric cardinality unbounded. They stay on spans. See Metrics.ServerName set, server.port comes from ServerName only, not from the Host header.-1.http.route is always the Echo route, never the pattern of an outer http.ServeMux.error.type panic) and then re-panicked, so telemetry is recorded also when a
Recover middleware is added before this middleware. With a Recover middleware added after this middleware, the
returned *middleware.PanicStackError is reported as panic instead of its Go type. See Errors.ServerName without a host (for example :8080) is rejected: NewMiddleware panics and Config.ToMiddleware
returns an error. v0.0.3 accepted it.network.protocol.version is 2 for HTTP/2 and 3 for HTTP/3, instead of 2.0 and 3.0.http.request.body.size and http.response.body.size (Opt-In for spans in the semantic
conventions). The body size metrics stay. See Spans for how to add them back.A request that ends with an error sets error.type on the span and on the metrics, as the semantic conventions
require. The rules match the span status:
error.type,echo.HTTPError
or any error with a StatusCode() int method, also when wrapped), reports the status code, for example 500,*net.OpError. Errors created with
fmt.Errorf("...: %w", err) are unwrapped first; errors joining several errors (errors.Join, fmt.Errorf with
more than one %w) report their own type. An ErrorType() string method anywhere in the error chain takes
precedence; keep its values low cardinality, as error.type is also a metric attribute._OTHER (below 100 or above 999) or the code itself
(600-999),panic, also when a 4xx response was already sent.The middleware records a panic and then re-panics, so add a Recover middleware before this middleware
(e.Use(middleware.Recover()) first). The recorded status is the status of the response that was already sent, the
status of a panic value that carries one (for example echo.ErrUnauthorized), or 500. A Recover middleware added after
this middleware (with the default configuration) returns the panic as a *middleware.PanicStackError, which is also
reported as panic.
error.type is part of the span end attributes. A Config.SpanEndAttributes callback must append to the attr
argument and return it, otherwise error.type and the other end attributes are dropped.
Spans follow the HTTP server span semantic conventions, with these exceptions:
url.query is not set. The query string can contain sensitive data, and the semantic conventions require redacting
it. http.request.body.size and http.response.body.size are Opt-In and not set either.http.response.status_code is not set when no response was sent, for example after an http.ErrAbortHandler panic.client.address comes from c.RealIP(): the connection's remote address, or the result of Echo.IPExtractor when
it is set.
Add attributes with SpanStartAttributes and SpanEndAttributes. Both callbacks must append to the attr argument and
return it:
SpanStartAttributes: func(c *echo.Context, v *echootel.Values, attr []attribute.KeyValue) []attribute.KeyValue { if q := c.Request().URL.RawQuery; q != "" { attr = append(attr, semconv.URLQuery(redactQuery(q))) // redactQuery is your own function } return attr }, SpanEndAttributes: func(c *echo.Context, v *echootel.Values, attr []attribute.KeyValue) []attribute.KeyValue { if v.HTTPRequestBodySize >= 0 { attr = append(attr, semconv.HTTPRequestBodySize(int(v.HTTPRequestBodySize))) } return append(attr, semconv.HTTPResponseBodySize(int(v.HTTPResponseBodySize))) },
The middleware records http.server.request.duration, http.server.request.body.size and
http.server.response.body.size with these attributes: http.request.method, url.scheme, http.route,
network.protocol.name, network.protocol.version, http.response.status_code and error.type.
server.address, server.port and http.request.method_original are Opt-In for metrics in the semantic conventions
and are not added: the Host header and the request method are chosen by the client and would make metric cardinality
unbounded. Add attributes with a known set of values with MetricAttributes, for example:
MetricAttributes: func(c *echo.Context, v *echootel.Values) []attribute.KeyValue { return append(v.MetricAttributes(), semconv.ServerAddress("api.example.com")) },
net/http closes the connection without
sending a response.Renovate proposes a new MAJOR version (for example github.com/labstack/echo-otel/v4 to /v5) as an update. A new
MAJOR version of this library needs the same MAJOR version of Echo, so update Echo first. To stay on the current Echo
version, disable major updates for this library:
{
"packageRules": [
{
"matchManagers": ["gomod"],
"matchPackageNames": ["github.com/labstack/echo-otel/v4", "github.com/labstack/echo-otel/v5"],
"matchUpdateTypes": ["major"],
"enabled": false
}
]
}labstack/echo-otel is a public repo on GitHub by labstack. Echo OpenTelemetry middleware.
It declares the MIT license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-10-01. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
An opinionated GoLang framework for accelerated microservice development. Built in support for databases and observability.
Single-binary observability platform. Ingest OTLP, store as Parquet, query with DuckDB.