Skip to content

pkg:instrumentation-graphql ignoreTrivialResolveSpans doesn't work #1686

Open
@charly22

Description

@charly22

What version of OpenTelemetry are you using?

     "@opentelemetry/api": "^1.4.1"

What version of Node are you using?

v18.17.1

What did you do?

I enabled the auto instrumentation with ignoreTrivialResolveSpans option enabled

new GraphQLInstrumentation({
  ignoreTrivialResolveSpans: true
})

Expected:

What did you expect to see?

The resolves that don't have any custom implementation don't generate any span

What did you see instead?

All resolves generate a corresponding span

Additional context

Digging into Apollo's implementation, I found that when it loads its internal plugins, it always wraps the field.resolve with a function that executes the default or the user-defined resolver, as you can see here:

https://github.com/apollographql/apollo-server/blob/f6e3ae021417c3b54200f8d3fcf4366dc3518998/packages/server/src/utils/schemaInstrumentation.ts#L57-L101

For that reason, this condition:

if (field.resolve) {
field.resolve = wrapFieldResolver(tracer, getConfig, field.resolve);
}

evaluates true for all resolvers (including the default ones) and always ends up instrumenting all field resolvers

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpkg:instrumentation-graphqlpriority:p3Bugs which cause problems in user apps not related to correctness (performance, memory use, etc)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions