-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(server-utils): Emit low cardinality graphql span names #23542
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
Draft
andreiborza
wants to merge
3
commits into
develop
Choose a base branch
from
ab/graphql-low-cardinality-span-names
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
11 changes: 11 additions & 0 deletions
11
...ckages/node-integration-tests/suites/tracing/apollo-graphql/span-streaming/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,11 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| traceLifecycle: 'stream', | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| tracesSampleRate: 1.0, | ||
| integrations: [Sentry.graphqlIntegration({ ignoreResolveSpans: false })], | ||
| transport: loggingTransport, | ||
| }); |
22 changes: 22 additions & 0 deletions
22
...packages/node-integration-tests/suites/tracing/apollo-graphql/span-streaming/scenario.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,22 @@ | ||
| 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: 'query GetHello {hello}' }); | ||
| await server.executeOperation({ | ||
| query: 'mutation TestMutation($email: String) { login(email: $email) }', | ||
| variables: { email: 'test@email.com' }, | ||
| }); | ||
|
|
||
| setTimeout(() => { | ||
| span.end(); | ||
| server.stop(); | ||
| }, 500); | ||
| }); | ||
| } | ||
|
|
||
| run(); |
93 changes: 93 additions & 0 deletions
93
dev-packages/node-integration-tests/suites/tracing/apollo-graphql/span-streaming/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,93 @@ | ||
| import type { SerializedStreamedSpanContainer } from '@sentry/core'; | ||
| import { afterAll, describe, expect } from 'vitest'; | ||
| import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../../utils/runner'; | ||
|
|
||
| type StreamedSpan = SerializedStreamedSpanContainer['items'][number]; | ||
|
|
||
| // Scoped to the `Test Transaction` segment: creating the server parses the schema's typeDefs, which | ||
| // emits a parse span under `Test Server Start`. | ||
| function graphqlSpans(container: SerializedStreamedSpanContainer): StreamedSpan[] { | ||
| return container.items.filter( | ||
| item => | ||
| item.attributes['sentry.op']?.value === 'graphql' && | ||
| item.attributes['sentry.segment.name']?.value === 'Test Transaction', | ||
| ); | ||
| } | ||
|
|
||
| describe('GraphQL/Apollo Tests > span streaming', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createTestRunner, test) => { | ||
| test('names graphql spans after the operation type, never the operation name or field path', async () => { | ||
| await createTestRunner() | ||
| .expect({ | ||
| span: container => { | ||
| const spans = graphqlSpans(container); | ||
|
|
||
| const executeSpans = spans.filter(span => span.attributes['graphql.operation.type']); | ||
| expect(executeSpans.map(span => span.name)).toEqual(['GraphQL query', 'GraphQL mutation']); | ||
|
|
||
| // Resolver spans keep the field path as an attribute, but it is unbounded, so it must not | ||
| // reach the span name. | ||
| const resolveSpans = spans.filter(span => span.attributes['graphql.field.path']); | ||
| expect(resolveSpans.map(span => span.attributes['graphql.field.path']?.value)).toEqual(['hello', 'login']); | ||
|
|
||
| // Parse, validate and resolve spans have no operation type to name them after. | ||
| const fallbackSpans = spans.filter(span => !executeSpans.includes(span)); | ||
| expect(fallbackSpans.every(span => span.name === 'GraphQL Operation')).toBe(true); | ||
|
|
||
| expect(spans.some(span => span.name.includes('GetHello') || span.name.includes('TestMutation'))).toBe( | ||
| false, | ||
| ); | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
|
|
||
| test('marks every graphql span with its processing type', async () => { | ||
| await createTestRunner() | ||
| .expect({ | ||
| span: container => { | ||
| const processingTypes = graphqlSpans(container).map( | ||
| span => span.attributes['graphql.processing.type']?.value, | ||
| ); | ||
|
|
||
| expect(processingTypes.sort()).toEqual([ | ||
| 'execute', | ||
| 'execute', | ||
| 'parse', | ||
| 'parse', | ||
| 'resolve', | ||
| 'resolve', | ||
| 'validate', | ||
| 'validate', | ||
| ]); | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
|
|
||
| test('records the operations on the segment span without renaming it', async () => { | ||
| await createTestRunner() | ||
| .expect({ | ||
| span: container => { | ||
| // `Test Server Start` is a segment too, so pick the one the operations ran under. | ||
| const segmentSpan = container.items.find(item => item.is_segment && item.name === 'Test Transaction'); | ||
|
|
||
| expect(segmentSpan).toBeDefined(); | ||
| // Both operations are recorded here rather than in the name. | ||
| expect(segmentSpan?.attributes['sentry.graphql.operation']?.value).toEqual([ | ||
| 'query GetHello', | ||
| 'mutation TestMutation', | ||
| ]); | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
| }); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.