diff --git a/packages/nextjs/src/common/utils/dropMiddlewareTunnelRequests.ts b/packages/nextjs/src/common/utils/dropMiddlewareTunnelRequests.ts index c4442beaa132..7263efb2030b 100644 --- a/packages/nextjs/src/common/utils/dropMiddlewareTunnelRequests.ts +++ b/packages/nextjs/src/common/utils/dropMiddlewareTunnelRequests.ts @@ -1,6 +1,12 @@ -import { HTTP_TARGET } from '@sentry/conventions/attributes'; -import { getClient, GLOBAL_OBJ, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, type Span, type SpanAttributes } from '@sentry/core'; -import { isSentryRequestSpan } from '@sentry/opentelemetry'; +import { HTTP_TARGET, HTTP_URL, URL_FULL } from '@sentry/conventions/attributes'; +import { + getClient, + GLOBAL_OBJ, + isSentryRequestUrl, + SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, + type Span, + type SpanAttributes, +} from '@sentry/core'; import { ATTR_NEXT_SPAN_TYPE } from '../nextSpanAttributes'; import { isPathnameUnderSentryTunnelRoute } from './tunnelPathnameMatch'; import { TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION } from '../span-attributes-with-logic-attached'; @@ -36,7 +42,7 @@ export function dropMiddlewareTunnelRequests(span: Span, attrs: SpanAttributes | // Check if this is either a tunnel route request or a Sentry ingest request const isTunnel = isTunnelRouteSpan(attrs || {}); - const isSentry = isSentryRequestSpan(span); + const isSentry = isSentryRequestSpan(attrs || {}); if (isTunnel || isSentry) { // Mark the span to be dropped @@ -44,6 +50,17 @@ export function dropMiddlewareTunnelRequests(span: Span, attrs: SpanAttributes | } } +function isSentryRequestSpan(attrs: SpanAttributes): boolean { + // `URL_FULL` is the new attribute, but we still support the old one, `HTTP_URL`, for now. + // eslint-disable-next-line typescript/no-deprecated + const httpUrl = attrs[HTTP_URL] || attrs[URL_FULL]; + + if (!httpUrl) { + return false; + } + + return isSentryRequestUrl(httpUrl.toString(), getClient()); +} /** * Checks if a span's HTTP target matches the tunnel route. */ diff --git a/packages/nextjs/test/utils/dropMiddlewareTunnelRequests.test.ts b/packages/nextjs/test/utils/dropMiddlewareTunnelRequests.test.ts index 2d933373578d..1affd8a732df 100644 --- a/packages/nextjs/test/utils/dropMiddlewareTunnelRequests.test.ts +++ b/packages/nextjs/test/utils/dropMiddlewareTunnelRequests.test.ts @@ -15,10 +15,6 @@ vi.mock('@sentry/core', async requireActual => { }; }); -vi.mock('@sentry/opentelemetry', () => ({ - isSentryRequestSpan: () => false, -})); - function createMockSpan(): { setAttribute: ReturnType; attributes: Record } { const attributes: Record = {}; return { diff --git a/packages/opentelemetry/src/exports.ts b/packages/opentelemetry/src/exports.ts index 7816f437351c..641f10bc4bef 100644 --- a/packages/opentelemetry/src/exports.ts +++ b/packages/opentelemetry/src/exports.ts @@ -16,8 +16,6 @@ export { // Re-export this for backwards compatibility (this used to be a different implementation) export { getDynamicSamplingContextFromSpan } from '@sentry/core'; -export { isSentryRequestSpan } from './utils/isSentryRequest'; - export { enhanceDscWithOpenTelemetryRootSpanName } from './utils/enhanceDscWithOpenTelemetryRootSpanName'; export { getActiveSpan } from './utils/getActiveSpan'; diff --git a/packages/opentelemetry/src/utils/isSentryRequest.ts b/packages/opentelemetry/src/utils/isSentryRequest.ts deleted file mode 100644 index 012c769b2f5b..000000000000 --- a/packages/opentelemetry/src/utils/isSentryRequest.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { HTTP_URL, URL_FULL } from '@sentry/conventions/attributes'; -import { getClient, isSentryRequestUrl } from '@sentry/core'; -import type { AbstractSpan } from '../types'; -import { spanHasAttributes } from './spanTypes'; - -/** - * - * @param otelSpan Checks whether a given OTEL Span is an http request to sentry. - * @returns boolean - */ -export function isSentryRequestSpan(span: AbstractSpan): boolean { - if (!spanHasAttributes(span)) { - return false; - } - - const { attributes } = span; - - // `URL_FULL` is the new attribute, but we still support the old one, `HTTP_URL`, for now. - // eslint-disable-next-line typescript/no-deprecated - const httpUrl = attributes[HTTP_URL] || attributes[URL_FULL]; - - if (!httpUrl) { - return false; - } - - return isSentryRequestUrl(httpUrl.toString(), getClient()); -}