-
-
Notifications
You must be signed in to change notification settings - Fork 360
feat(tracing): Implement strict trace continuation #5829
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
antonis
wants to merge
4
commits into
main
Choose a base branch
from
worktree-strict-trace-continuation
base: main
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
4 commits
Select commit
Hold shift + click to select a range
914b82a
feat(tracing): Implement strict trace continuation
antonis d425efc
chore: Add changelog entry for strict trace continuation
antonis 3fe2c78
Merge remote-tracking branch 'origin/main' into worktree-strict-traceโฆ
antonis 34c001f
style: Fix oxfmt import spacing
antonis 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
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,262 @@ | ||
| import { continueTrace, getCurrentScope, setCurrentClient } from '@sentry/core'; | ||
|
|
||
| import { getDefaultTestClientOptions, TestClient } from './mocks/client'; | ||
|
|
||
| describe('strictTraceContinuation', () => { | ||
| let client: TestClient; | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('with matching org IDs', () => { | ||
| beforeEach(() => { | ||
| client = new TestClient( | ||
| getDefaultTestClientOptions({ | ||
| tracesSampleRate: 1.0, | ||
| dsn: 'https://abc@o123.ingest.sentry.io/1234', | ||
| }), | ||
| ); | ||
| setCurrentClient(client); | ||
| client.init(); | ||
| }); | ||
|
|
||
| it('continues trace when baggage org_id matches DSN org ID', () => { | ||
| const scope = continueTrace( | ||
| { | ||
| sentryTrace: '12312012123120121231201212312012-1121201211212012-1', | ||
| baggage: 'sentry-org_id=123', | ||
| }, | ||
| () => { | ||
| return getCurrentScope(); | ||
| }, | ||
| ); | ||
|
|
||
| expect(scope.getPropagationContext().traceId).toBe('12312012123120121231201212312012'); | ||
| expect(scope.getPropagationContext().parentSpanId).toBe('1121201211212012'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with mismatching org IDs', () => { | ||
| beforeEach(() => { | ||
| client = new TestClient( | ||
| getDefaultTestClientOptions({ | ||
| tracesSampleRate: 1.0, | ||
| dsn: 'https://abc@o123.ingest.sentry.io/1234', | ||
| }), | ||
| ); | ||
| setCurrentClient(client); | ||
| client.init(); | ||
| }); | ||
|
|
||
| it('starts new trace when baggage org_id does not match DSN org ID', () => { | ||
| const scope = continueTrace( | ||
| { | ||
| sentryTrace: '12312012123120121231201212312012-1121201211212012-1', | ||
| baggage: 'sentry-org_id=456', | ||
| }, | ||
| () => { | ||
| return getCurrentScope(); | ||
| }, | ||
| ); | ||
|
|
||
| expect(scope.getPropagationContext().traceId).not.toBe('12312012123120121231201212312012'); | ||
| expect(scope.getPropagationContext().parentSpanId).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with orgId option override', () => { | ||
| beforeEach(() => { | ||
| client = new TestClient( | ||
| getDefaultTestClientOptions({ | ||
| tracesSampleRate: 1.0, | ||
| dsn: 'https://abc@o123.ingest.sentry.io/1234', | ||
| orgId: '999', | ||
| }), | ||
| ); | ||
| setCurrentClient(client); | ||
| client.init(); | ||
| }); | ||
|
|
||
| it('uses orgId option over DSN-extracted org ID', () => { | ||
| // baggage org_id=123 matches DSN but NOT the orgId option (999) | ||
| const scope = continueTrace( | ||
| { | ||
| sentryTrace: '12312012123120121231201212312012-1121201211212012-1', | ||
| baggage: 'sentry-org_id=123', | ||
| }, | ||
| () => { | ||
| return getCurrentScope(); | ||
| }, | ||
| ); | ||
|
|
||
| // Should start new trace because orgId option (999) != baggage org_id (123) | ||
| expect(scope.getPropagationContext().traceId).not.toBe('12312012123120121231201212312012'); | ||
| expect(scope.getPropagationContext().parentSpanId).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('continues trace when baggage matches orgId option', () => { | ||
| const scope = continueTrace( | ||
| { | ||
| sentryTrace: '12312012123120121231201212312012-1121201211212012-1', | ||
| baggage: 'sentry-org_id=999', | ||
| }, | ||
| () => { | ||
| return getCurrentScope(); | ||
| }, | ||
| ); | ||
|
|
||
| expect(scope.getPropagationContext().traceId).toBe('12312012123120121231201212312012'); | ||
| expect(scope.getPropagationContext().parentSpanId).toBe('1121201211212012'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('strictTraceContinuation=true', () => { | ||
| beforeEach(() => { | ||
| client = new TestClient( | ||
| getDefaultTestClientOptions({ | ||
| tracesSampleRate: 1.0, | ||
| dsn: 'https://abc@o123.ingest.sentry.io/1234', | ||
| strictTraceContinuation: true, | ||
| }), | ||
| ); | ||
| setCurrentClient(client); | ||
| client.init(); | ||
| }); | ||
|
|
||
| it('starts new trace when baggage has no org_id', () => { | ||
| const scope = continueTrace( | ||
| { | ||
| sentryTrace: '12312012123120121231201212312012-1121201211212012-1', | ||
| baggage: 'sentry-environment=production', | ||
| }, | ||
| () => { | ||
| return getCurrentScope(); | ||
| }, | ||
| ); | ||
|
|
||
| expect(scope.getPropagationContext().traceId).not.toBe('12312012123120121231201212312012'); | ||
| expect(scope.getPropagationContext().parentSpanId).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('starts new trace when SDK has no org_id but baggage does', () => { | ||
| // Use a DSN without org ID in hostname | ||
| const clientWithoutOrgId = new TestClient( | ||
| getDefaultTestClientOptions({ | ||
| tracesSampleRate: 1.0, | ||
| dsn: 'https://abc@sentry.example.com/1234', | ||
| strictTraceContinuation: true, | ||
| }), | ||
| ); | ||
| setCurrentClient(clientWithoutOrgId); | ||
| clientWithoutOrgId.init(); | ||
|
|
||
| const scope = continueTrace( | ||
| { | ||
| sentryTrace: '12312012123120121231201212312012-1121201211212012-1', | ||
| baggage: 'sentry-org_id=123', | ||
| }, | ||
| () => { | ||
| return getCurrentScope(); | ||
| }, | ||
| ); | ||
|
|
||
| expect(scope.getPropagationContext().traceId).not.toBe('12312012123120121231201212312012'); | ||
| expect(scope.getPropagationContext().parentSpanId).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('continues trace when both org IDs are missing', () => { | ||
| const clientWithoutOrgId = new TestClient( | ||
| getDefaultTestClientOptions({ | ||
| tracesSampleRate: 1.0, | ||
| dsn: 'https://abc@sentry.example.com/1234', | ||
| strictTraceContinuation: true, | ||
| }), | ||
| ); | ||
| setCurrentClient(clientWithoutOrgId); | ||
| clientWithoutOrgId.init(); | ||
|
|
||
| const scope = continueTrace( | ||
| { | ||
| sentryTrace: '12312012123120121231201212312012-1121201211212012-1', | ||
| baggage: 'sentry-environment=production', | ||
| }, | ||
| () => { | ||
| return getCurrentScope(); | ||
| }, | ||
| ); | ||
|
|
||
| expect(scope.getPropagationContext().traceId).toBe('12312012123120121231201212312012'); | ||
| expect(scope.getPropagationContext().parentSpanId).toBe('1121201211212012'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('strictTraceContinuation=false (default)', () => { | ||
| beforeEach(() => { | ||
| client = new TestClient( | ||
| getDefaultTestClientOptions({ | ||
| tracesSampleRate: 1.0, | ||
| dsn: 'https://abc@o123.ingest.sentry.io/1234', | ||
| strictTraceContinuation: false, | ||
| }), | ||
| ); | ||
| setCurrentClient(client); | ||
| client.init(); | ||
| }); | ||
|
|
||
| it('continues trace when baggage has no org_id', () => { | ||
| const scope = continueTrace( | ||
| { | ||
| sentryTrace: '12312012123120121231201212312012-1121201211212012-1', | ||
| baggage: 'sentry-environment=production', | ||
| }, | ||
| () => { | ||
| return getCurrentScope(); | ||
| }, | ||
| ); | ||
|
|
||
| expect(scope.getPropagationContext().traceId).toBe('12312012123120121231201212312012'); | ||
| expect(scope.getPropagationContext().parentSpanId).toBe('1121201211212012'); | ||
| }); | ||
|
|
||
| it('continues trace when SDK has no org_id but baggage does', () => { | ||
| const clientWithoutOrgId = new TestClient( | ||
| getDefaultTestClientOptions({ | ||
| tracesSampleRate: 1.0, | ||
| dsn: 'https://abc@sentry.example.com/1234', | ||
| strictTraceContinuation: false, | ||
| }), | ||
| ); | ||
| setCurrentClient(clientWithoutOrgId); | ||
| clientWithoutOrgId.init(); | ||
|
|
||
| const scope = continueTrace( | ||
| { | ||
| sentryTrace: '12312012123120121231201212312012-1121201211212012-1', | ||
| baggage: 'sentry-org_id=123', | ||
| }, | ||
| () => { | ||
| return getCurrentScope(); | ||
| }, | ||
| ); | ||
|
|
||
| expect(scope.getPropagationContext().traceId).toBe('12312012123120121231201212312012'); | ||
| expect(scope.getPropagationContext().parentSpanId).toBe('1121201211212012'); | ||
| }); | ||
|
|
||
| it('still starts new trace when org IDs mismatch', () => { | ||
| const scope = continueTrace( | ||
| { | ||
| sentryTrace: '12312012123120121231201212312012-1121201211212012-1', | ||
| baggage: 'sentry-org_id=456', | ||
| }, | ||
| () => { | ||
| return getCurrentScope(); | ||
| }, | ||
| ); | ||
|
|
||
| expect(scope.getPropagationContext().traceId).not.toBe('12312012123120121231201212312012'); | ||
| expect(scope.getPropagationContext().parentSpanId).toBeUndefined(); | ||
| }); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.