11import { getCurrentHub , Hub } from '@sentry/hub' ;
2- import { DebugMeta , Event , Measurements , Transaction as TransactionInterface , TransactionContext } from '@sentry/types' ;
2+ import {
3+ Event ,
4+ Measurements ,
5+ Transaction as TransactionInterface ,
6+ TransactionContext ,
7+ TransactionMetadata ,
8+ } from '@sentry/types' ;
39import { dropUndefinedKeys , isInstanceOf , logger } from '@sentry/utils' ;
410
511import { Span as SpanClass , SpanRecorder } from './span' ;
6- import { computeTracestateValue } from './utils' ;
7-
8- type TransactionMetadata = Pick < DebugMeta , 'transactionSampling' | 'tracestate' > ;
912
1013/** JSDoc */
1114export class Transaction extends SpanClass implements TransactionInterface {
1215 public name : string ;
1316
14- public readonly tracestate : string ;
15-
16- private _metadata : TransactionMetadata = { } ;
17+ public metadata : TransactionMetadata ;
1718
1819 private _measurements : Measurements = { } ;
1920
@@ -42,9 +43,9 @@ export class Transaction extends SpanClass implements TransactionInterface {
4243
4344 this . _trimEnd = transactionContext . trimEnd ;
4445
45- // _getNewTracestate only returns undefined in the absence of a client or dsn, in which case it doesn't matter what
46- // the header values are - nothing can be sent anyway - so the third alternative here is just to make TS happy
47- this . tracestate = transactionContext . tracestate || this . _getNewTracestate ( ) || 'things are broken' ;
46+ this . metadata = transactionContext . metadata || { } ;
47+ this . metadata . tracestate = this . metadata . tracestate || { } ;
48+ this . metadata . tracestate . sentry = this . metadata . tracestate . sentry || this . _getNewTracestate ( this . _hub ) ;
4849
4950 // this is because transactions are also spans, and spans have a transaction pointer
5051 this . transaction = this ;
@@ -81,7 +82,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
8182 * @hidden
8283 */
8384 public setMetadata ( newMetadata : TransactionMetadata ) : void {
84- this . _metadata = { ...this . _metadata , ...newMetadata } ;
85+ this . metadata = { ...this . metadata , ...newMetadata } ;
8586 }
8687
8788 /**
@@ -118,8 +119,6 @@ export class Transaction extends SpanClass implements TransactionInterface {
118119 } ) . endTimestamp ;
119120 }
120121
121- this . _metadata . tracestate = this . tracestate ;
122-
123122 const transaction : Event = {
124123 contexts : {
125124 trace : this . getTraceContext ( ) ,
@@ -130,7 +129,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
130129 timestamp : this . endTimestamp ,
131130 transaction : this . name ,
132131 type : 'transaction' ,
133- debug_meta : this . _metadata ,
132+ debug_meta : this . metadata ,
134133 } ;
135134
136135 const hasMeasurements = Object . keys ( this . _measurements ) . length > 0 ;
@@ -170,27 +169,4 @@ export class Transaction extends SpanClass implements TransactionInterface {
170169
171170 return this ;
172171 }
173-
174- /**
175- * Create a new tracestate header value
176- *
177- * @returns The new tracestate value, or undefined if there's no client or no dsn
178- */
179- private _getNewTracestate ( ) : string | undefined {
180- const client = this . _hub . getClient ( ) ;
181- const dsn = client ?. getDsn ( ) ;
182-
183- if ( ! client || ! dsn ) {
184- return ;
185- }
186-
187- const { environment, release } = client . getOptions ( ) || { } ;
188-
189- // TODO - the only reason we need the non-null assertion on `dsn.publicKey` (below) is because `dsn.publicKey` has
190- // to be optional while we transition from `dsn.user` -> `dsn.publicKey`. Once `dsn.user` is removed, we can make
191- // `dsn.publicKey` required and remove the `!`.
192-
193- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
194- return computeTracestateValue ( { trace_id : this . traceId , environment, release, public_key : dsn . publicKey ! } ) ;
195- }
196172}
0 commit comments