-
-
Couldn't load subscription status.
- Fork 1.7k
Using Sentry Performance Monitoring with Inertia.js #8528
-
Errors instrumentation should work out of the box with Inertia.js, but you'll have to do some more work to get it working for performance monitoring. In particular, you'll need to give information to Sentry about the inertia router so that Sentry can generate pageload and navigations appropriately.
Adding Inertia support with Sentry performance monitoring depends on if you are using Sentry.BrowserTracing or `Sentry.browserTracingIntegration.
If you are using Sentry.browserTracingIntegration, first disable the automatic routing instrumentation, and then initialize pageloads/navigations yourself accordingly via the inertia router.
Sentry.init({ integrations: [ Sentry.browserTracingIntegration({ // disable automatic span creation instrumentNavigation: false, instrumentPageLoad: false, }), ], }); // We start the pageload span as early as possible! let name = route().current(); let pageLoadSpan = Sentry.startBrowserTracingPageLoadSpan({ op: "pageload", name }); router.on("before", (route) => { const client = Sentry.getClient(); const newName = route().current(); if (newName !== name) { name = newName; Sentry.startBrowserTracingNavigationSpan(client, { op: "navigation", name, attributes: { [Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route", }, }); } } }); router.on('finish', () => { name = route().current(); // always make sure we are using the correct route name const span = Sentry.getActiveSpan(); const op = span && Sentry.spanToJSON(span).op; if (op === 'pageload' || op === 'navigation) { span.setName(name); } });
If you are using Sentry.BrowserTracing, create a routingInstrumentation that listens in on the inertia router.
// Uses https://inertiajs.com/events function inertiaRoutingInstrumentation( customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true, ) { let activeTransaction; let name; if (startTransactionOnPageLoad) { name = route().current(); activeTransaction = customStartTransaction({ name, op: 'pageload', metadata: { source: 'route', }, }); } if (startTransactionOnLocationChange) { router.on('before', (_to, _from) => { if (activeTransaction) { activeTransaction.finish(); } const newName = route().current(); if (newName !== name) { activeTransaction = customStartTransaction({ name: newName, op: 'navigation', metadata: { source: 'route', }, }); } }); router.on('finish', () => { activeTransaction.setName(route().current(), 'route'); }); } } Sentry.init({ dsn: '__PUBLIC_DSN__', tracesSampleRate: 1.0, integrations: [ new Sentry.BrowserTracing({ routingInstrumentation: inertiaRoutingInstrumentation, }), ], });
Beta Was this translation helpful? Give feedback.
All reactions
-
🎉 8 -
❤️ 1 -
🚀 1
Replies: 1 comment 1 reply
-
Hello
Question about @sentry/vue ver. 1.0.15,
Sentry.init({
dsn: 'PUBLIC_DSN',
tracesSampleRate: 1.0,
integrations: [
new Sentry.BrowserTracing({
routingInstrumentation: inertiaRoutingInstrumentation,
}),
],
});
I got warning:
Deprecated symbol used, consult docs for better alternative
Method expression is not of Function type
Now, I should use Sentry.browserTracingIntegration
But in Sentry.browserTracingIntegration I can't find routingInstrumentation or alternatives for this option, do you have any advice?
Beta Was this translation helpful? Give feedback.
All reactions
-
@RChutchev with Sentry.browserTracingIntegration, custom routing has changed a bit. See the docs to see how to set it up. https://docs.sentry.io/platforms/javascript/performance/instrumentation/automatic-instrumentation/#custom-routing
I'll mark a TODO on the guide to update this!
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2