Skip to content

GraphQL field instrumentation does not work for union return types #1506

Open
@mengledowl

Description

@mengledowl

What version of OpenTelemetry are you using?

@opentelemetry/api v 1.4.1

What version of Node are you using?

18.16.0

What did you do?

Create a GraphQL API (I'm using Apollo but I don't believe it matters) with a query, mutation, or a field on an individual type whose response type is a union, eg:

type Foo {
  field: String
}

type Bar {
  anotherField: String
}

union MyUnion = Foo | Bar

type Query {
  fooOrBar: MyUnion!
}

Then execute a GraphQL query, eg:

{
  fooOrBar {
    ...on Foo {
      myField
    }
    ...on Bar {
      anotherField
    }
  }
}

What did you expect to see?

Resolve spans for each resolver that ran (eg. if a Foo is returned, a span for fooOrBar and myField)

What did you see instead?

A single resolve span for the query field only (fooOrBar). This is the case no matter how deeply the query nests.

Additional context

I'm using the node SDK to instrument automatically. I also made sure to set ignoreTrivialResponseSpans to false and depth to -1 (I know they are defaulted, but I wanted to be sure it wasn't related) like so:

const sdk = new opentelemetry.NodeSDK({
  // other settings...
  instrumentations: [getNodeAutoInstrumentations({
    '@opentelemetry/instrumentation-graphql': {
      ignoreTrivialResolveSpans: false,
      depth: -1,
    },
  })],
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpkg:instrumentation-graphqlpriority:p2Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrectup-for-grabsGood for taking. Extra help will be provided by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions