http: set r.Pattern on dispatched requests for automatic route tagging#3897
Merged
http: set r.Pattern on dispatched requests for automatic route tagging#3897
Conversation
The default HTTP muxer now populates r.Pattern with "METHOD /path" on
every matched request, following the Go 1.22+ convention established by
http.ServeMux. This enables observability middleware such as otelhttp
(v0.65.0+) to automatically tag spans and metrics with the matched
route without any per-handler wrapping.
The pattern is captured before chi's internal wildcard rewriting, so
r.Pattern always reflects the original Goa route (e.g. GET /users/{id},
GET /files/{*path}).
This replaces the need for the otel plugin in goa.design/plugins which
has been deprecated (goadesign/plugins#242).
Fixes #3896
This was referenced Feb 16, 2026
JoaoBraveCoding
added a commit
to JoaoBraveCoding/api
that referenced
this pull request
Feb 24, 2026
It was removed in open-telemetry/opentelemetry-go-contrib#8268 Approach was inspired by goadesign/goa#3897
philipgough
pushed a commit
to observatorium/api
that referenced
this pull request
Feb 26, 2026
* chore: update dependencies * fix race condition * chore: updated bingo tools * fix: move from the deprecated CFB to CTR * chore: updated some go expressions to recent standards * refactor: stop using deprecated WithRouteTag It was removed in open-telemetry/opentelemetry-go-contrib#8268 Approach was inspired by goadesign/goa#3897 * downgrade golangci-ling to 2.8.0 as it's the most recent version still on 1.24 * update github.com/efficientgo/e2e
Copilot AI
pushed a commit
to observatorium/api
that referenced
this pull request
Feb 26, 2026
* chore: update dependencies * fix race condition * chore: updated bingo tools * fix: move from the deprecated CFB to CTR * chore: updated some go expressions to recent standards * refactor: stop using deprecated WithRouteTag It was removed in open-telemetry/opentelemetry-go-contrib#8268 Approach was inspired by goadesign/goa#3897 * downgrade golangci-ling to 2.8.0 as it's the most recent version still on 1.24 * update github.com/efficientgo/e2e
philipgough
pushed a commit
to rhobs/api
that referenced
this pull request
Apr 10, 2026
* chore: update dependencies * fix race condition * chore: updated bingo tools * fix: move from the deprecated CFB to CTR * chore: updated some go expressions to recent standards * refactor: stop using deprecated WithRouteTag It was removed in open-telemetry/opentelemetry-go-contrib#8268 Approach was inspired by goadesign/goa#3897 * downgrade golangci-ling to 2.8.0 as it's the most recent version still on 1.24 * update github.com/efficientgo/e2e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The default HTTP muxer now populates
r.Patternwith"METHOD /path"on every dispatched request, following the Go 1.22+ convention established byhttp.ServeMux.This enables observability middleware such as
otelhttp(v0.65.0+) to automatically tag spans and metrics with the matched route — no per-handler wrapping required.Problem
The
otelhttppackage removedWithRouteTagin v0.65.0, breaking the otel plugin which generated calls to that function. The upstream replacement isr.Pattern— otelhttp now reads it automatically after handler dispatch.Since Goa uses a Chi-based muxer (not
http.ServeMux),r.Patternwas never set, so otelhttp couldn't pick up the route.Solution
A single change in
mux.Handle: capture the original Goa pattern before Chi's wildcard rewriting and setr.Patterninside the handler wrapper:Benefits over the old plugin approach:
r.PatternThe otel plugin has been deprecated in goadesign/plugins#242.
Fixes #3896
Test plan
TestRequestPattern— verifiesr.Patternis set correctly for simple paths, parameterized segments (/users/{id}), and wildcards (/files/{*path})TestMiddlewares,TestVars,TestResolvePattern)go test ./http/green