Skip to content

Commit

Permalink
feat(node): Do not create GraphQL resolver spans by default (#12097)
Browse files Browse the repository at this point in the history
Users can pass `ignoreResolveSpans` and `ignoreTrivalResolveSpans` to
the integration now, which is passed to the instrumentation. They
default to `true`. This should reduce noise and perf overhead.

Closes #12092
  • Loading branch information
mydea committed May 17, 2024
1 parent 56570b3 commit 9bbdfe7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@ describe('GraphQL/Apollo Tests', () => {
status: 'ok',
origin: 'auto.graphql.otel.graphql',
}),
expect.objectContaining({
data: {
'graphql.field.name': 'hello',
'graphql.field.path': 'hello',
'graphql.field.type': 'String',
'graphql.source': 'hello',
'otel.kind': 'INTERNAL',
'sentry.origin': 'manual',
},
description: 'graphql.resolve hello',
status: 'ok',
origin: 'manual',
}),
]),
};

Expand Down
25 changes: 23 additions & 2 deletions packages/node/src/integrations/tracing/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,34 @@ import type { IntegrationFn } from '@sentry/types';

import { addOriginToSpan } from '../../utils/addOriginToSpan';

const _graphqlIntegration = (() => {
interface GraphqlOptions {
/** Do not create spans for resolvers. */
ignoreResolveSpans?: boolean;

/**
* Don't create spans for the execution of the default resolver on object properties.
*
* When a resolver function is not defined on the schema for a field, graphql will
* use the default resolver which just looks for a property with that name on the object.
* If the property is not a function, it's not very interesting to trace.
* This option can reduce noise and number of spans created.
*/
ignoreTrivalResolveSpans?: boolean;
}

const _graphqlIntegration = ((_options: GraphqlOptions = {}) => {
const options = {
ignoreResolveSpans: true,
ignoreTrivialResolveSpans: true,
..._options,
};

return {
name: 'Graphql',
setupOnce() {
addOpenTelemetryInstrumentation(
new GraphQLInstrumentation({
ignoreTrivialResolveSpans: true,
...options,
responseHook(span) {
addOriginToSpan(span, 'auto.graphql.otel.graphql');
},
Expand Down

0 comments on commit 9bbdfe7

Please sign in to comment.