open-telemetry / opentelemetry-js-contrib

OpenTelemetry instrumentation for JavaScript modules
https://opentelemetry.io
Apache License 2.0
703 stars 524 forks source link

Add path to span name of `graphq.resolve` spans created by graphql instrumentation #1791

Closed satazor closed 1 year ago

satazor commented 1 year ago

Is your feature request related to a problem? Please describe

Currently, the graphql instrumentation packages adds spans for all resolvers where span name equals to graphql.resolve. Here's how it looks in datadog for example:

Screenshot 2023-11-10 at 13 29 46

However, to have improved DX, the span name could contain the actual path.

Describe the solution you'd like to see

Something like graphl.resolve - <path> as the span name would make this much better:

Describe alternatives you've considered

The most obvious workound is to add a processor that changes the span name:

if (span.name === 'graphql.resolve' && span.attributes['graphql.field.path']) {
  span.updateName(`${span.name} ${span.attributes['graphql.field.path']}`);
}
diogotorres97 commented 1 year ago

I did a PR to update the span name to have more information. If you can check, if this #1796 resolves the issue 😄