Uh oh!
There was an error while loading. Please reload this page.
feat(node): Add instrumentation for hono handler - #17428
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
32e3a23 to
505c480Compare
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
505c480 to
a7ef204CompareKaribash
commented
Sep 2, 2025
| } | ||
| const path = c.req.path; | ||
| const spanName = `${type.replace('_', ' ')} - ${path}`; |
There was a problem hiding this comment.
What would be an example span name here? I think there are no tests that check this name so I couldn't find an example.
Would be good to also have tests for this.
There was a problem hiding this comment.
I checked other test codes, but I couldn’t find a way to test the span name.
I also looked into transaction.spans, but it doesn’t seem to include the span name.
{
"span_id": "c6b2cd926a07da13",
"trace_id": "8d75c4926828d1b7b98dc2b9356c3fc9",
"data": {
"sentry.origin": "auto.http.otel.hono",
"sentry.op": "request_handler.hono",
"hono.type": "request_handler",
"hono.name": "/async"
},
"description": "/async",
"parent_span_id": "b3270618aac86a93",
"start_timestamp": 1757852841.829,
"timestamp": 1757852841.8291407,
"status": "ok",
"op": "request_handler.hono",
"origin": "auto.http.otel.hono"
}Do you know how we can test the span name in this case?
| if ( | ||
| result && | ||
| typeof result === 'object' && | ||
| typeof Object.getOwnPropertyDescriptor(result, 'then')?.value === 'function' |
There was a problem hiding this comment.
You can use isThenable here from @sentry/core
There was a problem hiding this comment.
Thanks, I’ve fixed this in the following commit: 8dc3939
| * Safely executes a function and handles errors. | ||
| */ | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| private _safeExecute(execute: () => any, onSuccess: () => void, onFailure: (error: unknown) => void): () => any { |
There was a problem hiding this comment.
I'm wondering if it would be possible to type this instead of relying on any here?
There was a problem hiding this comment.
Since the return value of handler.apply(this, [c, next]) is any, I think it would be difficult to type this explicitly.
| path, | ||
| ...handlers.map((handler, index) => | ||
| instrumentation._wrapHandler( | ||
| index + 1 === handlers.length ? HonoTypes.REQUEST_HANDLER : HonoTypes.MIDDLEWARE, |
There was a problem hiding this comment.
Can we be sure that the handlers are always those two in this order?
There was a problem hiding this comment.
I overlooked the case where the middleware is registered on its own.
That has been fixed in the following commit: 7172211
s1gr1d
commented
Sep 9, 2025
@Karibash just a general heads-up: It's awesome that you are working on this instrumentation right now. Keep in mind that we are planning to start working on a dedicated hono SDK in about a month. So your integration can be used in the meantime but we might need to deprecate it once the new SDK is stable :) |
Karibash
commented
Sep 9, 2025
@s1gr1d Thanks for the heads-up! |
s1gr1d
commented
Sep 9, 2025
It will use OTel under the hood but we'll focus on making it work on Cloudflare as a first priority. |
Karibash
commented
Sep 9, 2025
Got it — so in that sense, the approach in this PR won’t differ too much from what you’re planning for the new SDK (aside from the implementation details that will naturally evolve), right? |
s1gr1d
commented
Sep 11, 2025
Probably not, but it's not planned out in detail yet |
a7ef204 to
bafc2beCompare
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
s1gr1d
commented
Sep 15, 2025
Can you check the missing exports? |
Karibash
commented
Sep 16, 2025
I’ve fixed this in the following commit: 20f5ac8 |
Karibash
commented
Sep 22, 2025
Hi @s1gr1d, any updates on this PR? |
| "express": "^4.21.1", | ||
| "generic-pool": "^3.9.0", | ||
| "graphql": "^16.3.0", | ||
| "hono": "^4.8.12", |
There was a problem hiding this comment.
Can you update the version here? It's popping up in our vulnerability check.
…ther it is a Promise
20f5ac8 to
3c89525Compare
s1gr1d
left a comment
There was a problem hiding this comment.
Thank you for contributing this!
Uh oh!
There was an error while loading. Please reload this page.
This PR adds the external contributor to the CHANGELOG.md file, so that they are credited for their contribution. See #17428 Co-authored-by: s1gr1d <32902192+s1gr1d@users.noreply.github.com>
Summary
This PR enhances the Hono integration by adding comprehensive handler instrumentation, error handling capabilities, and thorough test coverage. The changes build upon the basic Hono integration to provide a complete tracing and error monitoring solution.
New Features
Bug Fixes
Implementation Details
Testing
Related Issue
close#15260