UNPKG

@sentry/nextjs

Version:
64 lines (60 loc) • 2.82 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 nextSpanAttributes = require('../nextSpanAttributes.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(); } } 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, client) { if (!isResolveSegmentSpan(spanAttributes)) { return; } const segment = spanAttributes[nextSpanAttributes.ATTR_NEXT_SEGMENT]; const route = rootSpanAttributes[attributes.HTTP_ROUTE]; const enhancedName = segment === PAGE_SEGMENT ? "Page" : "Layout"; const enhancedDescription = getEnhancedResolveSegmentSpanName({ segment, route: typeof route === "string" ? route : "" }); activeSpan.updateName(core.hasSpanStreamingEnabled(client) ? enhancedName : enhancedDescription); activeSpan.setAttributes({ [attributes.SENTRY_NEXTJS_SSR_FUNCTION_TYPE]: segment === PAGE_SEGMENT ? "Page" : "Layout", [attributes.SENTRY_NEXTJS_SSR_FUNCTION_ROUTE]: route, [attributes.SENTRY_OP]: op.FUNCTION, [attributes.SENTRY_DESCRIPTION]: enhancedDescription, [attributes.CODE_FUNCTION_NAME]: enhancedName, [attributes.HTTP_ROUTE]: route }); core.INTERNAL_setSegmentNameSourceIfSegment(activeSpan, "route"); } exports.commonObjectToIsolationScope = commonObjectToIsolationScope; exports.getEnhancedResolveSegmentSpanName = getEnhancedResolveSegmentSpanName; exports.isResolveSegmentSpan = isResolveSegmentSpan; exports.maybeEnhanceServerComponentSpanName = maybeEnhanceServerComponentSpanName; //# sourceMappingURL=tracingUtils.js.map