@@ -23,6 +23,8 @@ const dc = require('diagnostics_channel');
23
23
const {
24
24
kHttpClientAbortCount,
25
25
kHttpClientCount,
26
+ kHttpServerAbortCount,
27
+ kHttpServerCount,
26
28
kSpanHttpClient,
27
29
kSpanHttpMethod,
28
30
kSpanHttpReqUrl,
@@ -31,6 +33,9 @@ const {
31
33
32
34
const undiciFetch = dc . tracingChannel ( 'undici:fetch' ) ;
33
35
36
+ // To lazy load the http2 constants
37
+ let http2Constants ;
38
+
34
39
let tracingEnabled = false ;
35
40
36
41
const fetchSubscribeListener = ( message , name ) => { } ;
@@ -119,3 +124,47 @@ dc.subscribe('undici:request:error', ({ request, error }) => {
119
124
}
120
125
}
121
126
} ) ;
127
+
128
+ dc . subscribe ( 'http2.client.stream.created' , ( { stream } ) => {
129
+ stream [ nsolid_tracer_s ] = {
130
+ start : now ( ) ,
131
+ response : false ,
132
+ } ;
133
+ } ) ;
134
+
135
+ dc . subscribe ( 'http2.client.stream.finish' , ( { stream, flags } ) => {
136
+ stream [ nsolid_tracer_s ] . response = true ;
137
+ } ) ;
138
+
139
+ dc . subscribe ( 'http2.client.stream.close' , ( { stream, code } ) => {
140
+ http2Constants ||= require ( 'internal/http2/core' ) . constants ;
141
+ const tracingInfo = stream [ nsolid_tracer_s ] ;
142
+ if ( code === http2Constants . NGHTTP2_NO_ERROR && tracingInfo . response ) {
143
+ nsolid_counts [ kHttpClientCount ] ++ ;
144
+ nsolidApi . pushClientBucket ( now ( ) - tracingInfo . start ) ;
145
+ } else {
146
+ nsolid_counts [ kHttpClientAbortCount ] ++ ;
147
+ }
148
+ } ) ;
149
+
150
+ dc . subscribe ( 'http2.server.stream.start' , ( { stream } ) => {
151
+ stream [ nsolid_tracer_s ] = {
152
+ start : now ( ) ,
153
+ response : false ,
154
+ } ;
155
+ } ) ;
156
+
157
+ dc . subscribe ( 'http2.server.stream.finish' , ( { stream, flags } ) => {
158
+ stream [ nsolid_tracer_s ] . response = true ;
159
+ } ) ;
160
+
161
+ dc . subscribe ( 'http2.server.stream.close' , ( { stream, code } ) => {
162
+ http2Constants ||= require ( 'internal/http2/core' ) . constants ;
163
+ const tracingInfo = stream [ nsolid_tracer_s ] ;
164
+ if ( code === http2Constants . NGHTTP2_NO_ERROR && tracingInfo . response ) {
165
+ nsolid_counts [ kHttpServerCount ] ++ ;
166
+ nsolidApi . pushServerBucket ( now ( ) - tracingInfo . start ) ;
167
+ } else {
168
+ nsolid_counts [ kHttpServerAbortCount ] ++ ;
169
+ }
170
+ } ) ;
0 commit comments