10000 fix(node): Suppress Spotlight calls (#16380) · getsentry/sentry-javascript@3d18c8e · GitHub
[go: up one dir, main page]

Skip to content

Commit 3d18c8e

Browse files
authored
fix(node): Suppress Spotlight calls (#16380)
Uses the established `suppressTracing` wrapper to hide Spotlight calls from OTEL too.
1 parent 3604a08 commit 3d18c8e

File tree

1 file changed

+33
-52
lines changed

1 file changed

+33
-52
lines changed
Lines changed: 33 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as http from 'node:http';
22
import type { Client, Envelope, IntegrationFn } from '@sentry/core';
3-
import { defineIntegration, logger, serializeEnvelope } from '@sentry/core';
3+
import { defineIntegration, logger, serializeEnvelope, suppressTracing } from '@sentry/core';
44

55
type SpotlightConnectionOptions = {
66
/**
@@ -52,40 +52,40 @@ function connectToSpotlight(client: Client, options: Required<SpotlightConnectio
5252
}
5353

5454
const serializedEnvelope = serializeEnvelope(envelope);
55-
56-
const request = getNativeHttpRequest();
57-
const req = request(
58-
{
59-
method: 'POST',
60-
path: spotlightUrl.pathname,
61-
hostname: spotlightUrl.hostname,
62-
port: spotlightUrl.port,
63-
headers: {
64-
'Content-Type': 'application/x-sentry-envelope',
55+
suppressTracing(() => {
56+
const req = http.request(
57+
{
58+
method: 'POST',
59+
path: spotlightUrl.pathname,
60+
hostname: spotlightUrl.hostname,
61+
port: spotlightUrl.port,
62+
headers: {
63+
'Content-Type': 'application/x-sentry-envelope',
64+
},
6565
},
66-
},
67-
res => {
68-
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 400) {
69-
// Reset failed requests counter on success
70-
failedRequests = 0;
71-
}
72-
res.on('data', () => {
73-
// Drain socket
74-
});
75-
76-
res.on('end', () => {
77-
// Drain socket
78-
});
79-
res.setEncoding('utf8');
80-
},
81-
);
82-
83-
req.on('error', () => {
84-
failedRequests++;
85-
logger.warn('[Spotlight] Failed to send envelope to Spotlight Sidecar');
66+
res => {
67+
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 400) {
68+
// Reset failed requests counter on success
69+
failedRequests = 0;
70+
}
71+
res.on('data', () => {
72+
// Drain socket
73+
});
74+
75+
res.on('end', () => {
76+
// Drain socket
77+
});
78+
res.setEncoding('utf8');
79+
},
80+
);
81+
82+
req.on('error', () => {
83+
failedRequests++;
84+
logger.warn('[Spotlight] Failed to send envelope to Spotlight Sidecar');
85+
});
86+
req.write(serializedEnvelope);
87+
req.end();
8688
});
87-
req.write(serializedEnvelope);
88-
req.end();
8989
});
9090
}
9191

@@ -97,22 +97,3 @@ function parseSidecarUrl(url: string): URL | undefined {
9797
return undefined;
9898
}
9999
}
100-
101-
type HttpRequestImpl = typeof http.request;
102-
type WrappedHttpRequest = HttpRequestImpl & { __sentry_original__: HttpRequestImpl };
103-
104-
/**
105-
* We want to get an unpatched http request implementation to avoid capturing our own calls.
106-
*/
107-
export function getNativeHttpRequest(): HttpRequestImpl {
108-
const { request } = http;
109-
if (isWrapped(request)) {
110-
return request.__sentry_original__;
111-
}
112-
113-
return request;
114-
}
115-
116-
function isWrapped(impl: HttpRequestImpl): impl is WrappedHttpRequest {
117-
return '__sentry_original__' in impl;
118-
}

0 commit comments

Comments
 (0)
0