UNPKG

@sentry/nextjs

Version:
94 lines (90 loc) 3.87 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const attributes = require('@sentry/conventions/attributes'); const core = require('@sentry/core'); const debugBuild = require('../debug-build.js'); const nextSpanAttributes = require('../nextSpanAttributes.js'); const spanAttributesWithLogicAttached = require('../span-attributes-with-logic-attached.js'); const PAGE_SEGMENT = "__PAGE__"; const commonIsolationScopeMap = /* @__PURE__ */ new WeakMap(); function commonObjectToIsolationScope(commonObject) { if (core.isObjectLike(commonObject)) { const memoIsolationScope = commonIsolationScopeMap.get(commonObject); if (memoIsolationScope) { return memoIsolationScope; } else { const newIsolationScope = new core.Scope(); commonIsolationScopeMap.set(commonObject, newIsolationScope); return newIsolationScope; } } else { return new core.Scope(); } } let nextjsEscapedAsyncStorage; function escapeNextjsTracing(cb) { const MaybeGlobalAsyncLocalStorage = core.GLOBAL_OBJ.AsyncLocalStorage; if (!MaybeGlobalAsyncLocalStorage) { debugBuild.DEBUG_BUILD && core.debug.warn( "Tried to register AsyncLocalStorage async context strategy in a runtime that doesn't support AsyncLocalStorage." ); return cb(); } if (!nextjsEscapedAsyncStorage) { nextjsEscapedAsyncStorage = new MaybeGlobalAsyncLocalStorage(); } if (nextjsEscapedAsyncStorage.getStore()) { return cb(); } else { return core.startNewTrace(() => { return nextjsEscapedAsyncStorage.run(true, () => { return cb(); }); }); } } function dropNextjsRootContext() { if (core.getClient()?.getOptions()?.skipOpenTelemetrySetup) { return; } const nextJsOwnedSpan = core.getActiveSpan(); if (nextJsOwnedSpan) { const rootSpan = core.getRootSpan(nextJsOwnedSpan); const rootSpanAttributes = core.spanToJSON(rootSpan).data; if (rootSpanAttributes?.["next.span_type"]) { core.getRootSpan(nextJsOwnedSpan)?.setAttribute(spanAttributesWithLogicAttached.TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION, true); } } } function isResolveSegmentSpan(spanAttributes) { return spanAttributes[nextSpanAttributes.ATTR_NEXT_SPAN_TYPE] === "NextNodeServer.getLayoutOrPageModule" && spanAttributes[nextSpanAttributes.ATTR_NEXT_SPAN_NAME] === "resolve segment modules" && typeof spanAttributes[nextSpanAttributes.ATTR_NEXT_SEGMENT] === "string"; } function getEnhancedResolveSegmentSpanName({ segment, route }) { if (segment === PAGE_SEGMENT) { return `resolve page server component "${route}"`; } if (segment === "") { return "resolve root layout server component"; } return `resolve layout server component "${segment}"`; } function maybeEnhanceServerComponentSpanName(activeSpan, spanAttributes, rootSpanAttributes) { if (!isResolveSegmentSpan(spanAttributes)) { return; } const segment = spanAttributes[nextSpanAttributes.ATTR_NEXT_SEGMENT]; const route = rootSpanAttributes[attributes.HTTP_ROUTE]; const enhancedName = getEnhancedResolveSegmentSpanName({ segment, route: typeof route === "string" ? route : "" }); activeSpan.updateName(enhancedName); activeSpan.setAttributes({ "sentry.nextjs.ssr.function.type": segment === PAGE_SEGMENT ? "Page" : "Layout", "sentry.nextjs.ssr.function.route": route }); activeSpan.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, "function.nextjs"); } exports.commonObjectToIsolationScope = commonObjectToIsolationScope; exports.dropNextjsRootContext = dropNextjsRootContext; exports.escapeNextjsTracing = escapeNextjsTracing; exports.getEnhancedResolveSegmentSpanName = getEnhancedResolveSegmentSpanName; exports.isResolveSegmentSpan = isResolveSegmentSpan; exports.maybeEnhanceServerComponentSpanName = maybeEnhanceServerComponentSpanName; //# sourceMappingURL=tracingUtils.js.map