Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(instrumentation-graphql): add option to ignore resolver spans #1858

Merged
merged 9 commits into from
Jan 15, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const DEFAULT_CONFIG: GraphQLInstrumentationConfig = {
mergeItems: false,
depth: -1,
allowValues: false,
ignoreResolveSpans: false,
};

const supportedVersions = ['>=14'];
Expand Down Expand Up @@ -474,7 +475,11 @@ export class GraphQLInstrumentation extends InstrumentationBase {
if (!contextValue) {
contextValue = {};
}
if (contextValue[OTEL_GRAPHQL_DATA_SYMBOL]) {

if (
contextValue[OTEL_GRAPHQL_DATA_SYMBOL] ||
this._getConfig().ignoreResolveSpans
) {
return {
schema,
document,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export interface GraphQLInstrumentationConfig extends InstrumentationConfig {
*/
depth?: number;

/**
* Do not create spans for resolvers.
*
* @default false
*/
ignoreResolveSpans?: boolean;

/**
* Don't create spans for the execution of the default resolver on object properties.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,37 @@ describe('graphql', () => {
});
});

describe('when ignoreResolveSpans is true', () => {
beforeEach(() => {
create({
ignoreResolveSpans: true,
});
});

afterEach(() => {
exporter.reset();
graphQLInstrumentation.disable();
});

it('should not create a span for a defined resolver', async () => {
const schema = buildSchema(`
type Query {
hello: String
}
`);

const rootValue = {
hello: () => 'world',
};

await graphql({ schema, source: '{ hello }', rootValue });
const resolveSpans = exporter
.getFinishedSpans()
.filter(span => span.name === `${SpanNames.RESOLVE} hello`);
assert.deepStrictEqual(resolveSpans.length, 0);
});
});

describe('when allowValues is set to true', () => {
describe('AND source is query with param', () => {
let spans: ReadableSpan[];
Expand Down
Loading