-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Add links to span options (#15453)
part of #14991
- Loading branch information
Showing
5 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
dev-packages/browser-integration-tests/suites/tracing/linking-spanOptions/init.js
This file contains 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,9 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
integrations: [], | ||
tracesSampleRate: 1, | ||
}); |
20 changes: 20 additions & 0 deletions
20
dev-packages/browser-integration-tests/suites/tracing/linking-spanOptions/subject.js
This file contains 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 @@ | ||
const rootSpan1 = Sentry.startInactiveSpan({ name: 'rootSpan1' }); | ||
rootSpan1.end(); | ||
|
||
const rootSpan2 = Sentry.startInactiveSpan({ name: 'rootSpan2' }); | ||
rootSpan2.end(); | ||
|
||
Sentry.startSpan( | ||
{ | ||
name: 'rootSpan3', | ||
links: [ | ||
{ context: rootSpan1.spanContext() }, | ||
{ context: rootSpan2.spanContext(), attributes: { 'sentry.link.type': 'previous_trace' } }, | ||
], | ||
}, | ||
async () => { | ||
Sentry.startSpan({ name: 'childSpan3.1' }, async childSpan1 => { | ||
childSpan1.end(); | ||
}); | ||
}, | ||
); |
48 changes: 48 additions & 0 deletions
48
dev-packages/browser-integration-tests/suites/tracing/linking-spanOptions/test.ts
This file contains 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,48 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { TransactionEvent } from '@sentry/core'; | ||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { envelopeRequestParser, shouldSkipTracingTest, waitForTransactionRequest } from '../../../utils/helpers'; | ||
|
||
sentryTest('should link spans by adding "links" to span options', async ({ getLocalTestUrl, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const rootSpan1Promise = waitForTransactionRequest(page, event => event.transaction === 'rootSpan1'); | ||
const rootSpan2Promise = waitForTransactionRequest(page, event => event.transaction === 'rootSpan2'); | ||
const rootSpan3Promise = waitForTransactionRequest(page, event => event.transaction === 'rootSpan3'); | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
await page.goto(url); | ||
|
||
const rootSpan1 = envelopeRequestParser<TransactionEvent>(await rootSpan1Promise); | ||
const rootSpan2 = envelopeRequestParser<TransactionEvent>(await rootSpan2Promise); | ||
const rootSpan3 = envelopeRequestParser<TransactionEvent>(await rootSpan3Promise); | ||
|
||
const rootSpan1_traceId = rootSpan1.contexts?.trace?.trace_id as string; | ||
const rootSpan1_spanId = rootSpan1.contexts?.trace?.span_id as string; | ||
const rootSpan2_traceId = rootSpan2.contexts?.trace?.trace_id as string; | ||
const rootSpan2_spanId = rootSpan2.contexts?.trace?.span_id as string; | ||
|
||
expect(rootSpan1.transaction).toBe('rootSpan1'); | ||
expect(rootSpan1.spans).toEqual([]); | ||
|
||
expect(rootSpan3.transaction).toBe('rootSpan3'); | ||
expect(rootSpan3.spans?.length).toBe(1); | ||
expect(rootSpan3.spans?.[0].description).toBe('childSpan3.1'); | ||
|
||
expect(rootSpan3.contexts?.trace?.links?.length).toBe(2); | ||
expect(rootSpan3.contexts?.trace?.links).toEqual([ | ||
{ | ||
sampled: true, | ||
span_id: rootSpan1_spanId, | ||
trace_id: rootSpan1_traceId, | ||
}, | ||
{ | ||
attributes: { 'sentry.link.type': 'previous_trace' }, | ||
sampled: true, | ||
span_id: rootSpan2_spanId, | ||
trace_id: rootSpan2_traceId, | ||
}, | ||
]); | ||
}); |
This file contains 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 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