@@ -244,10 +244,21 @@ class GitpodJsonRpcConnectionHandler<T extends object> extends JsonRpcConnection
244
244
onConnection ( connection : MessageConnection , request ?: object ) : void {
245
245
const clientMetadata = ClientMetadata . fromRequest ( request ) ;
246
246
247
+ // trace the ws connection itself
248
+ const span = opentracing . globalTracer ( ) . startSpan ( "ws-connection" ) ;
249
+ const ctx = { span } ;
250
+ traceClientMetadata ( ctx , clientMetadata ) ;
251
+ TraceContext . setOWI ( ctx , {
252
+ userId : clientMetadata . userId ,
253
+ sessionId : clientMetadata . sessionId ,
254
+ } ) ;
255
+ connection . onClose ( ( ) => span . finish ( ) ) ;
256
+
247
257
const factory = new GitpodJsonRpcProxyFactory < T > (
248
258
this . createAccessGuard ( request ) ,
249
259
this . createRateLimiter ( clientMetadata . id , request ) ,
250
260
clientMetadata ,
261
+ ctx ,
251
262
) ;
252
263
const proxy = factory . createProxy ( ) ;
253
264
factory . target = this . targetFactory ( proxy , request ) ;
@@ -272,6 +283,7 @@ class GitpodJsonRpcProxyFactory<T extends object> extends JsonRpcProxyFactory<T>
272
283
protected readonly accessGuard : FunctionAccessGuard ,
273
284
protected readonly rateLimiter : RateLimiter ,
274
285
protected readonly clientMetadata : ClientMetadata ,
286
+ protected readonly connectionCtx : TraceContext ,
275
287
) {
276
288
super ( ) ;
277
289
}
@@ -283,7 +295,7 @@ class GitpodJsonRpcProxyFactory<T extends object> extends JsonRpcProxyFactory<T>
283
295
increaseApiCallUserCounter ( method , "anonymous" ) ;
284
296
}
285
297
286
- const span = opentracing . globalTracer ( ) . startSpan ( method ) ;
298
+ const span = TraceContext . startSpan ( method , undefined , this . connectionCtx . span ) ;
287
299
const ctx = { span } ;
288
300
const userId = this . clientMetadata . userId ;
289
301
try {
0 commit comments