File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed
plugins/node/opentelemetry-instrumentation-graphql Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ const DEFAULT_CONFIG: GraphQLInstrumentationConfig = {
59
59
mergeItems : false ,
60
60
depth : - 1 ,
61
61
allowValues : false ,
62
+ ignoreResolveSpans : false ,
62
63
} ;
63
64
64
65
const supportedVersions = [ '>=14' ] ;
@@ -474,7 +475,11 @@ export class GraphQLInstrumentation extends InstrumentationBase {
474
475
if ( ! contextValue ) {
475
476
contextValue = { } ;
476
477
}
477
- if ( contextValue [ OTEL_GRAPHQL_DATA_SYMBOL ] ) {
478
+
479
+ if (
480
+ contextValue [ OTEL_GRAPHQL_DATA_SYMBOL ] ||
481
+ this . _getConfig ( ) . ignoreResolveSpans
482
+ ) {
478
483
return {
479
484
schema,
480
485
document,
Original file line number Diff line number Diff line change @@ -39,6 +39,13 @@ export interface GraphQLInstrumentationConfig extends InstrumentationConfig {
39
39
*/
40
40
depth ?: number ;
41
41
42
+ /**
43
+ * Do not create spans for resolvers.
44
+ *
45
+ * @default false
46
+ */
47
+ ignoreResolveSpans ?: boolean ;
48
+
42
49
/**
43
50
* Don't create spans for the execution of the default resolver on object properties.
44
51
*
Original file line number Diff line number Diff line change @@ -689,6 +689,37 @@ describe('graphql', () => {
689
689
} ) ;
690
690
} ) ;
691
691
692
+ describe ( 'when ignoreResolveSpans is true' , ( ) => {
693
+ beforeEach ( ( ) => {
694
+ create ( {
695
+ ignoreResolveSpans : true ,
696
+ } ) ;
697
+ } ) ;
698
+
699
+ afterEach ( ( ) => {
700
+ exporter . reset ( ) ;
701
+ graphQLInstrumentation . disable ( ) ;
702
+ } ) ;
703
+
704
+ it ( 'should not create a span for a defined resolver' , async ( ) => {
705
+ const schema = buildSchema ( `
706
+ type Query {
707
+ hello: String
708
+ }
709
+ ` ) ;
710
+
711
+ const rootValue = {
712
+ hello : ( ) => 'world' ,
713
+ } ;
714
+
715
+ await graphql ( { schema, source : '{ hello }' , rootValue } ) ;
716
+ const resolveSpans = exporter
717
+ . getFinishedSpans ( )
718
+ . filter ( span => span . name === `${ SpanNames . RESOLVE } hello` ) ;
719
+ assert . deepStrictEqual ( resolveSpans . length , 0 ) ;
720
+ } ) ;
721
+ } ) ;
722
+
692
723
describe ( 'when allowValues is set to true' , ( ) => {
693
724
describe ( 'AND source is query with param' , ( ) => {
694
725
let spans : ReadableSpan [ ] ;
You can’t perform that action at this time.
0 commit comments