fix(hono): Capture transaction name on request for correct culprit#20801
Merged
Conversation
Contributor
size-limit report 📦
|
nicohrubec
approved these changes
May 11, 2026
chargome
approved these changes
May 11, 2026
Member
chargome
left a comment
There was a problem hiding this comment.
LGTM! Not sure if it would make sense to update the name in both request and reponse handler for best effort but also I'm not aware of hono internals for routing.
|
|
||
| function updateSpanRouteName(isolationScope: Scope, context: Context): void { | ||
| const activeSpan = getActiveSpan(); | ||
| const lastMatchedRoute = routePath(context, -1); |
Member
There was a problem hiding this comment.
nit: A comment explaining what this actually does would be helpful, but not worth a CI rerun
Member
There was a problem hiding this comment.
Also, is this always the correct one?
Member
Author
There was a problem hiding this comment.
I can include a comment in another PR.
And yes, -1 gets the last matched path which is the one where it's routed to.
https://hono.dev/docs/helpers/route#using-with-index-parameter
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.
Hono error events were showing a wrong culprit (
?(index)) because the transaction name was only being set in the response handler. When an error was thrown during middleware execution,captureExceptionran beforeresponseHandlerhad a chance to update the span name and isolation scope transaction name.This PR moves the span and transaction name update into
requestHandlerso the correct route name is set before any middleware or route handler executes. TheresponseHandlernow only captures errors.Also switches from
routePath(context)(last matched route so far) toroutePath(context, -1)(final matched route) which avoids wildcard patterns like/error/*leaking into the transaction name.Also adds another test for route parametrization when using middleware.
Closes #20399