Skip to content

Conversation

@s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Dec 16, 2025

If the error is caught with the hono error handler, no trace data was sent alongside the event. This PR fixed this.

Before:
image

After:
image

Copy link
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Comment on lines 63 to 67
activeSpan.updateName(`${context.req.method} ${routePath(context)}`);
updateSpanName(getRootSpan(activeSpan), `${context.req.method} ${routePath(context)}`);
}

getIsolationScope().setTransactionName(`${context.req.method} ${routePath(context)}`);

This comment was marked as outdated.

if (shouldHandleError(err)) {
const activeSpan = getActiveSpan();
if (activeSpan) {
activeSpan.updateName(`${context.req.method} ${routePath(context)}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: "${context.req.method} ${routePath(context)}" is used 3 times. We could use a const at the beginning

if (activeSpan) {
activeSpan.updateName(spanName);
updateSpanName(getRootSpan(activeSpan), spanName);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Renaming active span can corrupt traces

The error handler updates activeSpan.updateName(spanName) and also updates the root span name. If the currently active span at error time is not the root http.server span (e.g., a nested span is still active), this change can rename that child span to the transaction name and distort span descriptions in the trace.

Fix in Cursor Fix in Web

@github-actions
Copy link
Contributor

github-actions bot commented Dec 17, 2025

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,922 - 8,907 +0%
GET With Sentry 1,732 19% 1,760 -2%
GET With Sentry (error only) 6,162 69% 6,292 -2%
POST Baseline 1,196 - 1,230 -3%
POST With Sentry 589 49% 590 -0%
POST With Sentry (error only) 1,067 89% 1,081 -1%
MYSQL Baseline 3,373 - 3,375 -0%
MYSQL With Sentry 469 14% 459 +2%
MYSQL With Sentry (error only) 2,686 80% 2,718 -1%

View base workflow run

if (shouldHandleError(err)) {
if (context) {
const activeSpan = getActiveSpan();
const spanName = `${context.req.method} ${routePath(context)}`;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Inconsistent null-safety between routePath and method access

The routePath function (vendored from Hono) uses optional chaining c.req?.path to defensively handle cases where req might be undefined, but the span name construction directly accesses context.req.method without the same protection. If context is truthy but context.req is unexpectedly undefined, accessing context.req.method would throw a TypeError. For consistency with the vendored defensive pattern, consider using context.req?.method with an appropriate fallback.

Additional Locations (1)

Fix in Cursor Fix in Web

@s1gr1d s1gr1d enabled auto-merge (squash) December 18, 2025 14:32
@s1gr1d s1gr1d merged commit 3fda84d into develop Dec 18, 2025
401 of 405 checks passed
@s1gr1d s1gr1d deleted the sig/cloudflare-hono-error-name branch December 18, 2025 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants