-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(tracing): Include transaction in DSC if transaction source is not…
… an unparameterized URL (#5392) This patch re-introduces the `transaction` field in the Dynamic Sampling Context (DSC). However, its presence is now determined by the [transaction source](https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations) which was introduced in #5367. As of this we we add the `transaction` field back, if the source indicates that the transaction name is not an unparameterized URL (meaning, the source is set and it is not `url`). Additionally, the PR (once again) adjusts our unit and integration tests to reflect this change. Repurposed some DSC<=>`sendDefaultPii` tests that we previously skipped to now cover the transaction<=>transaction source dependence. Did some cleanup of commented out old code and explanations that no longer apply. Remove he `'unknown'` field from the `TransactionSource` type because it is only used by Relay and SDKs shouldn't set it.
- Loading branch information
Showing
16 changed files
with
71 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ import * as sentryCore from '@sentry/core'; | |
import * as hubModule from '@sentry/hub'; | ||
import { Hub } from '@sentry/hub'; | ||
import { addExtensionMethods, Span, TRACEPARENT_REGEXP, Transaction } from '@sentry/tracing'; | ||
import { TransactionContext } from '@sentry/types'; | ||
import { parseSemver } from '@sentry/utils'; | ||
import * as http from 'http'; | ||
import * as https from 'https'; | ||
|
@@ -17,7 +18,10 @@ import { getDefaultNodeClientOptions } from '../helper/node-client-options'; | |
const NODE_VERSION = parseSemver(process.versions.node); | ||
|
||
describe('tracing', () => { | ||
function createTransactionOnScope(customOptions: Partial<NodeClientOptions> = {}) { | ||
function createTransactionOnScope( | ||
customOptions: Partial<NodeClientOptions> = {}, | ||
customContext?: Partial<TransactionContext>, | ||
) { | ||
const options = getDefaultNodeClientOptions({ | ||
dsn: 'https://[email protected]/12312012', | ||
tracesSampleRate: 1.0, | ||
|
@@ -44,7 +48,9 @@ describe('tracing', () => { | |
const transaction = hub.startTransaction({ | ||
name: 'dogpark', | ||
traceId: '12312012123120121231201212312012', | ||
...customContext, | ||
}); | ||
|
||
hub.getScope()?.setSpan(transaction); | ||
|
||
return transaction; | ||
|
@@ -112,8 +118,6 @@ describe('tracing', () => { | |
expect(baggageHeader).toBeDefined(); | ||
expect(typeof baggageHeader).toEqual('string'); | ||
expect(baggageHeader).toEqual( | ||
// Commented out as long as transaction and user_id are not part of DSC | ||
// 'sentry-environment=production,sentry-release=1.0.0,sentry-transaction=dogpark,sentry-user_id=uid123,' + | ||
'sentry-environment=production,sentry-release=1.0.0,' + | ||
'sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,' + | ||
'sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1', | ||
|
@@ -131,31 +135,24 @@ describe('tracing', () => { | |
expect(baggageHeader).toBeDefined(); | ||
expect(typeof baggageHeader).toEqual('string'); | ||
expect(baggageHeader).toEqual( | ||
// Commented out as long as transaction and user_id are not part of DSC | ||
// 'dog=great,sentry-environment=production,sentry-release=1.0.0,sentry-transaction=dogpark,' + | ||
// 'sentry-user_id=uid123,sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,' + | ||
// 'sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1', | ||
'dog=great,sentry-environment=production,sentry-release=1.0.0,' + | ||
'sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,' + | ||
'sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1', | ||
); | ||
}); | ||
|
||
// TODO: Skipping this test because right now we're rethinking the mechanism for including such data | ||
it.skip('does not add the user_id to the baggage header if <optionTBA> is set to false', async () => { | ||
it('adds the transaction name to the the baggage header if a valid transaction source is set', async () => { | ||
nock('http://dogs.are.great').get('/').reply(200); | ||
|
||
createTransactionOnScope(); | ||
createTransactionOnScope({}, { metadata: { source: 'custom' } }); | ||
|
||
const request = http.get({ host: 'http://dogs.are.great/', headers: { baggage: 'dog=great' } }); | ||
const baggageHeader = request.getHeader('baggage') as string; | ||
|
||
expect(baggageHeader).toBeDefined(); | ||
expect(typeof baggageHeader).toEqual('string'); | ||
expect(baggageHeader).toEqual( | ||
// Commented out as long as transaction and user_id are not part of DSC | ||
// 'dog=great,sentry-environment=production,sentry-release=1.0.0,sentry-transaction=dogpark,' + | ||
'dog=great,sentry-environment=production,sentry-release=1.0.0,' + | ||
'dog=great,sentry-environment=production,sentry-release=1.0.0,sentry-transaction=dogpark,' + | ||
'sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,' + | ||
'sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1', | ||
); | ||
|
This file contains 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 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 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 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 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