UNPKG

@sentry/nextjs

Version:
43 lines (39 loc) • 1.87 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const core = require('@sentry/core'); const react = require('@sentry/react'); const RouterImport = require('next/router'); const attributes = require('@sentry/conventions/attributes'); const op = require('@sentry/conventions/op'); const pagesRouterRoutingInstrumentation = require('./pagesRouterRoutingInstrumentation.js'); const Router = RouterImport.default.events ? RouterImport.default : RouterImport.default.default; function pagesRouterInstrumentNavigation(client) { Router.events.on("routeChangeStart", (navigationTarget) => { const strippedNavigationTarget = core.stripUrlQueryAndFragment(navigationTarget); const matchedRoute = pagesRouterRoutingInstrumentation.getNextRouteFromPathname(strippedNavigationTarget); let newLocation; let spanSource; if (matchedRoute) { newLocation = matchedRoute; spanSource = "route"; } else { newLocation = strippedNavigationTarget; spanSource = "url"; } react.startBrowserTracingNavigationSpan( client, { // With span streaming, span names have to be low cardinality, so we can't fall back to the URL. name: spanSource === "route" || !core.hasSpanStreamingEnabled(client) ? newLocation : core.NAVIGATION_SPAN_NAME_FALLBACK, attributes: { [attributes.SENTRY_OP]: op.NAVIGATION, [attributes.SENTRY_ORIGIN]: "auto.navigation.nextjs.pages_router_instrumentation", [attributes.SENTRY_SEGMENT_NAME_SOURCE]: spanSource, ...spanSource === "route" && { [attributes.URL_TEMPLATE]: newLocation } } }, { url: react.getAbsoluteUrl(navigationTarget) } ); }); } exports.pagesRouterInstrumentNavigation = pagesRouterInstrumentNavigation; //# sourceMappingURL=pagesRouterNavigationInstrumentation.js.map