-
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5dcec12
feat(server-utils): Emit low cardinality graphql span names
andreiborza ca3bd08
Name graphql phase spans with the fallback and mark them with graphql…
andreiborza d95710e
Assert the recorded operation value, not just its presence
andreiborza 09b2018
Share the graphql constants between both paths instead of mirroring them
andreiborza b748f87
Trim the constant comments
andreiborza 47731ab
Drop the explanatory comments on the span name branches
andreiborza 232c4d1
Cover the processing type in the integration suites instead of a unit…
andreiborza 426abf5
Name graphql phase spans after the processing type
andreiborza 393a67b
Rely on the default trace lifecycle in the streamed graphql suite
andreiborza 0398116
Say that the root span operation attribute follows useOperationNameFo…
andreiborza 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
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
...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,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, | ||
| }); |
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(); |
95 changes: 95 additions & 0 deletions
95
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,95 @@ | ||
| 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']); | ||
| expect(resolveSpans.map(span => span.name)).toEqual(['GraphQL resolve', 'GraphQL resolve']); | ||
|
|
||
| // Parse and validate spans have no operation type, so they are named after the phase. | ||
| const phaseSpans = spans.filter(span => !executeSpans.includes(span) && !resolveSpans.includes(span)); | ||
| expect(phaseSpans.length).toBeGreaterThan(0); | ||
| expect(phaseSpans.every(span => ['GraphQL parse', 'GraphQL validate'].includes(span.name))).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
18 changes: 11 additions & 7 deletions
18
packages/server-utils/src/integrations/graphql/constants.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
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.