Skip to content

Commit 991cb71

Browse files
committed
refactor
1 parent 14b085f commit 991cb71

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

packages/node/src/integrations/tracing/graphql.ts

+12-17
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,7 @@ const INTEGRATION_NAME = 'Graphql';
4040
export const instrumentGraphql = generateInstrumentOnce<GraphqlOptions>(
4141
INTEGRATION_NAME,
4242
(_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);
5144

5245
return new GraphQLInstrumentation({
5346
...options,
@@ -87,21 +80,14 @@ export const instrumentGraphql = generateInstrumentOnce<GraphqlOptions>(
8780
},
8881
);
8982

90-
const _graphqlIntegration = ((_options: GraphqlOptions = {}) => {
83+
const _graphqlIntegration = ((options: GraphqlOptions = {}) => {
9184
return {
9285
name: INTEGRATION_NAME,
9386
setupOnce() {
9487
// We set defaults here, too, because otherwise we'd update the instrumentation config
9588
// to the config without defaults, as `generateInstrumentOnce` automatically calls `setConfig(options)`
9689
// 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));
10591
},
10692
};
10793
}) satisfies IntegrationFn;
@@ -112,3 +98,12 @@ const _graphqlIntegration = ((_options: GraphqlOptions = {}) => {
11298
* Capture tracing data for GraphQL.
11399
*/
114100
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

Comments
 (0)