-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref(tracing): Include transaction in DSC if transaction source is not an unparameterized URL #5392
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { TransactionSource } 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> = {}, | ||
transactionSource?: TransactionSource, | ||
) { | ||
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', | ||
metadata: { source: transactionSource }, | ||
}); | ||
|
||
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({}, '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', | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,19 +235,17 @@ export class Transaction extends SpanClass implements TransactionInterface { | |
? rate.toLocaleString('fullwide', { useGrouping: false, maximumFractionDigits: 16 }) | ||
: undefined; | ||
|
||
// For now we're not sending the transaction name and user_id due to PII concerns | ||
// commenting it out for now because we'll probably need it in the future | ||
|
||
const scope = hub.getScope(); | ||
const { /* id: user_id, */ segment: user_segment } = (scope && scope.getUser()) || {}; | ||
const { segment: user_segment } = (scope && scope.getUser()) || {}; | ||
|
||
const source = this.metadata.source; | ||
const transaction = source && source !== 'url' && source !== 'unknown' ? this.name : undefined; | ||
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. Was debating whether to include Can remove it though if we agree that we never set 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. For now I think this logic is fine. I would even argue that we should remove If we decide to remove 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. Yes that's a very good point. Thoughts about removing |
||
|
||
return createBaggage( | ||
dropUndefinedKeys({ | ||
environment, | ||
release, | ||
// transaction: this.name, | ||
// replace `someContidion` with whatever decision we come up with to guard PII in DSC | ||
// ...(someCondition && { user_id }), | ||
transaction, | ||
user_segment, | ||
public_key, | ||
trace_id: this.traceId, | ||
|
Uh oh!
There was an error while loading. Please reload this page.