-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ref(node): Streamline graphql instrumentation #21556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
logaretm
merged 4 commits into
develop
from
awad/js-2380-streamline-opentelemetryinstrumentation-graphql
Jun 15, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4cc4cb7
ref(node): Streamline graphql instrumentation
logaretm 7dcd8c8
test(node-integration-tests): Cover graphql resolve spans and source …
logaretm 6327f24
chore: type fixes
logaretm 2b354fa
ref(node): Inline graphql responseHook logic into instrumentation
logaretm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
10 changes: 10 additions & 0 deletions
10
dev-packages/node-integration-tests/suites/tracing/apollo-graphql/resolvers/instrument.mjs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| tracesSampleRate: 1.0, | ||
| integrations: [Sentry.graphqlIntegration({ ignoreResolveSpans: false })], | ||
| transport: loggingTransport, | ||
| }); |
26 changes: 26 additions & 0 deletions
26
...ackages/node-integration-tests/suites/tracing/apollo-graphql/resolvers/scenario-query.mjs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
|
|
||
| async function run() { | ||
| const { createApolloServer } = await import('../../apollo-server.mjs'); | ||
| const server = createApolloServer(); | ||
|
|
||
| await Sentry.startSpan( | ||
| { | ||
| name: 'Test Transaction', | ||
| op: 'transaction', | ||
| }, | ||
| async span => { | ||
| // Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation | ||
| await server.executeOperation({ | ||
| query: '{hello}', | ||
| }); | ||
|
|
||
| setTimeout(() => { | ||
| span.end(); | ||
| server.stop(); | ||
| }, 500); | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| run(); |
52 changes: 52 additions & 0 deletions
52
dev-packages/node-integration-tests/suites/tracing/apollo-graphql/resolvers/test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { afterAll, describe, expect } from 'vitest'; | ||
| import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../../utils/runner'; | ||
|
|
||
| // Server start transaction (Apollo Server v5 no longer runs introspection query on start) | ||
| const EXPECTED_START_SERVER_TRANSACTION = { | ||
| transaction: 'Test Server Start', | ||
| }; | ||
|
|
||
| describe('GraphQL/Apollo Tests > resolve spans', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| // With `ignoreResolveSpans: false`, the instrumentation emits a span for the execute step as well as | ||
| // for `parse`, `validate` and each (non-trivial) field resolver. | ||
| const EXPECTED_TRANSACTION = { | ||
| // `useOperationNameForRootSpan` defaults to true, so the root span name gets the operation appended. | ||
| transaction: 'Test Transaction (query)', | ||
| spans: expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| description: 'query', | ||
| origin: 'auto.graphql.otel.graphql', | ||
| data: expect.objectContaining({ | ||
| 'graphql.operation.type': 'query', | ||
| 'graphql.source': '{hello}', | ||
| 'sentry.origin': 'auto.graphql.otel.graphql', | ||
| }), | ||
| }), | ||
| expect.objectContaining({ description: 'graphql.parse' }), | ||
| expect.objectContaining({ description: 'graphql.validate' }), | ||
| expect.objectContaining({ | ||
| description: 'graphql.resolve hello', | ||
| data: expect.objectContaining({ | ||
| 'graphql.field.name': 'hello', | ||
| 'graphql.field.path': 'hello', | ||
| 'graphql.field.type': 'String', | ||
| 'graphql.parent.name': 'Query', | ||
| }), | ||
| }), | ||
| ]), | ||
| }; | ||
|
|
||
| createEsmAndCjsTests(__dirname, 'scenario-query.mjs', 'instrument.mjs', (createTestRunner, test) => { | ||
| test('emits parse, validate and resolve spans when ignoreResolveSpans is false', async () => { | ||
| await createTestRunner() | ||
| .expect({ transaction: EXPECTED_START_SERVER_TRANSACTION }) | ||
| .expect({ transaction: EXPECTED_TRANSACTION }) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
| }); | ||
| }); |
31 changes: 31 additions & 0 deletions
31
dev-packages/node-integration-tests/suites/tracing/apollo-graphql/scenario-redaction.mjs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import gql from 'graphql-tag'; | ||
|
|
||
| async function run() { | ||
| const { createApolloServer } = await import('./apollo-server.mjs'); | ||
| const server = createApolloServer(); | ||
|
|
||
| await Sentry.startSpan( | ||
| { | ||
| name: 'Test Transaction', | ||
| op: 'transaction', | ||
| }, | ||
| async span => { | ||
| // Inline string literal (not a variable) so we can assert it gets redacted out of `graphql.source`. | ||
| await server.executeOperation({ | ||
| query: gql` | ||
| mutation { | ||
| login(email: "secret@example.com") | ||
| } | ||
| `, | ||
| }); | ||
|
|
||
| setTimeout(() => { | ||
| span.end(); | ||
| server.stop(); | ||
| }, 500); | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| run(); |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l/m: This is neither in OTel's nor Sentry's semantic conventions. Maybe we should define it or update it to https://getsentry.github.io/sentry-conventions/attributes/graphql/#graphql-document?
Feel free to disregard for this PR, just maybe good to note as a follow-up?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's an old attribute that predated OTel so they have it for backward compat stuff
https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/packages/instrumentation-graphql/src/enums/AttributeNames.ts#L6
I think we can track it as part of the attributes to fix before v11 release, since we have a lot of those semantic attrs missing or need renaming all over. What do you think?