UNPKG

@sentry/nextjs

Version:
68 lines (64 loc) • 2.99 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const attributes = require('@sentry/conventions/attributes'); const op = require('@sentry/conventions/op'); const core = require('@sentry/core'); const react = require('@sentry/react'); const parameterization = require('./parameterization.js'); const traceMetaTags = require('./traceMetaTags.js'); const PAGELOAD_TRACE_META_TAG_TIMEOUT_MS = 1e4; let pendingPageloadWait; function settlePendingPageloadWait() { pendingPageloadWait?.giveUp(); } function startPageloadSpan(client, spanOptions, documentUrl, traceMetaTags$1) { const span = react.startBrowserTracingPageLoadSpan(client, traceMetaTags.withCacheOrigin(spanOptions, traceMetaTags$1), traceMetaTags$1); const scope = core.getCurrentScope(); const { normalizedRequest } = scope.getScopeData().sdkProcessingMetadata; if (normalizedRequest) { scope.setSDKProcessingMetadata({ normalizedRequest: { ...normalizedRequest, url: documentUrl } }); } return span; } function appRouterInstrumentPageLoad(client) { const documentUrl = core.filterCollectedUrl(react.WINDOW.location.href, client); const pathname = parameterization.stripTrailingSlash(react.WINDOW.location.pathname); const parameterizedPathname = react.resolveCurrentRoute(client); const spanOptions = { // With span streaming, span names have to be low cardinality, so we can't fall back to the URL. name: parameterizedPathname ?? (core.hasSpanStreamingEnabled(client) ? core.PAGELOAD_SPAN_NAME_FALLBACK : pathname), // pageload should always start at timeOrigin (and needs to be in s, not ms) attributes: { [attributes.SENTRY_OP]: op.PAGELOAD, [attributes.SENTRY_ORIGIN]: "auto.pageload.nextjs.app_router_instrumentation", [attributes.SENTRY_SEGMENT_NAME_SOURCE]: parameterizedPathname ? "route" : "url", [attributes.URL_PATH]: react.WINDOW.location.pathname, [attributes.URL_FULL]: documentUrl, [attributes.URL_TEMPLATE]: parameterizedPathname } }; const traceMetaTags$1 = traceMetaTags.readTraceMetaTags(); if (traceMetaTags$1 || !traceMetaTags.canWaitForTraceMetaTag()) { startPageloadSpan(client, spanOptions, documentUrl, traceMetaTags$1); return; } pendingPageloadWait = traceMetaTags.waitForTraceMetaTag( (values) => { pendingPageloadWait = void 0; startPageloadSpan(client, spanOptions, documentUrl, values); }, () => { pendingPageloadWait = void 0; const span = startPageloadSpan(client, spanOptions, documentUrl); if (span) { traceMetaTags.waitForTraceMetaTag( (values) => span.isRecording() && traceMetaTags.addTraceMetaTagLink(span, values), () => void 0 ); } }, PAGELOAD_TRACE_META_TAG_TIMEOUT_MS ); } exports.appRouterInstrumentPageLoad = appRouterInstrumentPageLoad; exports.settlePendingPageloadWait = settlePendingPageloadWait; //# sourceMappingURL=appRouterPageloadInstrumentation.js.map