@sentry/nextjs
Version:
Official Sentry SDK for Next.js
30 lines (27 loc) • 1.3 kB
JavaScript
import { HTTP_ROUTE, URL_PATH, HTTP_TARGET } from '@sentry/conventions/attributes';
import { getClient } from '@sentry/core';
import { getSanitizedRequestUrl } from './urls.js';
function setUrlProcessingMetadata(event) {
if (event.type !== "transaction" || event.contexts?.trace?.op !== "http.server" || !event.contexts?.trace?.data) {
return;
}
const client = getClient();
if (!client) {
return;
}
const traceData = event.contexts.trace.data;
const componentRoute = traceData["next.route"] || traceData[HTTP_ROUTE];
const httpTarget = traceData[URL_PATH] ?? traceData[HTTP_TARGET];
if (!componentRoute) {
return;
}
const isolationScopeData = event.sdkProcessingMetadata?.capturedSpanIsolationScope?.getScopeData();
const headersDict = isolationScopeData?.sdkProcessingMetadata?.normalizedRequest?.headers;
const url = getSanitizedRequestUrl(componentRoute, void 0, headersDict, httpTarget?.toString());
if (url && isolationScopeData?.sdkProcessingMetadata) {
isolationScopeData.sdkProcessingMetadata.normalizedRequest = isolationScopeData.sdkProcessingMetadata.normalizedRequest || {};
isolationScopeData.sdkProcessingMetadata.normalizedRequest.url = url;
}
}
export { setUrlProcessingMetadata };
//# sourceMappingURL=setUrlProcessingMetadata.js.map