Skill: golang-echo-otel-middleware
Use this skill when adding or configuring github.com/adlandh/echo-otel-middleware/v2 in a Go Echo application, or when writing examples for this middleware.
Essentials
- Import path must include
/v2:github.com/adlandh/echo-otel-middleware/v2. - Alias examples as
echootelmiddlewareto match the package name and README. - This middleware targets Echo v5: use
github.com/labstack/echo/v5and handler signatures with*echo.Context. Middleware()uses global OpenTelemetry tracer provider and propagator; useMiddlewareWithConfigwhen the app owns explicit OTel setup.
Basic Usage
app := echo.New()
app.Use(echootelmiddleware.Middleware())
Use explicit config when a tracer provider or propagator is constructed by the application:
app.Use(echootelmiddleware.MiddlewareWithConfig(echootelmiddleware.OtelConfig{
TracerProvider: tp,
Propagator: otel.GetTextMapPropagator(),
}))
Config Defaults
TracerProvider:otel.GetTracerProvider().Propagator:otel.GetTextMapPropagator().Skipper: Echomiddleware.DefaultSkipper.BodySkipper: no-op, returnsfalse, false.AreHeadersDump:true.IsBodyDump:false.RemoveNewLines:false.LimitNameSizeandLimitValueSize:0, meaning unlimited.
Safe Body Dumping
- Body dumping is opt-in with
IsBodyDump: truebecause it can capture PII, tokens, and secrets. - Prefer
BodySkipperto exclude sensitive endpoints, compressed bodies, uploads, auth payloads, or large responses. BodySkipperonly runs whenIsBodyDumpis true and returns(skipReqBody, skipRespBody).
BodySkipper: func(c *echo.Context) (bool, bool) {
if c.Request().Header.Get("Content-Encoding") == "gzip" {
return true, true
}
return false, false
},
Attribute Limits
LimitNameSizeandLimitValueSizeare byte-based, not rune-based.- Truncation preserves valid UTF-8; values over a limit greater than 10 get a trailing
.... RemoveNewLinesreplaces\nwith spaces in string attributes, useful for backends such as Sentry.
Do Not Assume
- Metrics are not implemented in this middleware; do not add or document metrics unless explicitly requested.
- Echo v4 examples are wrong for this package because context types and imports differ.
Source: adlandh/echo-otel-middleware — distributed by TomeVault.