@sentry/nextjs
Version:
Official Sentry SDK for Next.js
40 lines (37 loc) • 1.72 kB
JavaScript
import { HTTP_TARGET } from '@sentry/conventions/attributes';
import { getClient, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, GLOBAL_OBJ } from '@sentry/core';
import { isSentryRequestSpan } from '@sentry/opentelemetry';
import { ATTR_NEXT_SPAN_TYPE } from '../nextSpanAttributes.js';
import { isPathnameUnderSentryTunnelRoute } from './tunnelPathnameMatch.js';
import { TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION } from '../span-attributes-with-logic-attached.js';
const globalWithInjectedValues = GLOBAL_OBJ;
function dropMiddlewareTunnelRequests(span, attrs) {
if (getClient()?.getOptions()?.skipOpenTelemetrySetup) {
return;
}
const isMiddleware = attrs?.[ATTR_NEXT_SPAN_TYPE] === "Middleware.execute";
const isFetchSpan = attrs?.[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] === "auto.http.otel.node_fetch";
const isBaseServerHandleRequest = attrs?.[ATTR_NEXT_SPAN_TYPE] === "BaseServer.handleRequest";
if (!isMiddleware && !isFetchSpan && !isBaseServerHandleRequest) {
return;
}
const isTunnel = isTunnelRouteSpan(attrs || {});
const isSentry = isSentryRequestSpan(span);
if (isTunnel || isSentry) {
span.setAttribute(TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION, true);
}
}
function isTunnelRouteSpan(spanAttributes) {
const tunnelPath = globalWithInjectedValues._sentryRewritesTunnelPath || process.env._sentryRewritesTunnelPath;
if (!tunnelPath) {
return false;
}
const httpTarget = spanAttributes[HTTP_TARGET];
if (typeof httpTarget === "string") {
const pathname = httpTarget.split("?")[0] || "";
return isPathnameUnderSentryTunnelRoute(pathname, tunnelPath);
}
return false;
}
export { dropMiddlewareTunnelRequests };
//# sourceMappingURL=dropMiddlewareTunnelRequests.js.map