fix(graphql): rewrap late-added resolvers#3447
Open
Farhan-Abbas wants to merge 2 commits intoopen-telemetry:mainfrom
Open
fix(graphql): rewrap late-added resolvers#3447Farhan-Abbas wants to merge 2 commits intoopen-telemetry:mainfrom
Farhan-Abbas wants to merge 2 commits intoopen-telemetry:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GraphQL Instrumentation: Fix Missing Spans for Late-Added Resolvers
Which problem is this PR solving?
Fixes #3362. Custom resolvers on GraphQL Query and Mutation types are not being instrumented when using Apollo Server 5 with NestJS. This causes missing
graphql.resolvespans in distributed traces, making it impossible to see the performance of custom resolver logic.Example: When executing a query like:
Expected spans for
graphql.resolve departmentandgraphql.resolve department.employeeswere completely missing—only scalar fields (id, name) generated spans.Root cause: Apollo Server wraps resolvers after schema creation but before query execution. The old implementation used a permanent type-level "already patched" flag that skipped re-checking types, so late-added resolvers were never wrapped.
Short description of the changes
Per-query visited set instead of permanent type marking
OTEL_PATCHED_SYMBOLcheck with a temporaryvisitedInThisTraversalSetUser → friends → User)Per-resolver wrapping instead of per-type wrapping
Changes made
src/instrumentation.ts: Create and pass sharedvisitedSet towrapFields()callssrc/utils.ts: UpdatewrapFields()to use per-traversal Set; updatewrapFieldResolver()to check resolver functions directlysrc/utils.ts(wrapFieldResolverguard): checkfieldResolver[OTEL_PATCHED_SYMBOL](incoming resolver) instead ofwrappedFieldResolver[OTEL_PATCHED_SYMBOL](new wrapper being created)src/utils.ts(wrapFieldResolverguard): keeptypeof fieldResolver !== 'function'as the first condition so non-function/undefined resolvers return early before any symbol lookupVerification
graphql.resolve departmentandgraphql.resolve department.employees) are now visible in traces