You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current implementation of the OpenTelemetry plugin can lead to confusing spans because the execution span starts within the OpenTelemetry plugin but these do not wrap each other and instead run as part of an iteration over the plugins.
I think the correct way to handle OpenTelemetry traces within envelop is to wrap the GraphQL functions with spans, for example the executeFn and subscribeFn, this will effectively instrument the GraphQL phases.
A plugin that wants to add instrumentation can pick up the parent context and add a span which will appear alongside any other instrumented plugin in terms of the traces.
An example of wrapping the execute function would be like so:
setExecuteFn(async()=>{constspan=tracer.startSpan(`${operationType}.${operationName}`,{})// todo: fill in attrbutes.returnawaitopentelemetry.context.with(api.context.active(),async()=>{letresult: ExecutionResult;try{result=awaitexecute(args);if(isAsyncIterable(result)){returnmapAsyncIterator(result[Symbol.asyncIterator](),(next: ExecutionResult)=>next,(error: GraphQLError)=>markError(executionSpan,{errors: [error]}),()=>span.end());}}finally{if(!isAsyncIterable(result)){span.end();}}returnresult;});});
This could be repeated for all phases of the GraphQL request and gives a more realistic view of how the process is executed.
Further to this we could create a Yoga Plugin that takes this further and wraps the request handler so that the parent context is set through all phases.
Summary
The current implementation of the OpenTelemetry plugin can lead to confusing spans because the execution span starts within the OpenTelemetry plugin but these do not wrap each other and instead run as part of an iteration over the plugins.
I think the correct way to handle OpenTelemetry traces within envelop is to wrap the GraphQL functions with spans, for example the executeFn and subscribeFn, this will effectively instrument the GraphQL phases.
A plugin that wants to add instrumentation can pick up the parent context and add a span which will appear alongside any other instrumented plugin in terms of the traces.
An example of wrapping the execute function would be like so:
This could be repeated for all phases of the GraphQL request and gives a more realistic view of how the process is executed.
Further to this we could create a Yoga Plugin that takes this further and wraps the request handler so that the parent context is set through all phases.
I think this would provide a much better instrumentation of GraphQL and how it is executed.
The text was updated successfully, but these errors were encountered: