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
1 line
3.6 KiB
Plaintext
1 line
3.6 KiB
Plaintext
{"version":3,"file":"dropMiddlewareTunnelRequests.js","sources":["../../../../src/common/utils/dropMiddlewareTunnelRequests.ts"],"sourcesContent":["import { SEMATTRS_HTTP_TARGET } from '@opentelemetry/semantic-conventions';\nimport { GLOBAL_OBJ, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, type Span, type SpanAttributes } from '@sentry/core';\nimport { isSentryRequestSpan } from '@sentry/opentelemetry';\nimport { ATTR_NEXT_SPAN_TYPE } from '../nextSpanAttributes';\nimport { TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION } from '../span-attributes-with-logic-attached';\n\nconst globalWithInjectedValues = GLOBAL_OBJ as typeof GLOBAL_OBJ & {\n _sentryRewritesTunnelPath?: string;\n};\n\n/**\n * Drops spans for tunnel requests from middleware or fetch instrumentation.\n * This catches both:\n * 1. Requests to the local tunnel route (before rewrite)\n * 2. Requests to Sentry ingest (after rewrite)\n */\nexport function dropMiddlewareTunnelRequests(span: Span, attrs: SpanAttributes | undefined): void {\n // Only filter middleware spans or HTTP fetch spans\n const isMiddleware = attrs?.[ATTR_NEXT_SPAN_TYPE] === 'Middleware.execute';\n // The fetch span could be originating from rewrites re-writing a tunnel request\n // So we want to filter it out\n const isFetchSpan = attrs?.[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] === 'auto.http.otel.node_fetch';\n\n // If the span is not a middleware span or a fetch span, return\n if (!isMiddleware && !isFetchSpan) {\n return;\n }\n\n // Check if this is either a tunnel route request or a Sentry ingest request\n const isTunnel = isTunnelRouteSpan(attrs || {});\n const isSentry = isSentryRequestSpan(span);\n\n if (isTunnel || isSentry) {\n // Mark the span to be dropped\n span.setAttribute(TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION, true);\n }\n}\n\n/**\n * Checks if a span's HTTP target matches the tunnel route.\n */\nfunction isTunnelRouteSpan(spanAttributes: Record<string, unknown>): boolean {\n const tunnelPath = globalWithInjectedValues._sentryRewritesTunnelPath || process.env._sentryRewritesTunnelPath;\n if (!tunnelPath) {\n return false;\n }\n\n // eslint-disable-next-line deprecation/deprecation\n const httpTarget = spanAttributes[SEMATTRS_HTTP_TARGET];\n\n if (typeof httpTarget === 'string') {\n // Extract pathname from the target (e.g., \"/tunnel?o=123&p=456\" -> \"/tunnel\")\n const pathname = httpTarget.split('?')[0] || '';\n\n return pathname.startsWith(tunnelPath);\n }\n\n return false;\n}\n"],"names":["GLOBAL_OBJ","ATTR_NEXT_SPAN_TYPE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","isSentryRequestSpan","TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION","SEMATTRS_HTTP_TARGET"],"mappings":";;;;;;;;AAMA,MAAM,wBAAA,GAA2BA;;AAEjC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,4BAA4B,CAAC,IAAI,EAAQ,KAAK,EAAoC;AAClG;AACA,EAAE,MAAM,eAAe,KAAK,GAAGC,sCAAmB,CAAA,KAAM,oBAAoB;AAC5E;AACA;AACA,EAAE,MAAM,cAAc,KAAK,GAAGC,qCAAgC,CAAA,KAAM,2BAA2B;;AAE/F;AACA,EAAE,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE;AACrC,IAAI;AACJ,EAAE;;AAEF;AACA,EAAE,MAAM,WAAW,iBAAiB,CAAC,KAAA,IAAS,EAAE,CAAC;AACjD,EAAE,MAAM,QAAA,GAAWC,iCAAmB,CAAC,IAAI,CAAC;;AAE5C,EAAE,IAAI,QAAA,IAAY,QAAQ,EAAE;AAC5B;AACA,IAAI,IAAI,CA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