Skip to content

Commit 9bbdfe7

Browse files
authored
feat(node): Do not create GraphQL resolver spans by default (#12097)
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
1 parent 56570b3 commit 9bbdfe7

File tree

2 files changed

+23
-15
lines changed
  • dev-packages/node-integration-tests/suites/tracing/apollo-graphql
  • packages/node/src/integrations/tracing

2 files changed

+23
-15
lines changed

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@ describe('GraphQL/Apollo Tests', () => {
1616
status: 'ok',
1717
origin: 'auto.graphql.otel.graphql',
1818
}),
19-
expect.objectContaining({
20-
data: {
21-
'graphql.field.name': 'hello',
22-
'graphql.field.path': 'hello',
23-
'graphql.field.type': 'String',
24-
'graphql.source': 'hello',
25-
'otel.kind': 'INTERNAL',
26-
'sentry.origin': 'manual',
27-
},
28-
description: 'graphql.resolve hello',
29-
status: 'ok',
30-
origin: 'manual',
31-
}),
3219
]),
3320
};
3421

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,34 @@ import type { IntegrationFn } from '@sentry/types';
55

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

8-
const _graphqlIntegration = (() => {
8+
interface GraphqlOptions {
9+
/** Do not create spans for resolvers. */
10+
ignoreResolveSpans?: boolean;
11+
12+
/**
13+
* Don't create spans for the execution of the default resolver on object properties.
14+
*
15+
* When a resolver function is not defined on the schema for a field, graphql will
16+
* use the default resolver which just looks for a property with that name on the object.
17+
* If the property is not a function, it's not very interesting to trace.
18+
* This option can reduce noise and number of spans created.
19+
*/
20+
ignoreTrivalResolveSpans?: boolean;
21+
}
22+
23+
const _graphqlIntegration = ((_options: GraphqlOptions = {}) => {
24+
const options = {
25+
ignoreResolveSpans: true,
26+
ignoreTrivialResolveSpans: true,
27+
..._options,
28+
};
29+
930
return {
1031
name: 'Graphql',
1132
setupOnce() {
1233
addOpenTelemetryInstrumentation(
1334
new GraphQLInstrumentation({
14-
ignoreTrivialResolveSpans: true,
35+
...options,
1536
responseHook(span) {
1637
addOriginToSpan(span, 'auto.graphql.otel.graphql');
1738
},

0 commit comments

Comments
 (0)