Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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