graphql-hive / graphql-hive/envelop

@envelop/opentelemetry resolver spans aren’t active, nested spans attach to operation span

Open
#2,851 0 comments 1 reaction 1 assignee Claimed by @santino View on GitHub
Dominant language
No language data
Stars
827
Forks
132
PR merge metrics
No merged PRs in 30d

Description

### Issue workflow progress

*Progress of the issue based on the**
*[*Contributor Workflow*]()

- [X] 1\. The issue provides a
[minimal reproduction]() available on
[Stackblitz]().
* *Please install the latest* `@envelop/*` packages that you are using.
* *Please make sure the reproduction is as small as possible.*
* StackBlitz: [https://stackblitz.com/github/kdawgwilk/envelop/tree/repro/opentelemetry-resolver-context/repro/opentelemetry-resolver-context?file=index.js]()
- [X] 2\. A failing test has been provided
* `packages/plugins/opentelemetry/test/use-open-telemetry.spec.ts`
- [X] 3\. A local solution has been provided
* PR: [https://github.com/graphql-hive/envelop/pull/2852]()
- [X] 4\. A pull request is pending review
* PR: [https://github.com/graphql-hive/envelop/pull/2852]()

---

**Describe the bug**

When using `useOpenTelemetry({ resolvers: true })`, resolver spans are created but resolver execution is not run inside an active span context. As a result, nested spans created inside resolvers attach to the GraphQL operation span instead of the resolver span.

**To Reproduce** Steps to reproduce the behavior:

1. Enable `useOpenTelemetry` with `resolvers: true`.
2. Execute a GraphQL query whose resolvers call any instrumented library.
3. Inspect traces (or run the StackBlitz repro).

**Expected behavior**

Nested spans created during resolver execution should be children of the resolver span, not the operation span.

**Environment:**

* OS: macOS (darwin 24.6.0)
* NodeJS: v24.11.1
* `@envelop/*` versions:
* `@envelop/core`: `5.5.0`
* `@envelop/opentelemetry`: `9.1.0`
* `@envelop/on-resolve`: `7.1.0`

**Additional context**

The resolver span is created in the `useOnResolve` handler, but the resolver execution itself is not wrapped in an active span context (e.g. `context.with(trace.setSpan(...))` / `startActiveSpan`), so downstream instrumentations don’t see the resolver span as active.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.