-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref(tracing): Ignore third party baggage entries from incoming requests #5319
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
7 commits
Select commit
Hold shift + click to select a range
7a1bc93
ignore 3rd party entries baggage in incoming requests
Lms24 9359d3f
fix (integration) tests
Lms24 e9d1c2a
remove isBaggageEmpty helper function
Lms24 55e0243
add node integration tests to test correct merging of 3rd party bagga…
Lms24 2409063
re-add accidentally deleted yarn script
Lms24 1dc038f
fix serverless unit tests
Lms24 795dd25
change mutability condition in parseBaggageSetMutability
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
42 changes: 42 additions & 0 deletions
42
...ion-tests/suites/express/sentry-trace/baggage-other-vendors-with-sentry-entries/server.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,42 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import * as Tracing from '@sentry/tracing'; | ||
| import cors from 'cors'; | ||
| import express from 'express'; | ||
| import http from 'http'; | ||
|
|
||
| const app = express(); | ||
|
|
||
| export type TestAPIResponse = { test_data: { host: string; 'sentry-trace': string; baggage: string } }; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://[email protected]/1337', | ||
| release: '1.0', | ||
| environment: 'prod', | ||
| integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })], | ||
| tracesSampleRate: 1.0, | ||
| }); | ||
|
|
||
| app.use(Sentry.Handlers.requestHandler()); | ||
| app.use(Sentry.Handlers.tracingHandler()); | ||
|
|
||
| app.use(cors()); | ||
|
|
||
| app.get('/test/express', (_req, res) => { | ||
| // simulate setting a "third party" baggage header which the Sentry SDK should merge with Sentry DSC entries | ||
| const headers = http | ||
| .get({ | ||
| hostname: 'somewhere.not.sentry', | ||
| headers: { | ||
| baggage: | ||
| 'other=vendor,foo=bar,third=party,sentry-release=9.9.9,sentry-environment=staging,sentry-sample_rate=0.54,last=item', | ||
| }, | ||
| }) | ||
| .getHeaders(); | ||
|
|
||
| // Responding with the headers outgoing request headers back to the assertions. | ||
| res.send({ test_data: headers }); | ||
| }); | ||
|
|
||
| app.use(Sentry.Handlers.errorHandler()); | ||
|
|
||
| export default app; |
38 changes: 38 additions & 0 deletions
38
...ation-tests/suites/express/sentry-trace/baggage-other-vendors-with-sentry-entries/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,38 @@ | ||
| import * as path from 'path'; | ||
|
|
||
| import { getAPIResponse, runServer } from '../../../../utils/index'; | ||
| import { TestAPIResponse } from '../server'; | ||
|
|
||
| test('should ignore sentry-values in `baggage` header of a third party vendor and overwrite them with incoming DSC', async () => { | ||
| const url = await runServer(__dirname, `${path.resolve(__dirname, '.')}/server.ts`); | ||
|
|
||
| const response = (await getAPIResponse(new URL(`${url}/express`), { | ||
| 'sentry-trace': '', | ||
| baggage: 'sentry-release=2.1.0,sentry-environment=myEnv', | ||
| })) as TestAPIResponse; | ||
|
|
||
| expect(response).toBeDefined(); | ||
| expect(response).toMatchObject({ | ||
| test_data: { | ||
| host: 'somewhere.not.sentry', | ||
| baggage: 'other=vendor,foo=bar,third=party,last=item,sentry-release=2.1.0,sentry-environment=myEnv', | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| test('should ignore sentry-values in `baggage` header of a third party vendor and overwrite them with new DSC', async () => { | ||
| const url = await runServer(__dirname, `${path.resolve(__dirname, '.')}/server.ts`); | ||
|
|
||
| const response = (await getAPIResponse(new URL(`${url}/express`), {})) as TestAPIResponse; | ||
|
|
||
| expect(response).toBeDefined(); | ||
| expect(response).toMatchObject({ | ||
| test_data: { | ||
| host: 'somewhere.not.sentry', | ||
| baggage: expect.stringContaining( | ||
| 'other=vendor,foo=bar,third=party,last=item,sentry-environment=prod,sentry-release=1.0,' + | ||
| 'sentry-transaction=GET%20%2Ftest%2Fexpress,sentry-public_key=public', | ||
| ), | ||
| }, | ||
| }); | ||
| }); |
36 changes: 36 additions & 0 deletions
36
packages/node-integration-tests/suites/express/sentry-trace/baggage-other-vendors/server.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,36 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import * as Tracing from '@sentry/tracing'; | ||
| import cors from 'cors'; | ||
| import express from 'express'; | ||
| import http from 'http'; | ||
|
|
||
| const app = express(); | ||
|
|
||
| export type TestAPIResponse = { test_data: { host: string; 'sentry-trace': string; baggage: string } }; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://[email protected]/1337', | ||
| release: '1.0', | ||
| environment: 'prod', | ||
| integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })], | ||
| tracesSampleRate: 1.0, | ||
| }); | ||
|
|
||
| app.use(Sentry.Handlers.requestHandler()); | ||
| app.use(Sentry.Handlers.tracingHandler()); | ||
|
|
||
| app.use(cors()); | ||
|
|
||
| app.get('/test/express', (_req, res) => { | ||
| // simulate setting a "third party" baggage header which the Sentry SDK should merge with Sentry DSC entries | ||
| const headers = http | ||
| .get({ hostname: 'somewhere.not.sentry', headers: { baggage: 'other=vendor,foo=bar,third=party' } }) | ||
| .getHeaders(); | ||
|
|
||
| // Responding with the headers outgoing request headers back to the assertions. | ||
| res.send({ test_data: headers }); | ||
| }); | ||
|
|
||
| app.use(Sentry.Handlers.errorHandler()); | ||
|
|
||
| export default app; |
21 changes: 21 additions & 0 deletions
21
packages/node-integration-tests/suites/express/sentry-trace/baggage-other-vendors/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,21 @@ | ||
| import * as path from 'path'; | ||
|
|
||
| import { getAPIResponse, runServer } from '../../../../utils/index'; | ||
| import { TestAPIResponse } from '../server'; | ||
|
|
||
| test('should merge `baggage` header of a third party vendor with the Sentry DSC baggage items', async () => { | ||
| const url = await runServer(__dirname, `${path.resolve(__dirname, '.')}/server.ts`); | ||
|
|
||
| const response = (await getAPIResponse(new URL(`${url}/express`), { | ||
| 'sentry-trace': '', | ||
| baggage: 'sentry-release=2.0.0,sentry-environment=myEnv', | ||
| })) as TestAPIResponse; | ||
|
|
||
| expect(response).toBeDefined(); | ||
| expect(response).toMatchObject({ | ||
| test_data: { | ||
| host: 'somewhere.not.sentry', | ||
| baggage: 'other=vendor,foo=bar,third=party,sentry-release=2.0.0,sentry-environment=myEnv', | ||
| }, | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,15 +8,7 @@ import { | |
| TransactionContext, | ||
| TransactionMetadata, | ||
| } from '@sentry/types'; | ||
| import { | ||
| createBaggage, | ||
| dropUndefinedKeys, | ||
| getSentryBaggageItems, | ||
| getThirdPartyBaggage, | ||
| isBaggageMutable, | ||
| isSentryBaggageEmpty, | ||
| logger, | ||
| } from '@sentry/utils'; | ||
| import { createBaggage, dropUndefinedKeys, getSentryBaggageItems, isBaggageMutable, logger } from '@sentry/utils'; | ||
|
|
||
| import { Span as SpanClass, SpanRecorder } from './span'; | ||
|
|
||
|
|
@@ -197,17 +189,13 @@ export class Transaction extends SpanClass implements TransactionInterface { | |
|
|
||
| // Only add Sentry baggage items to baggage, if baggage does not exist yet or it is still | ||
| // empty and mutable | ||
| // TODO: we might want to ditch the isSentryBaggageEmpty condition because it prevents | ||
| // custom sentry-values in DSC (added by users in the future) | ||
| const finalBaggage = | ||
| !existingBaggage || (isBaggageMutable(existingBaggage) && isSentryBaggageEmpty(existingBaggage)) | ||
| !existingBaggage || isBaggageMutable(existingBaggage) | ||
| ? this._populateBaggageWithSentryValues(existingBaggage) | ||
| : existingBaggage; | ||
|
|
||
| // In case, we poulated the DSC, we have update the stored one on the transaction. | ||
| if (existingBaggage !== finalBaggage) { | ||
| this.metadata.baggage = finalBaggage; | ||
| } | ||
| // Update the baggage stored on the transaction. | ||
| this.metadata.baggage = finalBaggage; | ||
|
Comment on lines
-207
to
+198
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. IMO, it's simpler this way and saves us some bytes |
||
|
|
||
| return finalBaggage; | ||
| } | ||
|
|
@@ -255,7 +243,7 @@ export class Transaction extends SpanClass implements TransactionInterface { | |
| sample_rate, | ||
| ...getSentryBaggageItems(baggage), // keep user-added values | ||
| } as BaggageObj), | ||
| getThirdPartyBaggage(baggage), // TODO: remove once we ignore 3rd party baggage | ||
| '', | ||
| false, // set baggage immutable | ||
| ); | ||
| } | ||
|
|
||
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.
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.
Just to cut down a few bytes....