Skip to content

feat(react-router): Ensure http.server route handling is consistent #16986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2025

Conversation

mydea
Copy link
Member

@mydea mydea commented Jul 14, 2025

This updates react router http.server handling to ensure:

  • That we always have a correct route/url source
  • Streamlines how we get rid of the weird * transaction name by just using processEvent in the integration. This means we now always add the server integration, it just does less in non-matching node versions.
  • Ensure we always have a good span origin
  • Ensure the name of the spans is consistent with the target (e.g. containing the .data suffix) - we can revisit this later but for now this is consistent I'd say.

@mydea mydea self-assigned this Jul 14, 2025
cursor[bot]

This comment was marked as outdated.

Comment on lines +33 to +48
processEvent(event) {
// Express generates bogus `*` routes for data loaders, which we want to remove here
// we cannot do this earlier because some OTEL instrumentation adds this at some unexpected point
if (
event.type === 'transaction' &&
event.contexts?.trace?.data &&
event.contexts.trace.data[ATTR_HTTP_ROUTE] === '*' &&
// This means the name has been adjusted before, but the http.route remains, so we need to remove it
event.transaction !== 'GET *' &&
event.transaction !== 'POST *'
) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete event.contexts.trace.data[ATTR_HTTP_ROUTE];
}

return event;
Copy link
Member

Choose a reason for hiding this comment

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

Don't we also need to update the tx name here?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is done already in the respective place via updateSpanName, that forces a name over infernal. All we need to do here is remove the route attribute, as that can be misleading in product I think. (E2E tests should show this works xD)

@mydea mydea force-pushed the fn/rr-server-spans branch from 927c18a to ef814f8 Compare July 15, 2025 08:57
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Undefined Data Access Causes Fallback Failure

A TypeError can occur when accessing spanData.data[SEMATTRS_HTTP_TARGET] if spanData.data is undefined. This prevents the intended fallback (e.g., url.pathname) from being evaluated.

packages/react-router/src/server/wrapServerAction.ts#L47-L48

// eslint-disable-next-line deprecation/deprecation
const target = spanData.data[SEMATTRS_HTTP_TARGET];

packages/react-router/src/server/wrapServerLoader.ts#L48-L49

// eslint-disable-next-line deprecation/deprecation
const target = spanData.data[SEMATTRS_HTTP_TARGET];

packages/react-router/src/server/instrumentation/reactRouter.ts#L91-L92

// eslint-disable-next-line deprecation/deprecation
const target = spanData.data[SEMATTRS_HTTP_TARGET] || url.pathname;

Fix in CursorFix in Web


Bug: Route Handling Bug in React Router Integration

The processEvent method in reactRouterServerIntegration incorrectly handles bogus * routes. It only removes the http.route attribute when the transaction name is not "GET *" or "POST *", failing to address cases where the transaction name remains "GET *" or "POST *". This leaves transactions with unhelpful * names and http.route attributes, contradicting the intended goal of removing them and missing a case previously handled by older logic that updated the transaction name.

packages/react-router/src/server/integration/reactRouterServer.ts#L32-L49

},
processEvent(event) {
// Express generates bogus `*` routes for data loaders, which we want to remove here
// we cannot do this earlier because some OTEL instrumentation adds this at some unexpected point
if (
event.type === 'transaction' &&
event.contexts?.trace?.data &&
event.contexts.trace.data[ATTR_HTTP_ROUTE] === '*' &&
// This means the name has been adjusted before, but the http.route remains, so we need to remove it
event.transaction !== 'GET *' &&
event.transaction !== 'POST *'
) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete event.contexts.trace.data[ATTR_HTTP_ROUTE];
}
return event;
},

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

Copy link
Member

@chargome chargome left a comment

Choose a reason for hiding this comment

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

🚀

@mydea mydea merged commit 6e2eaed into develop Jul 15, 2025
143 checks passed
@mydea mydea deleted the fn/rr-server-spans branch July 15, 2025 12:46
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.

2 participants