-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(opentelemetry): Add addLink(s)
to span
#15387
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
12 commits
Select commit
Hold shift + click to select a range
92da34b
feat(core): Create types and utilities for span links
s1gr1d ebfafa8
review suggestions
s1gr1d 6736918
remove unknown typing
s1gr1d 3ab4aa8
feat(node): Add `addLink(s)` to span
s1gr1d 5a74d31
return undefined if no links
s1gr1d 84860b4
fix tests -> undefined instead of []
s1gr1d 2fb2b9d
add link to trace context
s1gr1d adf1cf8
fix test
s1gr1d 160fc56
type-cast tests
s1gr1d 91fde6d
change size limit
s1gr1d eee5c4d
Merge branch 'develop' into sig/otel-addLink
s1gr1d ff296f7
change test match
s1gr1d 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
33 changes: 33 additions & 0 deletions
33
dev-packages/node-integration-tests/suites/tracing/linking/scenario-addLink-nested.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,33 @@ | ||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
integrations: [], | ||
transport: loggingTransport, | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
Sentry.startSpan({ name: 'parent1' }, async parentSpan1 => { | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
Sentry.startSpan({ name: 'child1.1' }, async childSpan1 => { | ||
childSpan1.addLink({ | ||
context: parentSpan1.spanContext(), | ||
attributes: { 'sentry.link.type': 'previous_trace' }, | ||
}); | ||
|
||
childSpan1.end(); | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
Sentry.startSpan({ name: 'child1.2' }, async childSpan2 => { | ||
childSpan2.addLink({ | ||
context: parentSpan1.spanContext(), | ||
attributes: { 'sentry.link.type': 'previous_trace' }, | ||
}); | ||
|
||
childSpan2.end(); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
dev-packages/node-integration-tests/suites/tracing/linking/scenario-addLink.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,20 @@ | ||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
integrations: [], | ||
transport: loggingTransport, | ||
}); | ||
|
||
const span1 = Sentry.startInactiveSpan({ name: 'span1' }); | ||
span1.end(); | ||
|
||
Sentry.startSpan({ name: 'rootSpan' }, rootSpan => { | ||
rootSpan.addLink({ | ||
context: span1.spanContext(), | ||
attributes: { 'sentry.link.type': 'previous_trace' }, | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
dev-packages/node-integration-tests/suites/tracing/linking/scenario-addLinks-nested.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,31 @@ | ||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
integrations: [], | ||
transport: loggingTransport, | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
Sentry.startSpan({ name: 'parent1' }, async parentSpan1 => { | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
Sentry.startSpan({ name: 'child1.1' }, async childSpan1 => { | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
Sentry.startSpan({ name: 'child2.1' }, async childSpan2 => { | ||
childSpan2.addLinks([ | ||
{ context: parentSpan1.spanContext() }, | ||
{ | ||
context: childSpan1.spanContext(), | ||
attributes: { 'sentry.link.type': 'previous_trace' }, | ||
}, | ||
]); | ||
|
||
childSpan2.end(); | ||
}); | ||
|
||
childSpan1.end(); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
dev-packages/node-integration-tests/suites/tracing/linking/scenario-addLinks.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,26 @@ | ||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
integrations: [], | ||
transport: loggingTransport, | ||
}); | ||
|
||
const span1 = Sentry.startInactiveSpan({ name: 'span1' }); | ||
span1.end(); | ||
|
||
const span2 = Sentry.startInactiveSpan({ name: 'span2' }); | ||
span2.end(); | ||
|
||
Sentry.startSpan({ name: 'rootSpan' }, rootSpan => { | ||
rootSpan.addLinks([ | ||
{ context: span1.spanContext() }, | ||
{ | ||
context: span2.spanContext(), | ||
attributes: { 'sentry.link.type': 'previous_trace' }, | ||
}, | ||
]); | ||
}); |
157 changes: 157 additions & 0 deletions
157
dev-packages/node-integration-tests/suites/tracing/linking/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,157 @@ | ||
import { createRunner } from '../../../utils/runner'; | ||
|
||
describe('span links', () => { | ||
test('should link spans with addLink() in trace context', done => { | ||
let span1_traceId: string, span1_spanId: string; | ||
|
||
createRunner(__dirname, 'scenario-addLink.ts') | ||
.expect({ | ||
transaction: event => { | ||
expect(event.transaction).toBe('span1'); | ||
|
||
span1_traceId = event.contexts?.trace?.trace_id as string; | ||
span1_spanId = event.contexts?.trace?.span_id as string; | ||
|
||
expect(event.spans).toEqual([]); | ||
}, | ||
}) | ||
.expect({ | ||
transaction: event => { | ||
expect(event.transaction).toBe('rootSpan'); | ||
|
||
expect(event.contexts?.trace?.links).toEqual([ | ||
expect.objectContaining({ | ||
trace_id: expect.stringMatching(span1_traceId), | ||
span_id: expect.stringMatching(span1_spanId), | ||
attributes: expect.objectContaining({ | ||
'sentry.link.type': 'previous_trace', | ||
}), | ||
}), | ||
]); | ||
}, | ||
}) | ||
.start(done); | ||
}); | ||
|
||
test('should link spans with addLinks() in trace context', done => { | ||
let span1_traceId: string, span1_spanId: string, span2_traceId: string, span2_spanId: string; | ||
|
||
createRunner(__dirname, 'scenario-addLinks.ts') | ||
.expect({ | ||
transaction: event => { | ||
expect(event.transaction).toBe('span1'); | ||
|
||
span1_traceId = event.contexts?.trace?.trace_id as string; | ||
span1_spanId = event.contexts?.trace?.span_id as string; | ||
|
||
expect(event.spans).toEqual([]); | ||
}, | ||
}) | ||
.expect({ | ||
transaction: event => { | ||
expect(event.transaction).toBe('span2'); | ||
|
||
span2_traceId = event.contexts?.trace?.trace_id as string; | ||
span2_spanId = event.contexts?.trace?.span_id as string; | ||
|
||
expect(event.spans).toEqual([]); | ||
}, | ||
}) | ||
.expect({ | ||
transaction: event => { | ||
expect(event.transaction).toBe('rootSpan'); | ||
|
||
expect(event.contexts?.trace?.links).toEqual([ | ||
expect.not.objectContaining({ attributes: expect.anything() }) && | ||
expect.objectContaining({ | ||
trace_id: expect.stringMatching(span1_traceId), | ||
span_id: expect.stringMatching(span1_spanId), | ||
}), | ||
expect.objectContaining({ | ||
trace_id: expect.stringMatching(span2_traceId), | ||
span_id: expect.stringMatching(span2_spanId), | ||
attributes: expect.objectContaining({ | ||
'sentry.link.type': 'previous_trace', | ||
}), | ||
}), | ||
]); | ||
}, | ||
}) | ||
.start(done); | ||
}); | ||
|
||
test('should link spans with addLink() in nested startSpan() calls', done => { | ||
createRunner(__dirname, 'scenario-addLink-nested.ts') | ||
.expect({ | ||
transaction: event => { | ||
expect(event.transaction).toBe('parent1'); | ||
|
||
const parent1_traceId = event.contexts?.trace?.trace_id as string; | ||
const parent1_spanId = event.contexts?.trace?.span_id as string; | ||
|
||
const spans = event.spans || []; | ||
const child1_1 = spans.find(span => span.description === 'child1.1'); | ||
const child1_2 = spans.find(span => span.description === 'child1.2'); | ||
|
||
expect(child1_1).toBeDefined(); | ||
expect(child1_1?.links).toEqual([ | ||
expect.objectContaining({ | ||
trace_id: expect.stringMatching(parent1_traceId), | ||
span_id: expect.stringMatching(parent1_spanId), | ||
attributes: expect.objectContaining({ | ||
'sentry.link.type': 'previous_trace', | ||
}), | ||
}), | ||
]); | ||
|
||
expect(child1_2).toBeDefined(); | ||
expect(child1_2?.links).toEqual([ | ||
expect.objectContaining({ | ||
trace_id: expect.stringMatching(parent1_traceId), | ||
span_id: expect.stringMatching(parent1_spanId), | ||
attributes: expect.objectContaining({ | ||
'sentry.link.type': 'previous_trace', | ||
}), | ||
}), | ||
]); | ||
}, | ||
}) | ||
.start(done); | ||
}); | ||
|
||
test('should link spans with addLinks() in nested startSpan() calls', done => { | ||
createRunner(__dirname, 'scenario-addLinks-nested.ts') | ||
.expect({ | ||
transaction: event => { | ||
expect(event.transaction).toBe('parent1'); | ||
|
||
const parent1_traceId = event.contexts?.trace?.trace_id as string; | ||
const parent1_spanId = event.contexts?.trace?.span_id as string; | ||
|
||
const spans = event.spans || []; | ||
const child1_1 = spans.find(span => span.description === 'child1.1'); | ||
const child2_1 = spans.find(span => span.description === 'child2.1'); | ||
|
||
expect(child1_1).toBeDefined(); | ||
|
||
expect(child2_1).toBeDefined(); | ||
|
||
expect(child2_1?.links).toEqual([ | ||
expect.not.objectContaining({ attributes: expect.anything() }) && | ||
expect.objectContaining({ | ||
trace_id: expect.stringMatching(parent1_traceId), | ||
span_id: expect.stringMatching(parent1_spanId), | ||
}), | ||
expect.objectContaining({ | ||
trace_id: expect.stringMatching(child1_1?.trace_id || 'non-existent-id-fallback'), | ||
span_id: expect.stringMatching(child1_1?.span_id || 'non-existent-id-fallback'), | ||
attributes: expect.objectContaining({ | ||
'sentry.link.type': 'previous_trace', | ||
}), | ||
}), | ||
]); | ||
}, | ||
}) | ||
.start(done); | ||
}); | ||
}); |
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.