Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Sep 24, 2024
1 parent 14b085f commit 991cb71
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions packages/node/src/integrations/tracing/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,7 @@ const INTEGRATION_NAME = 'Graphql';
export const instrumentGraphql = generateInstrumentOnce<GraphqlOptions>(
INTEGRATION_NAME,
(_options: GraphqlOptions = {}) => {
// We set default values here, which are used in the case that this is preloaded
// In that case, no options are passed in, and we want to use the defaults
const options = {
ignoreResolveSpans: true,
ignoreTrivialResolveSpans: true,
useOperationNameForRootSpan: true,
..._options,
};
const options = getOptionsWithDefaults(_options);

return new GraphQLInstrumentation({
...options,
Expand Down Expand Up @@ -87,21 +80,14 @@ export const instrumentGraphql = generateInstrumentOnce<GraphqlOptions>(
},
);

const _graphqlIntegration = ((_options: GraphqlOptions = {}) => {
const _graphqlIntegration = ((options: GraphqlOptions = {}) => {
return {
name: INTEGRATION_NAME,
setupOnce() {
// We set defaults here, too, because otherwise we'd update the instrumentation config
// to the config without defaults, as `generateInstrumentOnce` automatically calls `setConfig(options)`
// when being called the second time
const options = {
ignoreResolveSpans: true,
ignoreTrivialResolveSpans: true,
useOperationNameForRootSpan: true,
..._options,
};

instrumentGraphql(options);
instrumentGraphql(getOptionsWithDefaults(options));
},
};
}) satisfies IntegrationFn;
Expand All @@ -112,3 +98,12 @@ const _graphqlIntegration = ((_options: GraphqlOptions = {}) => {
* Capture tracing data for GraphQL.
*/
export const graphqlIntegration = defineIntegration(_graphqlIntegration);

function getOptionsWithDefaults(options?: GraphqlOptions): GraphqlOptions {
return {
ignoreResolveSpans: true,
ignoreTrivialResolveSpans: true,
useOperationNameForRootSpan: true,
...options,
};
}

0 comments on commit 991cb71

Please sign in to comment.