11import * as http from 'node:http' ;
22import 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
55type 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