Skip to content

Conversation

@AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Jan 30, 2024

ref #10387

This PR adds two integrations for react router v4 and v5, meant to be used with the new browserTracingIntegration. The reason that we can't adjust the method for browserTracing is because react router has multiple versions we support (and is optional because there are multiple react routing libraries), so we have to make it a separate integration.

Setup is simple!

Sentry.init({
  integrations: [
    Sentry.browserTracingIntegration(),
    // or use reactRouterV5Integration
    Sentry.reactRouterV4Integration({ history, routes, matchPath }),
  ],
});

I also took the liberty to re-organize the files, everything should be validated by unit (actually they're basically integration) tests.

I didn't deprecate the routingInstrumentation yet, figured we should do that when we deprecate BrowserTracing in general.

@AbhiPrasad AbhiPrasad requested review from a team, mydea and stephanie-anderson and removed request for a team January 30, 2024 22:12
// TODO (v8): Remove this check and just return span
// eslint-disable-next-line deprecation/deprecation
return span.transaction;
return span && span.transaction;
Copy link
Member Author

Choose a reason for hiding this comment

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

needed this because the integration should only be changing the name of the root span (for transaction name paramaterization).

Copy link
Member

Choose a reason for hiding this comment

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

hmm not sure, is it not cleaner to do span ? getRootSpan(span) : undefined, or do we need this so often? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

It means I can do getRootSpan(getActiveSpan()), which helps with DX a lot


export const V4_SETUP_CLIENTS = new WeakMap<Client, boolean>();

export const V5_SETUP_CLIENTS = new WeakMap<Client, boolean>();
Copy link
Member Author

Choose a reason for hiding this comment

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

These weak maps are used to validate if the integration should work with withSentryRouting helper.

/**
* Options for React Router v4 and v4 integration
*/
type ReactRouterOptions = DefaultReactRouterOptions | RouteConfigReactRouterOptions;
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 union makes the DX waaay nicer, but I don't want to port it to the routingInstrumentation in fear of breaking anything.

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 78.18 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 69.39 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing, Replay with Canvas) - Webpack (gzipped) 73.28 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 63.01 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 33.41 KB (-0.01% 🔽)
@sentry/browser (incl. browserTracingIntegration) - Webpack (gzipped) 33.28 KB (-0.01% 🔽)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 31.32 KB (-0.01% 🔽)
@sentry/browser (incl. sendFeedback) - Webpack (gzipped) 31.33 KB (-0.01% 🔽)
@sentry/browser - Webpack (gzipped) 22.6 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 76 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 67.54 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 33.44 KB (-0.01% 🔽)
@sentry/browser - ES6 CDN Bundle (gzipped) 24.65 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 213.12 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 101.13 KB (+0.01% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 74.01 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 36.56 KB (-0.01% 🔽)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 69.78 KB (-0.01% 🔽)
@sentry/react - Webpack (gzipped) 22.63 KB (-0.01% 🔽)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 86.45 KB (-0.01% 🔽)
@sentry/nextjs Client - Webpack (gzipped) 50.76 KB (-0.01% 🔽)
@sentry-internal/feedback - Webpack (gzipped) 17.2 KB (-0.02% 🔽)

type ReactRouterOptions = DefaultReactRouterOptions | RouteConfigReactRouterOptions;

// @ts-expect-error Don't type narrow on routes or matchPath to save on bundle size
const _reactRouterV4 = (({ history, routes, matchPath }: ReactRouterOptions) => {
Copy link
Member

Choose a reason for hiding this comment

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

So the main thing I see here is - or maybe I am missing this somehow - that we do not disable the default page load/navigation spans emitted by the default browserTracingIntegration() here 🤔 So this would be emitted twice when a router integration is added, wouldn't it?

@AbhiPrasad
Copy link
Member Author

Upon further conversations async we decided to make this an integration that wraps browserTracingIntegration. Closing this PR for now.

@AbhiPrasad AbhiPrasad closed this Feb 1, 2024
@AbhiPrasad AbhiPrasad deleted the abhi-react-router-v4v5-integration branch February 1, 2024 18:53
mydea added a commit that referenced this pull request Feb 5, 2024
…t router v4 & v5 (#10488)

This adds new `reactRouterV4BrowserTracingIntegration()` and
`reactRouterV5BrowserTracingIntegration()` exports, deprecating these
old routing instrumentations.

I opted to leave as much as possible as-is for now, except for
streamlining the attributes/tags we use for the instrumentation.

Tests lifted from
#10430
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.

3 participants