@sentry/nextjs
Version:
Official Sentry SDK for Next.js
59 lines (56 loc) • 2.65 kB
JavaScript
import { HTTP_ROUTE, CODE_FUNCTION_NAME, SENTRY_DESCRIPTION, SENTRY_OP, SENTRY_NEXTJS_SSR_FUNCTION_ROUTE, SENTRY_NEXTJS_SSR_FUNCTION_TYPE } from '@sentry/conventions/attributes';
import { FUNCTION } from '@sentry/conventions/op';
import { isObjectLike, Scope, hasSpanStreamingEnabled, INTERNAL_setSegmentNameSourceIfSegment } from '@sentry/core';
import { ATTR_NEXT_SEGMENT, ATTR_NEXT_SPAN_TYPE, ATTR_NEXT_SPAN_NAME } from '../nextSpanAttributes.js';
const PAGE_SEGMENT = "__PAGE__";
const commonIsolationScopeMap = /* @__PURE__ */ new WeakMap();
function commonObjectToIsolationScope(commonObject) {
if (isObjectLike(commonObject)) {
const memoIsolationScope = commonIsolationScopeMap.get(commonObject);
if (memoIsolationScope) {
return memoIsolationScope;
} else {
const newIsolationScope = new Scope();
commonIsolationScopeMap.set(commonObject, newIsolationScope);
return newIsolationScope;
}
} else {
return new Scope();
}
}
function isResolveSegmentSpan(spanAttributes) {
return spanAttributes[ATTR_NEXT_SPAN_TYPE] === "NextNodeServer.getLayoutOrPageModule" && spanAttributes[ATTR_NEXT_SPAN_NAME] === "resolve segment modules" && typeof spanAttributes[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[ATTR_NEXT_SEGMENT];
const route = rootSpanAttributes[HTTP_ROUTE];
const enhancedName = segment === PAGE_SEGMENT ? "Page" : "Layout";
const enhancedDescription = getEnhancedResolveSegmentSpanName({
segment,
route: typeof route === "string" ? route : ""
});
activeSpan.updateName(hasSpanStreamingEnabled(client) ? enhancedName : enhancedDescription);
activeSpan.setAttributes({
[SENTRY_NEXTJS_SSR_FUNCTION_TYPE]: segment === PAGE_SEGMENT ? "Page" : "Layout",
[SENTRY_NEXTJS_SSR_FUNCTION_ROUTE]: route,
[SENTRY_OP]: FUNCTION,
[SENTRY_DESCRIPTION]: enhancedDescription,
[CODE_FUNCTION_NAME]: enhancedName,
[HTTP_ROUTE]: route
});
INTERNAL_setSegmentNameSourceIfSegment(activeSpan, "route");
}
export { commonObjectToIsolationScope, getEnhancedResolveSegmentSpanName, isResolveSegmentSpan, maybeEnhanceServerComponentSpanName };
//# sourceMappingURL=tracingUtils.js.map