Skip to content

Commit ea09821

Browse files
authored
ref(nextjs): Vendor isSentryRequestSpan from opentelemetry package (#22583)
Removing this export from opentelemetry package, instead vendoring this at the only place we are using this.
1 parent b5bf632 commit ea09821

4 files changed

Lines changed: 21 additions & 37 deletions

File tree

packages/nextjs/src/common/utils/dropMiddlewareTunnelRequests.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import { HTTP_TARGET } from '@sentry/conventions/attributes';
2-
import { getClient, GLOBAL_OBJ, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, type Span, type SpanAttributes } from '@sentry/core';
3-
import { isSentryRequestSpan } from '@sentry/opentelemetry';
1+
import { HTTP_TARGET, HTTP_URL, URL_FULL } from '@sentry/conventions/attributes';
2+
import {
3+
getClient,
4+
GLOBAL_OBJ,
5+
isSentryRequestUrl,
6+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
7+
type Span,
8+
type SpanAttributes,
9+
} from '@sentry/core';
410
import { ATTR_NEXT_SPAN_TYPE } from '../nextSpanAttributes';
511
import { isPathnameUnderSentryTunnelRoute } from './tunnelPathnameMatch';
612
import { TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION } from '../span-attributes-with-logic-attached';
@@ -36,14 +42,25 @@ export function dropMiddlewareTunnelRequests(span: Span, attrs: SpanAttributes |
3642

3743
// Check if this is either a tunnel route request or a Sentry ingest request
3844
const isTunnel = isTunnelRouteSpan(attrs || {});
39-
const isSentry = isSentryRequestSpan(span);
45+
const isSentry = isSentryRequestSpan(attrs || {});
4046

4147
if (isTunnel || isSentry) {
4248
// Mark the span to be dropped
4349
span.setAttribute(TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION, true);
4450
}
4551
}
4652

53+
function isSentryRequestSpan(attrs: SpanAttributes): boolean {
54+
// `URL_FULL` is the new attribute, but we still support the old one, `HTTP_URL`, for now.
55+
// eslint-disable-next-line typescript/no-deprecated
56+
const httpUrl = attrs[HTTP_URL] || attrs[URL_FULL];
57+
58+
if (!httpUrl) {
59+
return false;
60+
}
61+
62+
return isSentryRequestUrl(httpUrl.toString(), getClient());
63+
}
4764
/**
4865
* Checks if a span's HTTP target matches the tunnel route.
4966
*/

packages/nextjs/test/utils/dropMiddlewareTunnelRequests.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ vi.mock('@sentry/core', async requireActual => {
1515
};
1616
});
1717

18-
vi.mock('@sentry/opentelemetry', () => ({
19-
isSentryRequestSpan: () => false,
20-
}));
21-
2218
function createMockSpan(): { setAttribute: ReturnType<typeof vi.fn>; attributes: Record<string, unknown> } {
2319
const attributes: Record<string, unknown> = {};
2420
return {

packages/opentelemetry/src/exports.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ export {
1616
// Re-export this for backwards compatibility (this used to be a different implementation)
1717
export { getDynamicSamplingContextFromSpan } from '@sentry/core';
1818

19-
export { isSentryRequestSpan } from './utils/isSentryRequest';
20-
2119
export { enhanceDscWithOpenTelemetryRootSpanName } from './utils/enhanceDscWithOpenTelemetryRootSpanName';
2220

2321
export { getActiveSpan } from './utils/getActiveSpan';

packages/opentelemetry/src/utils/isSentryRequest.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)