99 getHttpClientSubscriptions ,
1010 getIsolationScope ,
1111 HTTP_ON_CLIENT_REQUEST ,
12+ HTTP_ON_CLIENT_REQUEST_FALLBACK ,
1213 httpRequestToRequestData ,
1314 stripUrlQueryAndFragment ,
1415 withIsolationScope ,
@@ -19,9 +20,15 @@ import { patchRequestToCaptureBody } from '../../utils/captureRequestBody';
1920import { getRequestOptions } from '../../utils/outgoingHttpRequest' ;
2021import type { LightNodeClient } from '../client' ;
2122import { errorMonitor } from 'node:events' ;
23+ import { NODE_VERSION } from '../../nodeVersion' ;
2224
2325const INTEGRATION_NAME = 'Http' ;
2426
27+ const FULLY_SUPPORTS_HTTP_DIAGNOSTICS_CHANNEL =
28+ ( NODE_VERSION . major === 22 && NODE_VERSION . minor >= 12 ) ||
29+ ( NODE_VERSION . major === 23 && NODE_VERSION . minor >= 2 ) ||
30+ NODE_VERSION . major >= 24 ;
31+
2532// We keep track of emit functions we wrapped, to avoid double wrapping
2633const wrappedEmitFns = new WeakSet < typeof Server . prototype . emit > ( ) ;
2734
@@ -99,6 +106,10 @@ const _httpIntegration = ((options: HttpIntegrationOptions = {}) => {
99106
100107 const { ignoreOutgoingRequests } = _options ;
101108
109+ const channel = FULLY_SUPPORTS_HTTP_DIAGNOSTICS_CHANNEL
110+ ? HTTP_ON_CLIENT_REQUEST
111+ : HTTP_ON_CLIENT_REQUEST_FALLBACK ;
112+
102113 const { [ HTTP_ON_CLIENT_REQUEST ] : onHttpClientRequestCreated } = getHttpClientSubscriptions ( {
103114 breadcrumbs : _options . breadcrumbs ,
104115 propagateTrace : _options . tracePropagation ,
@@ -111,7 +122,9 @@ const _httpIntegration = ((options: HttpIntegrationOptions = {}) => {
111122 } ) ;
112123
113124 subscribe ( 'http.server.request.start' , onHttpServerRequestStart ) ;
114- subscribe ( HTTP_ON_CLIENT_REQUEST , onHttpClientRequestCreated ) ;
125+ // Subscribe on the request creation in node versions that support it,
126+ // or to the request start (ie, .end() being called) on older versions.
127+ subscribe ( channel , onHttpClientRequestCreated ) ;
115128 } ,
116129 } ;
117130} ) satisfies IntegrationFn ;
0 commit comments