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