@@ -218,6 +218,11 @@ export type OpenTelemetryContextExtension = {
218
218
openTelemetry : {
219
219
tracer : Tracer ;
220
220
activeContext : ( ) => Context ;
221
+ httpContext : ( request ?: Request ) => Context | undefined ;
222
+ operationContext : ( context ?: any ) => Context | undefined ;
223
+ executionRequestContext : (
224
+ ExecutionRequest : ExecutionRequest ,
225
+ ) => Context | undefined ;
221
226
} ;
222
227
} ;
223
228
@@ -231,12 +236,17 @@ type State = Partial<
231
236
232
237
export type OpenTelemetryPlugin =
233
238
GatewayPlugin < OpenTelemetryContextExtension > & {
234
- getOtelContext : ( payload : {
239
+ getActiveContext : ( payload : {
235
240
request ?: Request ;
236
241
context ?: any ;
237
242
executionRequest ?: ExecutionRequest ;
238
243
} ) => Context ;
239
244
getTracer ( ) : Tracer ;
245
+ getHttpContext : ( request : Request ) => Context | undefined ;
246
+ getOperationContext : ( context : any ) => Context | undefined ;
247
+ getExecutionRequestContext : (
248
+ ExecutionRequest : ExecutionRequest ,
249
+ ) => Context | undefined ;
240
250
} ;
241
251
242
252
export function useOpenTelemetry (
@@ -321,7 +331,16 @@ export function useOpenTelemetry(
321
331
OtelState
322
332
> ( ( getState ) => ( {
323
333
getTracer : ( ) => tracer ,
324
- getOtelContext : ( { state } ) => getContext ( state ) ,
334
+ getActiveContext : ( { state } ) => getContext ( state ) ,
335
+ getHttpContext : ( request ) => {
336
+ return getState ( { request } ) . forRequest . otel ?. root ;
337
+ } ,
338
+ getOperationContext : ( context ) => {
339
+ return getState ( { context } ) . forOperation . otel ?. root ;
340
+ } ,
341
+ getExecutionRequestContext : ( executionRequest ) => {
342
+ return getState ( { executionRequest } ) . forSubgraphExecution . otel ?. root ;
343
+ } ,
325
344
instrumentation : {
326
345
request ( { state : { forRequest } , request } , wrapped ) {
327
346
if ( ! shouldTrace ( traces . spans ?. http , { request } ) ) {
@@ -706,7 +725,20 @@ export function useOpenTelemetry(
706
725
extendContext ( {
707
726
openTelemetry : {
708
727
tracer,
709
- activeContext : ( ) => getContext ( state ) ,
728
+ httpContext : ( request ) => {
729
+ const { forRequest } = request ? getState ( { request } ) : state ;
730
+ return forRequest . otel ?. root ;
731
+ } ,
732
+ operationContext : ( context ) => {
733
+ const { forOperation } = context ? getState ( { context } ) : state ;
734
+ return forOperation . otel ?. root ;
735
+ } ,
736
+ executionRequestContext : ( executionRequest ) => {
737
+ return getState ( { executionRequest } ) . forSubgraphExecution . otel
738
+ ?. root ;
739
+ } ,
740
+ activeContext : ( contextMatcher ?: Parameters < typeof getState > [ 0 ] ) =>
741
+ getContext ( contextMatcher ? getState ( contextMatcher ) : state ) ,
710
742
} ,
711
743
} ) ;
712
744
} ,
0 commit comments