feat(node): Add instrumentation for hono handler#17428
feat(node): Add instrumentation for hono handler#17428s1gr1d merged 11 commits intogetsentry:developfrom
Conversation
32e3a23 to
505c480
Compare
505c480 to
a7ef204
Compare
| } | ||
|
|
||
| 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
|
@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 :) |
|
@s1gr1d Thanks for the heads-up! |
|
It will use OTel under the hood but we'll focus on making it work on Cloudflare as a first priority. |
|
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? |
|
Probably not, but it's not planned out in detail yet |
a7ef204 to
bafc2be
Compare
|
Can you check the missing exports? |
I’ve fixed this in the following commit: 20f5ac8 |
|
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
…as a route handler
20f5ac8 to
3c89525
Compare
s1gr1d
left a comment
There was a problem hiding this comment.
Thank you for contributing this!
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 <[email protected]>
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