@@ -40,14 +40,7 @@ const INTEGRATION_NAME = 'Graphql';
40
40
export const instrumentGraphql = generateInstrumentOnce < GraphqlOptions > (
41
41
INTEGRATION_NAME ,
42
42
( _options : GraphqlOptions = { } ) => {
43
- // We set default values here, which are used in the case that this is preloaded
44
- // In that case, no options are passed in, and we want to use the defaults
45
- const options = {
46
- ignoreResolveSpans : true ,
47
- ignoreTrivialResolveSpans : true ,
48
- useOperationNameForRootSpan : true ,
49
- ..._options ,
50
- } ;
43
+ const options = getOptionsWithDefaults ( _options ) ;
51
44
52
45
return new GraphQLInstrumentation ( {
53
46
...options ,
@@ -87,21 +80,14 @@ export const instrumentGraphql = generateInstrumentOnce<GraphqlOptions>(
87
80
} ,
88
81
) ;
89
82
90
- const _graphqlIntegration = ( ( _options : GraphqlOptions = { } ) => {
83
+ const _graphqlIntegration = ( ( options : GraphqlOptions = { } ) => {
91
84
return {
92
85
name : INTEGRATION_NAME ,
93
86
setupOnce ( ) {
94
87
// We set defaults here, too, because otherwise we'd update the instrumentation config
95
88
// to the config without defaults, as `generateInstrumentOnce` automatically calls `setConfig(options)`
96
89
// when being called the second time
97
- const options = {
98
- ignoreResolveSpans : true ,
99
- ignoreTrivialResolveSpans : true ,
100
- useOperationNameForRootSpan : true ,
101
- ..._options ,
102
- } ;
103
-
104
- instrumentGraphql ( options ) ;
90
+ instrumentGraphql ( getOptionsWithDefaults ( options ) ) ;
105
91
} ,
106
92
} ;
107
93
} ) satisfies IntegrationFn ;
@@ -112,3 +98,12 @@ const _graphqlIntegration = ((_options: GraphqlOptions = {}) => {
112
98
* Capture tracing data for GraphQL.
113
99
*/
114
100
export const graphqlIntegration = defineIntegration ( _graphqlIntegration ) ;
101
+
102
+ function getOptionsWithDefaults ( options ?: GraphqlOptions ) : GraphqlOptions {
103
+ return {
104
+ ignoreResolveSpans : true ,
105
+ ignoreTrivialResolveSpans : true ,
106
+ useOperationNameForRootSpan : true ,
107
+ ...options ,
108
+ } ;
109
+ }
0 commit comments