Skip to content

Commit 3cab755

Browse files
committed
fix by looking at url :(
1 parent b96fd7f commit 3cab755

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

packages/node/src/integrations/node-fetch/SentryNodeFetchInstrumentation.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { context } from '@opentelemetry/api';
22
import { isTracingSuppressed, VERSION } from '@opentelemetry/core';
33
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
44
import { InstrumentationBase } from '@opentelemetry/instrumentation';
5-
import type { SanitizedRequestData } from '@sentry/core';
5+
import { isSentryRequestUrl, SanitizedRequestData } from '@sentry/core';
66
import {
77
addBreadcrumb,
88
getBreadcrumbLogLevelFromHttpStatusCode,
@@ -17,7 +17,6 @@ import * as diagch from 'diagnostics_channel';
1717
import { NODE_MAJOR, NODE_MINOR } from '../../nodeVersion';
1818
import { mergeBaggageHeaders } from '../../utils/baggage';
1919
import type { UndiciRequest, UndiciResponse } from './types';
20-
import { isNextEdgeRuntime } from '../../utils/isNextEdgeRuntime';
2120

2221
const SENTRY_TRACE_HEADER = 'sentry-trace';
2322
const SENTRY_BAGGAGE_HEADER = 'baggage';
@@ -239,17 +238,21 @@ export class SentryNodeFetchInstrumentation extends InstrumentationBase<SentryNo
239238
* Check if the given outgoing request should be ignored.
240239
*/
241240
private _shouldIgnoreOutgoingRequest(request: UndiciRequest): boolean {
242-
// Never instrument outgoing requests in Edge Runtime
243-
// This can be a problem when running in Next.js Edge Runtime in dev,
244-
// as there edge is simulated but still uses Node under the hood, leaving to problems
245-
if (isTracingSuppressed(context.active()) || isNextEdgeRuntime()) {
241+
if (isTracingSuppressed(context.active())) {
246242
return true;
247243
}
248244

249245
// Add trace propagation headers
250246
const url = getAbsoluteUrl(request.origin, request.path);
251247
const ignoreOutgoingRequests = this.getConfig().ignoreOutgoingRequests;
252248

249+
// Normally, we should not need this, because `suppressTracing` should take care of this
250+
// However, in Next.js Edge Runtime in dev, there is a bug where the edge is simulated but still uses Node under the hood, leading to problems
251+
// So we make sure to ignore outgoing requests to Sentry endpoints
252+
if (isSentryRequestUrl(url, getClient())) {
253+
return true;
254+
}
255+
253256
if (typeof ignoreOutgoingRequests !== 'function' || !url) {
254257
return false;
255258
}

packages/node/src/integrations/node-fetch/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { UndiciInstrumentationConfig } from '@opentelemetry/instrumentation-undici';
22
import { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici';
3-
import type { IntegrationFn } from '@sentry/core';
3+
import { IntegrationFn, isSentryRequestUrl } from '@sentry/core';
44
import { defineIntegration, getClient, hasSpansEnabled, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
55
import { generateInstrumentOnce } from '../../otel/instrument';
66
import type { NodeClient } from '../../sdk/client';
@@ -97,17 +97,17 @@ function getConfigWithDefaults(options: Partial<NodeFetchOptions> = {}): UndiciI
9797
const instrumentationConfig = {
9898
requireParentforSpans: false,
9999
ignoreRequestHook: request => {
100-
// Never instrument outgoing requests in Edge Runtime
101-
// This can be a problem when running in Next.js Edge Runtime in dev,
102-
// as there edge is simulated but still uses Node under the hood, leaving to problems
103-
if (isNextEdgeRuntime()) {
104-
return true;
105-
}
106-
107100
const url = getAbsoluteUrl(request.origin, request.path);
108101
const _ignoreOutgoingRequests = options.ignoreOutgoingRequests;
109102
const shouldIgnore = _ignoreOutgoingRequests && url && _ignoreOutgoingRequests(url);
110103

104+
// Normally, we should not need this, because `suppressTracing` should take care of this
105+
// However, in Next.js Edge Runtime in dev, there is a bug where the edge is simulated but still uses Node under the hood, leading to problems
106+
// So we make sure to ignore outgoing requests to Sentry endpoints
107+
if (isSentryRequestUrl(url, getClient())) {
108+
return true;
109+
}
110+
111111
return !!shouldIgnore;
112112
},
113113
startSpanHook: () => {

packages/node/src/utils/isNextEdgeRuntime.ts

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

0 commit comments

Comments
 (0)