-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(core): Add addLink(s)
to Sentry span
#15452
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 2 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
9 changes: 9 additions & 0 deletions
9
dev-packages/browser-integration-tests/suites/tracing/linking-addLink/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,9 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
integrations: [], | ||
tracesSampleRate: 1, | ||
}); |
28 changes: 28 additions & 0 deletions
28
dev-packages/browser-integration-tests/suites/tracing/linking-addLink/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,28 @@ | ||
// REGULAR --- | ||
const rootSpan1 = Sentry.startInactiveSpan({ name: 'rootSpan1' }); | ||
rootSpan1.end(); | ||
|
||
Sentry.startSpan({ name: 'rootSpan2' }, rootSpan2 => { | ||
rootSpan2.addLink({ | ||
context: rootSpan1.spanContext(), | ||
attributes: { 'sentry.link.type': 'previous_trace' }, | ||
}); | ||
}); | ||
|
||
// NESTED --- | ||
Sentry.startSpan({ name: 'rootSpan3' }, async rootSpan3 => { | ||
Sentry.startSpan({ name: 'childSpan3.1' }, async childSpan1 => { | ||
childSpan1.addLink({ | ||
context: rootSpan1.spanContext(), | ||
attributes: { 'sentry.link.type': 'previous_trace' }, | ||
}); | ||
|
||
childSpan1.end(); | ||
}); | ||
|
||
Sentry.startSpan({ name: 'childSpan3.2' }, async childSpan2 => { | ||
childSpan2.addLink({ context: rootSpan3.spanContext() }); | ||
|
||
childSpan2.end(); | ||
}); | ||
}); |
65 changes: 65 additions & 0 deletions
65
dev-packages/browser-integration-tests/suites/tracing/linking-addLink/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,65 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event, SpanJSON } from '@sentry/core'; | ||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { getMultipleSentryEnvelopeRequests, shouldSkipTracingTest } from '../../../utils/helpers'; | ||
|
||
sentryTest('should link spans with addLink() in trace context', async ({ getLocalTestUrl, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
const [rootSpan1, rootSpan2] = await getMultipleSentryEnvelopeRequests<Event>(page, 3, { url }); | ||
|
||
const rootSpan1_traceId = rootSpan1.contexts?.trace?.trace_id as string; | ||
const rootSpan1_spanId = rootSpan1.contexts?.trace?.span_id as string; | ||
|
||
expect(rootSpan1.transaction).toBe('rootSpan1'); | ||
expect(rootSpan1.spans).toEqual([]); | ||
|
||
expect(rootSpan2.transaction).toBe('rootSpan2'); | ||
expect(rootSpan2.spans).toEqual([]); | ||
|
||
expect(rootSpan2.contexts?.trace?.links?.length).toBe(1); | ||
expect(rootSpan2.contexts?.trace?.links?.[0]).toMatchObject({ | ||
attributes: { 'sentry.link.type': 'previous_trace' }, | ||
sampled: true, | ||
span_id: rootSpan1_spanId, | ||
trace_id: rootSpan1_traceId, | ||
}); | ||
}); | ||
|
||
sentryTest('should link spans with addLink() in nested startSpan() calls', async ({ getLocalTestUrl, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
const events = await getMultipleSentryEnvelopeRequests<Event>(page, 3, { url }); | ||
const [rootSpan1, /* rootSpan2 */ , rootSpan3] = events; | ||
|
||
const rootSpan1_traceId = rootSpan1.contexts?.trace?.trace_id as string; | ||
const rootSpan1_spanId = rootSpan1.contexts?.trace?.span_id as string; | ||
|
||
const [childSpan_3_1, childSpan_3_2] = rootSpan3.spans as [SpanJSON, SpanJSON]; | ||
const rootSpan3_traceId = rootSpan3.contexts?.trace?.trace_id as string; | ||
const rootSpan3_spanId = rootSpan3.contexts?.trace?.span_id as string; | ||
|
||
expect(rootSpan3.transaction).toBe('rootSpan3'); | ||
|
||
expect(childSpan_3_1.description).toBe('childSpan3.1'); | ||
expect(childSpan_3_1.links?.length).toBe(1); | ||
expect(childSpan_3_1.links?.[0]).toMatchObject({ | ||
attributes: { 'sentry.link.type': 'previous_trace' }, | ||
sampled: true, | ||
span_id: rootSpan1_spanId, | ||
trace_id: rootSpan1_traceId, | ||
}); | ||
|
||
expect(childSpan_3_2.description).toBe('childSpan3.2'); | ||
expect(childSpan_3_2.links?.[0]).toMatchObject({ | ||
sampled: true, | ||
span_id: rootSpan3_spanId, | ||
trace_id: rootSpan3_traceId, | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
dev-packages/browser-integration-tests/suites/tracing/linking-addLinks/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,9 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
integrations: [], | ||
tracesSampleRate: 1, | ||
}); |
35 changes: 35 additions & 0 deletions
35
dev-packages/browser-integration-tests/suites/tracing/linking-addLinks/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,35 @@ | ||
// REGULAR --- | ||
const rootSpan1 = Sentry.startInactiveSpan({ name: 'rootSpan1' }); | ||
rootSpan1.end(); | ||
|
||
const rootSpan2 = Sentry.startInactiveSpan({ name: 'rootSpan2' }); | ||
rootSpan2.end(); | ||
|
||
Sentry.startSpan({ name: 'rootSpan3' }, rootSpan3 => { | ||
rootSpan3.addLinks([ | ||
{ context: rootSpan1.spanContext() }, | ||
{ | ||
context: rootSpan2.spanContext(), | ||
attributes: { 'sentry.link.type': 'previous_trace' }, | ||
}, | ||
]); | ||
}); | ||
|
||
// NESTED --- | ||
Sentry.startSpan({ name: 'rootSpan4' }, async rootSpan4 => { | ||
Sentry.startSpan({ name: 'childSpan4.1' }, async childSpan1 => { | ||
Sentry.startSpan({ name: 'childSpan4.2' }, async childSpan2 => { | ||
childSpan2.addLinks([ | ||
{ context: rootSpan4.spanContext() }, | ||
{ | ||
context: rootSpan2.spanContext(), | ||
attributes: { 'sentry.link.type': 'previous_trace' }, | ||
}, | ||
]); | ||
|
||
childSpan2.end(); | ||
}); | ||
|
||
childSpan1.end(); | ||
}); | ||
}); |
80 changes: 80 additions & 0 deletions
80
dev-packages/browser-integration-tests/suites/tracing/linking-addLinks/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,80 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event, SpanJSON } from '@sentry/core'; | ||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { getMultipleSentryEnvelopeRequests, shouldSkipTracingTest } from '../../../utils/helpers'; | ||
|
||
sentryTest('should link spans with addLinks() in trace context', async ({ getLocalTestUrl, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
const [rootSpan1, rootSpan2, rootSpan3] = await getMultipleSentryEnvelopeRequests<Event>(page, 3, { url }); | ||
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. If I understand this test correctly, we're sending 4 transaction events here, right? waiting on 3 then also introduces a potential flake as we depend on events being sent in the correct order. |
||
|
||
const rootSpan1_traceId = rootSpan1.contexts?.trace?.trace_id as string; | ||
const rootSpan1_spanId = rootSpan1.contexts?.trace?.span_id as string; | ||
|
||
expect(rootSpan1.transaction).toBe('rootSpan1'); | ||
expect(rootSpan1.spans).toEqual([]); | ||
|
||
const rootSpan2_traceId = rootSpan2.contexts?.trace?.trace_id as string; | ||
const rootSpan2_spanId = rootSpan2.contexts?.trace?.span_id as string; | ||
|
||
expect(rootSpan2.transaction).toBe('rootSpan2'); | ||
expect(rootSpan2.spans).toEqual([]); | ||
|
||
expect(rootSpan3.transaction).toBe('rootSpan3'); | ||
expect(rootSpan3.spans).toEqual([]); | ||
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, | ||
}, | ||
]); | ||
}); | ||
|
||
sentryTest('should link spans with addLinks() in nested startSpan() calls', async ({ getLocalTestUrl, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
const events = await getMultipleSentryEnvelopeRequests<Event>(page, 4, { url }); | ||
const [/* rootSpan1 */ , rootSpan2, /* rootSpan3 */ , rootSpan4] = events; | ||
|
||
const rootSpan2_traceId = rootSpan2.contexts?.trace?.trace_id as string; | ||
const rootSpan2_spanId = rootSpan2.contexts?.trace?.span_id as string; | ||
|
||
const [childSpan_4_1, childSpan_4_2] = rootSpan4.spans as [SpanJSON, SpanJSON]; | ||
const rootSpan4_traceId = rootSpan4.contexts?.trace?.trace_id as string; | ||
const rootSpan4_spanId = rootSpan4.contexts?.trace?.span_id as string; | ||
|
||
expect(rootSpan4.transaction).toBe('rootSpan4'); | ||
|
||
expect(childSpan_4_1.description).toBe('childSpan4.1'); | ||
expect(childSpan_4_1.links).toBe(undefined); | ||
|
||
expect(childSpan_4_2.description).toBe('childSpan4.2'); | ||
expect(childSpan_4_2.links?.length).toBe(2); | ||
expect(childSpan_4_2.links).toEqual([ | ||
{ | ||
sampled: true, | ||
span_id: rootSpan4_spanId, | ||
trace_id: rootSpan4_traceId, | ||
}, | ||
{ | ||
attributes: { 'sentry.link.type': 'previous_trace' }, | ||
sampled: true, | ||
span_id: rootSpan2_spanId, | ||
trace_id: rootSpan2_traceId, | ||
}, | ||
]); | ||
}); |
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.
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.
if we need to wait for 3 events here (do we?) but only want 2, my gut feeling tells me that there's room for flakes. Let's use the
waitForTransactionRequest
helper instead and check for the correcttransaction
(or some other identifier). This should be safer for flakes and makes things more explicit.(side note: I think we should generally use this helper more often, as it works out really well in our e2e tests. But obviously, no action required, we can do this iteratively and over time)