Skip to content

Commit

Permalink
fix(node): Use suppressTracing to avoid capturing otel spans (getse…
Browse files Browse the repository at this point in the history
…ntry#11288)

I leave the other checks (e.g. in http integration) in there, for now
(where we check if the url is sentry URL), but this should ensure we are
also not picked up by any other OTEL instrumentation etc.
  • Loading branch information
mydea authored and cadesalaberry committed Apr 19, 2024
1 parent df29db5 commit 4f86046
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/node-experimental/src/transports/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as http from 'node:http';
import * as https from 'node:https';
import { Readable } from 'stream';
import { createGzip } from 'zlib';
import { context } from '@opentelemetry/api';
import { suppressTracing } from '@opentelemetry/core';
import { createTransport } from '@sentry/core';
import type {
BaseTransportOptions,
Expand All @@ -12,7 +14,6 @@ import type {
} from '@sentry/types';
import { consoleSandbox } from '@sentry/utils';
import { HttpsProxyAgent } from '../proxy';

import type { HTTPModule } from './http-module';

export interface NodeTransportOptions extends BaseTransportOptions {
Expand Down Expand Up @@ -80,8 +81,11 @@ export function makeNodeTransport(options: NodeTransportOptions): Transport {
? (new HttpsProxyAgent(proxy) as http.Agent)
: new nativeHttpModule.Agent({ keepAlive, maxSockets: 30, timeout: 2000 });

const requestExecutor = createRequestExecutor(options, options.httpModule ?? nativeHttpModule, agent);
return createTransport(options, requestExecutor);
// This ensures we do not generate any spans in OpenTelemetry for the transport
return context.with(suppressTracing(context.active()), () => {
const requestExecutor = createRequestExecutor(options, options.httpModule ?? nativeHttpModule, agent);
return createTransport(options, requestExecutor);
});
}

/**
Expand Down

0 comments on commit 4f86046

Please sign in to comment.