-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(tracing): Add user data to tracestate header
#3343
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
ba466c9
86ac6a3
a2ee549
2572ff4
ba14834
2a7b830
7cc1d39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,11 +40,6 @@ export class Transaction extends SpanClass implements TransactionInterface { | |
| this._trimEnd = transactionContext.trimEnd; | ||
| this._hub = hub || getCurrentHub(); | ||
|
|
||
| // create a new sentry tracestate value if we didn't inherit one | ||
| if (!this.metadata.tracestate?.sentry) { | ||
| this.metadata.tracestate = { ...this.metadata.tracestate, sentry: this._getNewTracestate(this._hub) }; | ||
| } | ||
|
|
||
| // this is because transactions are also spans, and spans have a transaction pointer | ||
| this.transaction = this; | ||
| } | ||
|
|
@@ -117,6 +112,11 @@ export class Transaction extends SpanClass implements TransactionInterface { | |
| }).endTimestamp; | ||
| } | ||
|
|
||
| // ensure that we have a tracestate to attach to the envelope header | ||
| if (!this.metadata.tracestate?.sentry) { | ||
| this.metadata.tracestate = { ...this.metadata.tracestate, sentry: this._getNewTracestate() }; | ||
| } | ||
|
|
||
|
Comment on lines
+115
to
+119
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. Nit: I saw that this is not a new thing (it predates this PR) but why do we push tracestate in debug_meta ? If we didn't _getNewTracestate() could become private.
Member
Author
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.
Because it needs to get through to here somehow, and putting it in *If you look a few lines into the linked function, you'll see that in fact it gets pulled out of the eventual event payload. Same with the sampling data.
Is there any advantage to that over it being protected (which it is currently)? 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. Again it was just a nit, but in general I find |
||
| const transaction: Event = { | ||
| contexts: { | ||
| trace: this.getTraceContext(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| /* eslint-disable @typescript-eslint/unbound-method */ | ||
| import { BrowserClient, init as initSDK } from '@sentry/browser'; | ||
| import { getCurrentHub, Hub } from '@sentry/hub'; | ||
| import { BrowserClient } from '@sentry/browser'; | ||
| import { Hub } from '@sentry/hub'; | ||
| import * as hubModule from '@sentry/hub'; | ||
| import { TransactionSamplingMethod } from '@sentry/types'; | ||
| import * as utilsModule from '@sentry/utils'; // for mocking | ||
|
|
@@ -9,7 +9,7 @@ import { logger } from '@sentry/utils'; | |
| import { BrowserTracing } from '../src/browser/browsertracing'; | ||
| import { addExtensionMethods } from '../src/hubextensions'; | ||
| import { Transaction } from '../src/transaction'; | ||
| import { computeTracestateValue, extractSentrytraceData, SENTRY_TRACE_REGEX } from '../src/utils'; | ||
| import { extractSentrytraceData, SENTRY_TRACE_REGEX } from '../src/utils'; | ||
| import { addDOMPropertiesToGlobal, getSymbolObjectKeyByName, testOnlyIfNodeVersionAtLeast } from './testutils'; | ||
|
|
||
| addExtensionMethods(); | ||
|
|
@@ -50,68 +50,6 @@ describe('Hub', () => { | |
|
|
||
| expect(transaction).toEqual(expect.objectContaining(transactionContext)); | ||
| }); | ||
|
|
||
| it('creates a new tracestate value if no tracestate data in transaction context', () => { | ||
| const transaction = hub.startTransaction({ name: 'FETCH /ball' }); | ||
|
|
||
| const b64Value = computeTracestateValue({ | ||
| traceId: transaction.traceId, | ||
| environment: 'dogpark', | ||
| release: 'off.leash.trail', | ||
| publicKey: 'dogsarebadatkeepingsecrets', | ||
| }); | ||
|
|
||
| expect(transaction.metadata?.tracestate?.sentry).toEqual(`sentry=${b64Value}`); | ||
| }); | ||
|
|
||
| it('creates a new tracestate value if tracestate data in transaction context only contains third party data', () => { | ||
| const transactionContext = { | ||
| name: 'FETCH /ball', | ||
| traceId: '12312012123120121231201212312012', | ||
| parentSpanId: '1121201211212012', | ||
| metadata: { tracestate: { thirdparty: 'maisey=silly;charlie=goofy' } }, | ||
| }; | ||
|
|
||
| const transaction = hub.startTransaction(transactionContext); | ||
|
|
||
| const b64Value = computeTracestateValue({ | ||
| traceId: transaction.traceId, | ||
| environment: 'dogpark', | ||
| release: 'off.leash.trail', | ||
| publicKey: 'dogsarebadatkeepingsecrets', | ||
| }); | ||
|
|
||
| expect(transaction).toEqual( | ||
| expect.objectContaining({ | ||
| metadata: { | ||
| tracestate: { | ||
| // a new value for `sentry` is created | ||
| sentry: `sentry=${b64Value}`, | ||
| // the third-party value isn't lost | ||
| thirdparty: 'maisey=silly;charlie=goofy', | ||
| }, | ||
| }, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('uses default environment if none given', () => { | ||
| const release = 'off.leash.park'; | ||
| initSDK({ | ||
| dsn: 'https://[email protected]/12312012', | ||
| release, | ||
| }); | ||
| const transaction = getCurrentHub().startTransaction({ name: 'FETCH /ball' }); | ||
|
|
||
| const b64Value = computeTracestateValue({ | ||
| traceId: transaction.traceId, | ||
| environment: 'production', | ||
| release, | ||
| publicKey: 'dogsarebadatkeepingsecrets', | ||
| }); | ||
|
|
||
| expect(transaction.metadata?.tracestate?.sentry).toEqual(`sentry=${b64Value}`); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getTransaction()', () => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.