Files
klz-cables.com/.pnpm-store/v10/files/7d/67d6a650f4cd009b60bbc5f7f3feee365af66914fc8543637cb76f7f1626d5bb2cca0af5ffb78a593000e90e970d9f0bd7374ac197d26c11a3ea08b7674b76
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

94 lines
3.4 KiB
Plaintext

import { withIsolationScope, getCurrentScope, winterCGRequestToRequestData, getActiveSpan, getRootSpan, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_OP, setCapturedScopesOnSpan, startSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, handleCallbackErrors, captureException } from '@sentry/core';
import { addHeadersAsAttributes } from '../common/utils/addHeadersAsAttributes.js';
import { waitUntil, flushSafelyWithTimeout } from '../common/utils/responseEnd.js';
/**
* Wraps a Next.js edge route handler with Sentry error and performance instrumentation.
*/
function wrapApiHandlerWithSentry(
handler,
parameterizedRoute,
) {
return new Proxy(handler, {
apply: async (wrappingTarget, thisArg, args) => {
// TODO: We still should add central isolation scope creation for when our build-time instrumentation does not work anymore with turbopack.
return withIsolationScope(isolationScope => {
const req = args[0];
const currentScope = getCurrentScope();
let headerAttributes = {};
if (req instanceof Request) {
isolationScope.setSDKProcessingMetadata({
normalizedRequest: winterCGRequestToRequestData(req),
});
currentScope.setTransactionName(`${req.method} ${parameterizedRoute}`);
headerAttributes = addHeadersAsAttributes(req.headers);
} else {
currentScope.setTransactionName(`handler (${parameterizedRoute})`);
}
let spanName;
let op = 'http.server';
// If there is an active span, it likely means that the automatic Next.js OTEL instrumentation worked and we can
// rely on that for parameterization.
const activeSpan = getActiveSpan();
if (activeSpan) {
spanName = `handler (${parameterizedRoute})`;
op = undefined;
const rootSpan = getRootSpan(activeSpan);
if (rootSpan) {
rootSpan.updateName(
req instanceof Request ? `${req.method} ${parameterizedRoute}` : `handler ${parameterizedRoute}`,
);
rootSpan.setAttributes({
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
...headerAttributes,
});
setCapturedScopesOnSpan(rootSpan, currentScope, isolationScope);
}
} else if (req instanceof Request) {
spanName = `${req.method} ${parameterizedRoute}`;
} else {
spanName = `handler ${parameterizedRoute}`;
}
return startSpan(
{
name: spanName,
op: op,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.wrap_api_handler',
...headerAttributes,
},
},
() => {
return handleCallbackErrors(
() => wrappingTarget.apply(thisArg, args),
error => {
captureException(error, {
mechanism: {
type: 'auto.function.nextjs.wrap_api_handler',
handled: false,
},
});
},
() => {
waitUntil(flushSafelyWithTimeout());
},
);
},
);
});
},
});
}
export { wrapApiHandlerWithSentry };
//# sourceMappingURL=wrapApiHandlerWithSentry.js.map