Skip to content
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

feat: Add instrumentation for React Router v3 #2759

Merged
merged 3 commits into from Jul 22, 2020

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Jul 21, 2020

Just making my contribution to what will soon be the biggest yarn.lock file ever 😎

This PR adds instrumentation support for react-router v3. This is based entirely on the excellent getsentry/sentry implementation. To see how it works, see below:

// Must be `react-router` >= v3.2.0 and < 4.0.0
import * as Router from 'react-router';
import { reactRouterV3Instrumentation  } from '@sentry/react';

// Rendered below
const routes = (
  <Route />
  <Route />
  <Route />
);

// Have to generate PlainRoutes from routes
const appRoutes = Router.createRoutes(routes);

Sentry.init({
  tracesSampleRate: 1,
  integrations: [
    new Integrations.BrowserTracing({
      routingInstrumentation: reactRouterV3Instrumentation(Router.browserHistory, appRoutes, Router.match),
    });
  ]
});

If you notice, we make the user pass in a history, routes and Router.match. This is so that is is easier to test, can accommodate various history settings (hashRouting, browserRouting) and we don't make any assumptions on dependencies.

This is tested on Sentry and unit tested.

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 93.18 89.19 100 92.5
reactrouter.tsx 93.18 89.19 100 92.5 100,105,119

@github-actions
Copy link
Contributor

github-actions bot commented Jul 21, 2020

size-limit report

Path Size Loading time (3g) Running time (snapdragon) Total time
@sentry/browser - CDN Bundle (gzipped) 17.64 KB (+0.01% 🔺) 353 ms (+0.01% 🔺) 409 ms (-27.24% 🔽) 762 ms
@sentry/browser - Webpack 18.39 KB (0%) 368 ms (0%) 873 ms (+24.66% 🔺) 1.3 s
@sentry/react - Webpack 18.39 KB (0%) 368 ms (0%) 860 ms (+40.02% 🔺) 1.3 s
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 22.57 KB (0%) 452 ms (0%) 367 ms (-5.66% 🔽) 818 ms

@getsentry-bot
Copy link
Contributor

getsentry-bot commented Jul 21, 2020

Warnings
⚠️ Please add a changelog entry for your changes.
Messages
📖

@sentry/browser bundle gzip'ed minified size: (ES5: 17.2363 kB) (ES6: 16.3525 kB)

📖 ✅ TSLint passed

Generated by 🚫 dangerJS against bd89da7

Copy link
Member

@HazAT HazAT left a comment

Choose a reason for hiding this comment

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

Looks solid :)

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.

None yet

3 participants