-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(tracing): Send sample rate and type in transaction item header in envelope #3068
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
4 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
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,56 @@ | ||
import { Event, TransactionSamplingMethod } from '@sentry/types'; | ||
|
||
import { API } from '../../src/api'; | ||
import { eventToSentryRequest } from '../../src/request'; | ||
|
||
describe('eventToSentryRequest', () => { | ||
const api = new API('https://[email protected]/12312012'); | ||
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. I wonder how dogs can be bad at keeping secrets? 🤔 |
||
const event: Event = { | ||
contexts: { trace: { trace_id: '1231201211212012', span_id: '12261980', op: 'pageload' } }, | ||
environment: 'dogpark', | ||
event_id: '0908201304152013', | ||
release: 'off.leash.park', | ||
spans: [], | ||
transaction: '/dogs/are/great/', | ||
type: 'transaction', | ||
user: { id: '1121', username: 'CharlieDog', ip_address: '11.21.20.12' }, | ||
}; | ||
|
||
[ | ||
{ method: TransactionSamplingMethod.Rate, rate: '0.1121', dog: 'Charlie' }, | ||
{ method: TransactionSamplingMethod.Sampler, rate: '0.1231', dog: 'Maisey' }, | ||
{ method: TransactionSamplingMethod.Inheritance, dog: 'Cory' }, | ||
{ method: TransactionSamplingMethod.Explicit, dog: 'Bodhi' }, | ||
|
||
// this shouldn't ever happen (at least the method should always be included in tags), but good to know that things | ||
// won't blow up if it does | ||
{ dog: 'Lucy' }, | ||
].forEach(({ method, rate, dog }) => { | ||
it(`adds transaction sampling information to item header - ${method}, ${rate}, ${dog}`, () => { | ||
// TODO kmclb - once tag types are loosened, don't need to cast to string here | ||
event.tags = { __sentry_samplingMethod: String(method), __sentry_sampleRate: String(rate), dog }; | ||
|
||
const result = eventToSentryRequest(event as Event, api); | ||
|
||
const [envelopeHeaderString, itemHeaderString, eventString] = result.body.split('\n'); | ||
|
||
const envelope = { | ||
envelopeHeader: JSON.parse(envelopeHeaderString), | ||
itemHeader: JSON.parse(itemHeaderString), | ||
event: JSON.parse(eventString), | ||
}; | ||
|
||
// the right stuff is added to the item header | ||
expect(envelope.itemHeader).toEqual({ | ||
type: 'transaction', | ||
// TODO kmclb - once tag types are loosened, don't need to cast to string here | ||
sample_rates: [{ id: String(method), rate: String(rate) }], | ||
}); | ||
|
||
// show that it pops the right tags and leaves the rest alone | ||
expect('__sentry_samplingMethod' in envelope.event.tags).toBe(false); | ||
expect('__sentry_sampleRate' in envelope.event.tags).toBe(false); | ||
expect('dog' in envelope.event.tags).toBe(true); | ||
}); | ||
}); | ||
}); |
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
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.
👍