-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(core): Deprecate Transaction.getDynamicSamplingContext
in favour of getDynamicSamplingContextFromSpan
#10094
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 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
45e844d
feat(core): Deprecate `Transaction.getDynamicSamplingContext` in favo…
Lms24 5788a54
fix v7 frozenDSC obtain mechanism
Lms24 3e156ba
fix tests, add tests
Lms24 c9c1592
apply new APIs (spanIsSampled, spanToJson) after rebase
Lms24 14f2cff
fix tracing tests
Lms24 9c76fc9
use txn.attributes instead of txn.metadata.source
Lms24 5b5dcea
sample rate attribute && remove emit
Lms24 be3dbbe
fix tests once again
Lms24 74b9799
use txn.metadata instead of txn.attributes :(
Lms24 6962539
lint
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
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
85 changes: 85 additions & 0 deletions
85
packages/core/test/lib/tracing/dynamicSamplingContext.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,85 @@ | ||
import type { TransactionSource } from '@sentry/types'; | ||
import { Hub, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, makeMain } from '../../../src'; | ||
import { Transaction, getDynamicSamplingContextFromSpan, startInactiveSpan } from '../../../src/tracing'; | ||
import { addTracingExtensions } from '../../../src/tracing'; | ||
import { TestClient, getDefaultTestClientOptions } from '../../mocks/client'; | ||
|
||
describe('getDynamicSamplingContextFromSpan', () => { | ||
let hub: Hub; | ||
beforeEach(() => { | ||
const options = getDefaultTestClientOptions({ tracesSampleRate: 1.0, release: '1.0.1' }); | ||
const client = new TestClient(options); | ||
hub = new Hub(client); | ||
hub.bindClient(client); | ||
makeMain(hub); | ||
addTracingExtensions(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
test('returns the DSC provided during transaction creation', () => { | ||
const transaction = new Transaction({ | ||
name: 'tx', | ||
metadata: { dynamicSamplingContext: { environment: 'myEnv' } }, | ||
}); | ||
|
||
const dynamicSamplingContext = getDynamicSamplingContextFromSpan(transaction); | ||
|
||
expect(dynamicSamplingContext).toStrictEqual({ environment: 'myEnv' }); | ||
}); | ||
|
||
test('returns a new DSC, if no DSC was provided during transaction creation', () => { | ||
const transaction = startInactiveSpan({ name: 'tx' }); | ||
|
||
// Only setting the attribute manually because we can't "fake" a | ||
// sample rate or txn name source anymore like we used to. | ||
transaction?.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, 0.56); | ||
transaction?.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route'); | ||
|
||
const dynamicSamplingContext = getDynamicSamplingContextFromSpan(transaction!); | ||
|
||
expect(dynamicSamplingContext).toStrictEqual({ | ||
release: '1.0.1', | ||
environment: 'production', | ||
sampled: 'true', | ||
sample_rate: '0.56', | ||
trace_id: expect.any(String), | ||
transaction: 'tx', | ||
}); | ||
}); | ||
|
||
describe('Including transaction name in DSC', () => { | ||
test('is not included if transaction source is url', () => { | ||
const transaction = new Transaction({ | ||
name: 'tx', | ||
metadata: { | ||
source: 'url', | ||
}, | ||
}); | ||
|
||
const dsc = getDynamicSamplingContextFromSpan(transaction); | ||
expect(dsc.transaction).toBeUndefined(); | ||
}); | ||
|
||
test.each([ | ||
['is included if transaction source is parameterized route/url', 'route'], | ||
['is included if transaction source is a custom name', 'custom'], | ||
])('%s', (_: string, source) => { | ||
const transaction = new Transaction({ | ||
name: 'tx', | ||
metadata: { | ||
...(source && { source: source as TransactionSource }), | ||
}, | ||
}); | ||
|
||
// Only setting the attribute manually because we're directly calling new Transaction() | ||
transaction?.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source); | ||
|
||
const dsc = getDynamicSamplingContextFromSpan(transaction); | ||
|
||
expect(dsc.transaction).toEqual('tx'); | ||
}); | ||
}); | ||
}); |
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.
Uh oh!
There was an error while loading. Please reload this page.