Skip to content

Commit 9af1886

Browse files
authored
ref(tracing): Make metadata property on Transaction class public (#3557)
1 parent 9dffb92 commit 9af1886

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

packages/tracing/src/transaction.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { getCurrentHub, Hub } from '@sentry/hub';
2-
import { 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';
39
import { dropUndefinedKeys, isInstanceOf, logger } from '@sentry/utils';
410

511
import { Span as SpanClass, SpanRecorder } from './span';
612

7-
interface TransactionMetadata {
8-
transactionSampling?: { [key: string]: string | number };
9-
}
10-
1113
/** JSDoc */
1214
export class Transaction extends SpanClass implements TransactionInterface {
1315
public name: string;
1416

15-
private _metadata: TransactionMetadata = {};
17+
public metadata: TransactionMetadata;
1618

1719
private _measurements: Measurements = {};
1820

@@ -39,6 +41,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
3941

4042
this.name = transactionContext.name || '';
4143

44+
this.metadata = transactionContext.metadata || {};
4245
this._trimEnd = transactionContext.trimEnd;
4346

4447
// this is because transactions are also spans, and spans have a transaction pointer
@@ -76,7 +79,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
7679
* @hidden
7780
*/
7881
public setMetadata(newMetadata: TransactionMetadata): void {
79-
this._metadata = { ...this._metadata, ...newMetadata };
82+
this.metadata = { ...this.metadata, ...newMetadata };
8083
}
8184

8285
/**
@@ -123,7 +126,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
123126
timestamp: this.endTimestamp,
124127
transaction: this.name,
125128
type: 'transaction',
126-
debug_meta: this._metadata,
129+
debug_meta: this.metadata,
127130
};
128131

129132
const hasMeasurements = Object.keys(this._measurements).length > 0;

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export {
4343
TraceparentData,
4444
Transaction,
4545
TransactionContext,
46+
TransactionMetadata,
4647
TransactionSamplingMethod,
4748
} from './transaction';
4849
export { Thread } from './thread';

packages/types/src/transaction.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export interface TransactionContext extends SpanContext {
2222
* If this transaction has a parent, the parent's sampling decision
2323
*/
2424
parentSampled?: boolean;
25+
26+
/**
27+
* Metadata associated with the transaction, for internal SDK use.
28+
*/
29+
metadata?: TransactionMetadata;
2530
}
2631

2732
/**
@@ -58,6 +63,11 @@ export interface Transaction extends TransactionContext, Span {
5863
*/
5964
data: { [key: string]: any };
6065

66+
/**
67+
* Metadata about the transaction
68+
*/
69+
metadata: TransactionMetadata;
70+
6171
/**
6272
* Set the name of the transaction
6373
*/
@@ -113,3 +123,13 @@ export enum TransactionSamplingMethod {
113123
Rate = 'client_rate',
114124
Inheritance = 'inheritance',
115125
}
126+
127+
export interface TransactionMetadata {
128+
transactionSampling?: { rate?: number; method?: string };
129+
130+
/** The two halves (sentry and third-party) of a transaction's tracestate header, used for dynamic sampling */
131+
tracestate?: {
132+
sentry?: string;
133+
thirdparty?: string;
134+
};
135+
}

0 commit comments

Comments
 (0)