Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
ba466c986ac6a3a2ee5492572ff4ba148342a7b8307cc1d39File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
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.
| ||
| const transaction: Event = { | ||
| contexts: { | ||
| trace: this.getTraceContext(), | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -145,10 +145,11 @@ export function secToMs(time: number): number { | ||
| export { stripUrlQueryAndFragment } from '@sentry/utils'; | ||
| type SentryTracestateData = { | ||
| traceId: string; | ||
| trace_id: string; | ||
| environment: string | undefined | null; | ||
| release: string | undefined | null; | ||
| publicKey: string; | ||
| public_key: string; | ||
| user: { id: string | undefined | null; segment: string | undefined | null }; | ||
RaduW marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }; | ||
| /** | ||
| @@ -159,9 +160,11 @@ type SentryTracestateData = { | ||
| */ | ||
| export function computeTracestateValue(data: SentryTracestateData): string { | ||
| // `JSON.stringify` will drop keys with undefined values, but not ones with null values, so this prevents | ||
| // `environment` and `release` from being dropped if they haven't been set by `Sentry.init` | ||
| // these values from being dropped if they haven't been set by `Sentry.init` | ||
| data.environment = data.environment || null; | ||
| data.release = data.release || null; | ||
| data.user.id = data.user.id || null; | ||
| data.user.segment = data.user.segment || null; | ||
| // See https://www.w3.org/TR/trace-context/#tracestate-header-field-values | ||
| // The spec for tracestate header values calls for a string of the form | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
What's going on here ? Doesn't seem to be related to the PR.
Uh oh!
There was an error while loading. Please reload this page.
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.
It actually is, though. The change here is from importing the type to importing the class. Later on in the file I'm calling
Hub.getScope(), a method which exists on the class but isn't in the type, so if I don't make this change, it won't compile. The alternative to doing this is to add the method to the type, which I'm happy to do instead if you think that's better.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.
Understood, it's probably me (I'm not so familiar with this code) but it further raises the question why we don't have
getScopein the interface ( since we do havepushScope,popScope,withScope).Anyway, not the right place to discuss general architecture of the API.