-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(core): Apply ignoreSpans to streamed spans
#19934
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
Open
Lms24
wants to merge
5
commits into
lms/feat-span-first
Choose a base branch
from
lms/feat-core-ignorespans-streaming
base: lms/feat-span-first
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.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
861feee
feat(core): Apply `ignoreSpans` when span streaming is enabled
Lms24 11cfe2b
format
Lms24 c5da976
add client report generation, also for child spans, add tests for sam…
Lms24 1bc5f72
handle client reports for core/browser
Lms24 6bca137
rename trace state flag, fix integration tests, rework unit tests
Lms24 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
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
11 changes: 11 additions & 0 deletions
11
dev-packages/browser-integration-tests/suites/tracing/ignoreSpans-streamed/child/init.js
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/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [Sentry.spanStreamingIntegration()], | ||
| ignoreSpans: [/ignore/], | ||
| parentSpanIsAlwaysRootSpan: false, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. worth noting: For this test, I enabled |
||
| tracesSampleRate: 1, | ||
| }); | ||
23 changes: 23 additions & 0 deletions
23
dev-packages/browser-integration-tests/suites/tracing/ignoreSpans-streamed/child/subject.js
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,23 @@ | ||
| Sentry.startSpan({ name: 'parent-span' }, () => { | ||
| Sentry.startSpan({ name: 'keep-me' }, () => {}); | ||
|
|
||
| // This child matches ignoreSpans —> dropped | ||
| Sentry.startSpan({ name: 'ignore-child' }, () => { | ||
| // dropped | ||
| Sentry.startSpan({ name: 'ignore-grandchild-1' }, () => { | ||
| // kept | ||
| Sentry.startSpan({ name: 'great-grandchild-1' }, () => { | ||
| // dropped | ||
| Sentry.startSpan({ name: 'ignore-great-great-grandchild-1' }, () => { | ||
| // kept | ||
| Sentry.startSpan({ name: 'great-great-great-grandchild-1' }, () => {}); | ||
| }); | ||
| }); | ||
| }); | ||
| // Grandchild is reparented to 'parent-span' —> kept | ||
| Sentry.startSpan({ name: 'grandchild-2' }, () => {}); | ||
| }); | ||
|
|
||
| // kept | ||
| Sentry.startSpan({ name: 'another-keeper' }, () => {}); | ||
| }); |
59 changes: 59 additions & 0 deletions
59
dev-packages/browser-integration-tests/suites/tracing/ignoreSpans-streamed/child/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,59 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { | ||
| envelopeRequestParser, | ||
| hidePage, | ||
| shouldSkipTracingTest, | ||
| testingCdnBundle, | ||
| waitForClientReportRequest, | ||
| } from '../../../../utils/helpers'; | ||
| import { waitForStreamedSpans } from '../../../../utils/spanUtils'; | ||
| import type { ClientReport } from '@sentry/core'; | ||
|
|
||
| sentryTest('ignored child spans are dropped and their children are reparented', async ({ getLocalTestUrl, page }) => { | ||
| sentryTest.skip(shouldSkipTracingTest() || testingCdnBundle()); | ||
|
|
||
| const spansPromise = waitForStreamedSpans(page, spans => !!spans?.find(s => s.name === 'parent-span')); | ||
|
|
||
| const clientReportPromise = waitForClientReportRequest(page); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
| await page.goto(url); | ||
|
|
||
| const spans = await spansPromise; | ||
|
|
||
| await hidePage(page); | ||
|
|
||
| const clientReport = envelopeRequestParser<ClientReport>(await clientReportPromise); | ||
|
|
||
| const segmentSpanId = spans.find(s => s.name === 'parent-span')?.span_id; | ||
|
|
||
| expect(spans.length).toBe(6); | ||
|
|
||
| expect(spans.some(s => s.name === 'keep-me')).toBe(true); | ||
| expect(spans.some(s => s.name === 'another-keeper')).toBe(true); | ||
|
|
||
| expect(spans.some(s => s.name?.includes('ignore'))).toBe(false); | ||
|
|
||
| const greatGrandChild1 = spans.find(s => s.name === 'great-grandchild-1'); | ||
| const grandchild2 = spans.find(s => s.name === 'grandchild-2'); | ||
| const greatGreatGreatGrandChild1 = spans.find(s => s.name === 'great-great-great-grandchild-1'); | ||
|
|
||
| expect(greatGrandChild1).toBeDefined(); | ||
| expect(grandchild2).toBeDefined(); | ||
| expect(greatGreatGreatGrandChild1).toBeDefined(); | ||
|
|
||
| expect(greatGrandChild1?.parent_span_id).toBe(segmentSpanId); | ||
| expect(grandchild2?.parent_span_id).toBe(segmentSpanId); | ||
| expect(greatGreatGreatGrandChild1?.parent_span_id).toBe(greatGrandChild1?.span_id); | ||
|
|
||
| expect(spans.every(s => s.name === 'parent-span' || !s.is_segment)).toBe(true); | ||
|
|
||
| expect(clientReport.discarded_events).toEqual([ | ||
| { | ||
| category: 'span', | ||
| quantity: 3, // 3 ignored child spans | ||
| reason: 'ignored', | ||
| }, | ||
| ]); | ||
| }); |
11 changes: 11 additions & 0 deletions
11
dev-packages/browser-integration-tests/suites/tracing/ignoreSpans-streamed/segment/init.js
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/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [Sentry.spanStreamingIntegration()], | ||
| ignoreSpans: [/ignore/], | ||
| tracesSampleRate: 1, | ||
| debug: true, | ||
| }); |
11 changes: 11 additions & 0 deletions
11
...packages/browser-integration-tests/suites/tracing/ignoreSpans-streamed/segment/subject.js
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 @@ | ||
| // This segment span matches ignoreSpans — should NOT produce a transaction | ||
| Sentry.startSpan({ name: 'ignore-segment' }, () => { | ||
| Sentry.startSpan({ name: 'child-of-ignored-segment' }, () => {}); | ||
| }); | ||
|
|
||
| setTimeout(() => { | ||
| // This segment span does NOT match — should produce a transaction | ||
| Sentry.startSpan({ name: 'normal-segment' }, () => { | ||
| Sentry.startSpan({ name: 'child-span' }, () => {}); | ||
| }); | ||
| }, 1000); |
44 changes: 44 additions & 0 deletions
44
dev-packages/browser-integration-tests/suites/tracing/ignoreSpans-streamed/segment/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,44 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { | ||
| envelopeRequestParser, | ||
| hidePage, | ||
| shouldSkipTracingTest, | ||
| testingCdnBundle, | ||
| waitForClientReportRequest, | ||
| } from '../../../../utils/helpers'; | ||
| import { observeStreamedSpan, waitForStreamedSpans } from '../../../../utils/spanUtils'; | ||
| import type { ClientReport } from '@sentry/core'; | ||
|
|
||
| sentryTest('ignored segment span drops entire trace', async ({ getLocalTestUrl, page }) => { | ||
| sentryTest.skip(shouldSkipTracingTest() || testingCdnBundle()); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| observeStreamedSpan(page, span => { | ||
| if (span.name === 'ignore-segment' || span.name === 'child-of-ignored-segment') { | ||
| throw new Error('Ignored span found'); | ||
| } | ||
| return false; // means we keep on looking for unwanted spans | ||
| }); | ||
|
|
||
| const spansPromise = waitForStreamedSpans(page, spans => !!spans?.find(s => s.name === 'normal-segment')); | ||
|
|
||
| const clientReportPromise = waitForClientReportRequest(page); | ||
|
|
||
| await page.goto(url); | ||
|
|
||
| expect((await spansPromise)?.length).toBe(2); | ||
|
|
||
| await hidePage(page); | ||
|
|
||
| const clientReport = envelopeRequestParser<ClientReport>(await clientReportPromise); | ||
|
|
||
| expect(clientReport.discarded_events).toEqual([ | ||
| { | ||
| category: 'span', | ||
| quantity: 2, // segment + child span | ||
| reason: 'ignored', | ||
| }, | ||
| ]); | ||
| }); |
12 changes: 12 additions & 0 deletions
12
...ckages/node-integration-tests/suites/tracing/ignoreSpans-streamed/children/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,12 @@ | ||
| 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, | ||
| transport: loggingTransport, | ||
| traceLifecycle: 'stream', | ||
| ignoreSpans: ['middleware - expressInit', 'custom-to-drop'], | ||
| clientReportFlushInterval: 1_000, | ||
| }); |
31 changes: 31 additions & 0 deletions
31
dev-packages/node-integration-tests/suites/tracing/ignoreSpans-streamed/children/server.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 express from 'express'; | ||
| import cors from 'cors'; | ||
| import * as Sentry from '@sentry/node'; | ||
| import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| const app = express(); | ||
|
|
||
| app.use(cors()); | ||
|
|
||
| app.get('/test/express', (_req, res) => { | ||
| Sentry.startSpan( | ||
| { | ||
| name: 'custom-to-drop', | ||
| op: 'custom', | ||
| }, | ||
| () => { | ||
| Sentry.startSpan( | ||
| { | ||
| name: 'custom', | ||
| op: 'custom', | ||
| }, | ||
| () => {}, | ||
| ); | ||
| }, | ||
| ); | ||
| res.send({ response: 'response 1' }); | ||
| }); | ||
|
|
||
| Sentry.setupExpressErrorHandler(app); | ||
|
|
||
| startExpressServerAndSendPortToRunner(app); |
60 changes: 60 additions & 0 deletions
60
dev-packages/node-integration-tests/suites/tracing/ignoreSpans-streamed/children/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,60 @@ | ||
| import { afterAll, describe, expect } from 'vitest'; | ||
| import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../../utils/runner'; | ||
| import { SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core'; | ||
|
|
||
| describe('filtering child spans with ignoreSpans (streaming)', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| createEsmAndCjsTests(__dirname, 'server.mjs', 'instrument.mjs', (createRunner, test) => { | ||
| test('child spans are dropped and remaining spans correctly parented', async () => { | ||
| const runner = createRunner() | ||
| .unignore('client_report') | ||
| .expect({ | ||
| client_report: { | ||
| discarded_events: [ | ||
| { | ||
| category: 'span', | ||
| quantity: 2, | ||
| reason: 'ignored', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| .expect({ | ||
| span: container => { | ||
| // 5 spans: 1 root, 2 middleware, 1 request handler, 1 custom | ||
| // Would be 7 if we didn't ignore the 'middleware - expressInit' and 'custom-to-drop' spans | ||
| expect(container.items).toHaveLength(5); | ||
| const getSpan = (name: string, op: string) => | ||
| container.items.find( | ||
| item => item.name === name && item.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_OP]?.value === op, | ||
| ); | ||
| const queryMiddlewareSpan = getSpan('query', 'middleware.express'); | ||
| const corsMiddlewareSpan = getSpan('corsMiddleware', 'middleware.express'); | ||
| const requestHandlerSpan = getSpan('/test/express', 'request_handler.express'); | ||
| const httpServerSpan = getSpan('GET /test/express', 'http.server'); | ||
| const customSpan = getSpan('custom', 'custom'); | ||
|
|
||
| expect(queryMiddlewareSpan).toBeDefined(); | ||
| expect(corsMiddlewareSpan).toBeDefined(); | ||
| expect(requestHandlerSpan).toBeDefined(); | ||
| expect(httpServerSpan).toBeDefined(); | ||
| expect(customSpan).toBeDefined(); | ||
|
|
||
| expect(customSpan?.parent_span_id).toBe(requestHandlerSpan?.span_id); | ||
| expect(requestHandlerSpan?.parent_span_id).toBe(httpServerSpan?.span_id); | ||
| expect(queryMiddlewareSpan?.parent_span_id).toBe(httpServerSpan?.span_id); | ||
| expect(corsMiddlewareSpan?.parent_span_id).toBe(httpServerSpan?.span_id); | ||
| expect(httpServerSpan?.parent_span_id).toBeUndefined(); | ||
| }, | ||
| }) | ||
| .start(); | ||
|
|
||
| runner.makeRequest('get', '/test/express'); | ||
|
|
||
| await runner.completed(); | ||
| }); | ||
| }); | ||
| }); |
12 changes: 12 additions & 0 deletions
12
...ckages/node-integration-tests/suites/tracing/ignoreSpans-streamed/segments/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,12 @@ | ||
| 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, | ||
| transport: loggingTransport, | ||
| traceLifecycle: 'stream', | ||
| ignoreSpans: [/\/health/], | ||
| clientReportFlushInterval: 1_000, | ||
| }); |
20 changes: 20 additions & 0 deletions
20
dev-packages/node-integration-tests/suites/tracing/ignoreSpans-streamed/segments/server.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,20 @@ | ||
| import express from 'express'; | ||
| import cors from 'cors'; | ||
| import * as Sentry from '@sentry/node'; | ||
| import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| const app = express(); | ||
|
|
||
| app.use(cors()); | ||
|
|
||
| app.get('/health', (_req, res) => { | ||
| res.send({ status: 'ok-health' }); | ||
| }); | ||
|
|
||
| app.get('/ok', (_req, res) => { | ||
| res.send({ status: 'ok' }); | ||
| }); | ||
|
|
||
| Sentry.setupExpressErrorHandler(app); | ||
|
|
||
| startExpressServerAndSendPortToRunner(app); |
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.
a couple of pre-existing tests (like this one) needed adjustments because they previously reported the wrong telemetry type (for span streaming). Also the number of dropped spans increased because we now also count child spans.