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 /**
@@ -57,40 +57,40 @@ function connectToSpotlight(client: Client, options: Required<SpotlightConnectio
5757 }
5858
5959 const serializedEnvelope = serializeEnvelope ( envelope ) ;
60-
61- const request = getNativeHttpRequest ( ) ;
62- const req = request (
63- {
64- method : 'POST' ,
65- path : spotlightUrl . pathname ,
66- hostname : spotlightUrl . hostname ,
67- port : spotlightUrl . port ,
68- headers : {
69- 'Content-Type' : 'application/x-sentry-envelope' ,
60+ suppressTracing ( ( ) => {
61+ const req = http . request (
62+ {
63+ method : 'POST' ,
64+ path : spotlightUrl . pathname ,
65+ hostname : spotlightUrl . hostname ,
66+ port : spotlightUrl . port ,
67+ headers : {
68+ 'Content-Type' : 'application/x-sentry-envelope' ,
69+ } ,
7070 } ,
71- } ,
72- res => {
73- if ( res . statusCode && res . statusCode >= 200 && res . statusCode < 400 ) {
74- // Reset failed requests counter on success
75- failedRequests = 0 ;
76- }
77- res . on ( 'data' , ( ) => {
78- // Drain socket
79- } ) ;
80-
81- res . on ( 'end' , ( ) => {
82- // Drain socket
83- } ) ;
84- res . setEncoding ( 'utf8' ) ;
85- } ,
86- ) ;
87-
88- req . on ( 'error' , ( ) => {
89- failedRequests ++ ;
90- logger . warn ( '[Spotlight] Failed to send envelope to Spotlight Sidecar' ) ;
71+ res => {
72+ if ( res . statusCode && res . statusCode >= 200 && res . statusCode < 400 ) {
73+ // Reset failed requests counter on success
74+ failedRequests = 0 ;
75+ }
76+ res . on ( 'data' , ( ) => {
77+ // Drain socket
78+ } ) ;
79+
80+ res . on ( 'end' , ( ) => {
81+ // Drain socket
82+ } ) ;
83+ res . setEncoding ( 'utf8' ) ;
84+ } ,
85+ ) ;
86+
87+ req . on ( 'error' , ( ) => {
88+ failedRequests ++ ;
89+ logger . warn ( '[Spotlight] Failed to send envelope to Spotlight Sidecar' ) ;
90+ } ) ;
91+ req . write ( serializedEnvelope ) ;
92+ req . end ( ) ;
9193 } ) ;
92- req . write ( serializedEnvelope ) ;
93- req . end ( ) ;
9494 } ) ;
9595}
9696
@@ -102,22 +102,3 @@ function parseSidecarUrl(url: string): URL | undefined {
102102 return undefined ;
103103 }
104104}
105-
106- type HttpRequestImpl = typeof http . request ;
107- type WrappedHttpRequest = HttpRequestImpl & { __sentry_original__ : HttpRequestImpl } ;
108-
109- /**
110- * We want to get an unpatched http request implementation to avoid capturing our own calls.
111- */
112- export function getNativeHttpRequest ( ) : HttpRequestImpl {
113- const { request } = http ;
114- if ( isWrapped ( request ) ) {
115- return request . __sentry_original__ ;
116- }
117-
118- return request ;
119- }
120-
121- function isWrapped ( impl : HttpRequestImpl ) : impl is WrappedHttpRequest {
122- return '__sentry_original__' in impl ;
123- }
0 commit comments