-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(core): Send Baggage in Envelope Header #5104
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
11 commits
Select commit
Hold shift + click to select a range
0ef7352
feat(core): Send baggage in envelope header
Lms24 ceec823
add other properties, only attach baggage to transaction events
Lms24 a7e24ae
drop undefined baggage keys, only add baggage header if baggage not e…
Lms24 24412cb
add `createEventEnvelope` unit tests for baggage handling
Lms24 97790a0
add baggage in envelope header integration test
Lms24 7ff814c
fix linter errors
Lms24 263599b
simplify integration test
Lms24 8bcf2a6
fix integration test in CI (hopefully)
Lms24 77d03fc
extract baggage emptyness check to function
Lms24 5739252
extract event envelope header creation to function
Lms24 abe18b7
remove unused import
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { DsnComponents, Event } from '@sentry/types'; | ||
|
||
import { createEventEnvelope } from '../../src/envelope'; | ||
|
||
const testDsn: DsnComponents = { protocol: 'https', projectId: 'abc', host: 'testry.io' }; | ||
|
||
describe('createEventEnvelope', () => { | ||
describe('baggage header', () => { | ||
it("doesn't add baggage header if event is not a transaction", () => { | ||
const event: Event = {}; | ||
const envelopeHeaders = createEventEnvelope(event, testDsn)[0]; | ||
|
||
expect(envelopeHeaders).toBeDefined(); | ||
expect(envelopeHeaders.baggage).toBeUndefined(); | ||
}); | ||
|
||
it("doesn't add baggage header if no baggage data is available", () => { | ||
const event: Event = { | ||
type: 'transaction', | ||
}; | ||
const envelopeHeaders = createEventEnvelope(event, testDsn)[0]; | ||
|
||
expect(envelopeHeaders).toBeDefined(); | ||
expect(envelopeHeaders.baggage).toBeUndefined(); | ||
}); | ||
|
||
const testTable: Array<[string, Event, string]> = [ | ||
['adds only baggage item', { type: 'transaction', release: '1.0.0' }, 'sentry-release=1.0.0'], | ||
[ | ||
'adds two baggage items', | ||
{ type: 'transaction', release: '1.0.0', environment: 'prod' }, | ||
'sentry-environment=prod,sentry-release=1.0.0', | ||
], | ||
[ | ||
'adds all baggageitems', | ||
{ | ||
type: 'transaction', | ||
release: '1.0.0', | ||
environment: 'prod', | ||
user: { id: 'bob', segment: 'segmentA' }, | ||
transaction: 'TX', | ||
}, | ||
'sentry-environment=prod,sentry-release=1.0.0,sentry-transaction=TX,sentry-userid=bob,sentry-usersegment=segmentA', | ||
], | ||
]; | ||
it.each(testTable)('%s', (_: string, event, serializedBaggage) => { | ||
const envelopeHeaders = createEventEnvelope(event, testDsn)[0]; | ||
|
||
expect(envelopeHeaders).toBeDefined(); | ||
expect(envelopeHeaders.baggage).toBeDefined(); | ||
expect(envelopeHeaders.baggage).toEqual(serializedBaggage); | ||
}); | ||
}); | ||
}); |
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,16 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
import { Integrations } from '@sentry/tracing'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
integrations: [new Integrations.BrowserTracing({ tracingOrigins: [/.*/] })], | ||
environment: 'production', | ||
tracesSampleRate: 1, | ||
}); | ||
|
||
Sentry.configureScope(scope => { | ||
scope.setUser({ id: 'user123', segment: 'segmentB' }); | ||
scope.setTransactionName('testTransactionBaggage'); | ||
}); |
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,16 @@ | ||
import { expect } from '@playwright/test'; | ||
import { Event, EventEnvelopeHeaders } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { envelopeHeaderRequestParser, getFirstSentryEnvelopeRequest } from '../../../utils/helpers'; | ||
|
||
sentryTest('should send baggage data in transaction envelope header', async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
const envHeader = await getFirstSentryEnvelopeRequest<EventEnvelopeHeaders>(page, url, envelopeHeaderRequestParser); | ||
|
||
expect(envHeader.baggage).toBeDefined(); | ||
expect(envHeader.baggage).toEqual( | ||
'sentry-environment=production,sentry-transaction=testTransactionBaggage,sentry-userid=user123,sentry-usersegment=segmentB', | ||
); | ||
}); |
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
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.
This doesn't have anything to do with baggage but it's a no longer necessary check I stumbled across. See this conversation for context
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.
Btw, why not use
scope?.getSession()
notation?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.
Great question!
It's because we try to optimize our codebase around targeting
es6
. Optional Chaining is a newer JS feature,ES2020 - "ES11"
as per: https://gist.github.com/rajaramtt/7df3702a04c644b0b62c9a64f48f3dbf#64-optional-chaining. This means that it'll have to be down-compiled toes6
compatible code when we generate the final assets to distribute on npm and the CDN (this is for max browser + node version support).Something like so:
ends up getting down-compiled to:
See the babel demo.
which is way more bytes, which is bad for bundle size.
We made a decision as a result to not use any optional chaining in code that might be used in browser environments. See some examples on bundle wins we made here: https://github.com/getsentry/sentry-javascript/pulls?q=is%3Apr+optional+chaining+is%3Aclosed+milestone%3A%22Tree+shaking+%2F+Bundle+Size%22