Skip to content

feat(react-router): Add otel instrumentation for server requests #16147

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

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from

Conversation

chargome
Copy link
Member

@chargome chargome commented Apr 28, 2025

This PR adds OpenTelemetry instrumentation for server-side requests in React Router by tracing server requests for data loaders and actions.

@chargome chargome self-assigned this Apr 28, 2025
@chargome
Copy link
Member Author

chargome commented Apr 29, 2025

Potentially blocked by #16160
good to go

@chargome chargome marked this pull request as ready for review May 12, 2025 14:57

// Set the source and overwrite attributes on the root span to ensure the transaction name
// is derived from the raw URL pathname rather than any parameterized route that may be set later
// TODO: try to set derived parameterized route from build here (args[0])
Copy link
Member Author

Choose a reason for hiding this comment

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

want to ship this in a follow-up

get(target, prop, receiver) {
if (prop === 'createRequestHandler') {
const original = target[prop];
return function wrappedCreateRequestHandler(this: unknown, ...args: unknown[]) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return function wrappedCreateRequestHandler(this: unknown, ...args: unknown[]) {
return function sentryWrappedCreateRequestHandler(this: unknown, ...args: unknown[]) {

l: Can we prefix this with sentry? :)

return function wrappedCreateRequestHandler(this: unknown, ...args: unknown[]) {
const originalRequestHandler = original.apply(this, args);

return async function wrappedRequestHandler(request: Request, initialContext?: unknown) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return async function wrappedRequestHandler(request: Request, initialContext?: unknown) {
return async function sentryWrappedRequestHandler(request: Request, initialContext?: unknown) {

l: and this one too

overwrite
) {
event.transaction = overwrite;
delete event.contexts?.trace?.data?.[SEMANTIC_ATTRIBUTE_SENTRY_OVERWRITE];
Copy link
Member

Choose a reason for hiding this comment

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

q: Can this attribute end up on transactions that don't match all those conditions above and thus won't be deleted? Does that matter? I'm wondering if we should just always delete at the end of the processor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call

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