feat(otel): add getRoute callback so adapters can resolve http.route#1915
Open
spokodev wants to merge 1 commit into
Open
feat(otel): add getRoute callback so adapters can resolve http.route#1915spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
The middleware overwrote the http.route attribute at finalize time with the Hono route pattern, even when a downstream adapter (such as an RPC layer) had already set a more specific value on the active span. The same pattern was also written to the http.server.request.duration metric, so per-operation latency collapsed into the pattern bucket (see issue honojs#1914). Add an optional getRoute(c) config callback. When it returns a non-empty string the value is used for both the span attribute and the metric attribute at finalize. When it returns undefined, an empty string, or throws, the middleware falls back to routePath(c). This is fully backward compatible. Closes honojs#1914
🦋 Changeset detectedLatest commit: 4cc351b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Closes #1914.
@hono/oteloverwrote thehttp.routeattribute on the active span at finalize time with the matched Hono pattern (e.g./rpc/*), even when a downstream adapter resolved a more specific operation name (e.g./rpc/user/getProfile) during request handling. The same Hono pattern was reported as thehttp.routeattribute of thehttp.server.request.durationmetric, so per-operation latency collapsed into the pattern bucket.This PR adds a
getRoute(c)config callback. When it returns a non-empty string the value is used at finalize for both the span attribute and the metric attribute. When it returnsundefined, an empty string, or throws, the middleware falls back toroutePath(c), so the existing behavior is preserved when the callback is not provided.Typical adapter usage:
Verification:
packages/otel/src/index.test.ts:http.routereflects thegetRoutereturn valuehttp.routereflects thegetRoutereturn valuegetRoutereturningundefinedfalls back toroutePath(c)getRoutereturning an empty string falls back toroutePath(c)getRoutethrowing falls back toroutePath(c)index.ts+types.tstomainmakes the two positive tests fail; applying the fix turns them greenyarn test --runfor@hono/otel: 27 / 27 (22 existing + 5 new)yarn typecheckcleanyarn turbo run lint --filter=@hono/otelcleanyarn formatreportsAll matched files use Prettier code style!.changeset/otel-get-route-callback.md(@hono/otel: minor)Out of scope:
tracer.startActiveSpanstill useroutePath(c), becausegetRoutemay rely on context state that downstream middleware writes after the span is started. The finalize step updates the attribute to the resolved value so the exported span and the metric agree.