File tree 5 files changed +81
-3
lines changed
5 files changed +81
-3
lines changed Original file line number Diff line number Diff line change @@ -75,8 +75,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
75
75
}
76
76
77
77
/**
78
- * Set metadata for this transaction.
79
- * @hidden
78
+ * @inheritDoc
80
79
*/
81
80
public setMetadata ( newMetadata : TransactionMetadata ) : void {
82
81
this . metadata = { ...this . metadata , ...newMetadata } ;
@@ -122,6 +121,8 @@ export class Transaction extends SpanClass implements TransactionInterface {
122
121
} ) . endTimestamp ;
123
122
}
124
123
124
+ const metadata = this . metadata ;
125
+
125
126
const transaction : Event = {
126
127
contexts : {
127
128
trace : this . getTraceContext ( ) ,
@@ -133,9 +134,14 @@ export class Transaction extends SpanClass implements TransactionInterface {
133
134
transaction : this . name ,
134
135
type : 'transaction' ,
135
136
sdkProcessingMetadata : {
136
- ...this . metadata ,
137
+ ...metadata ,
137
138
baggage : this . getBaggage ( ) ,
138
139
} ,
140
+ ...( metadata . source && {
141
+ transaction_info : {
142
+ source : metadata . source ,
143
+ } ,
144
+ } ) ,
139
145
} ;
140
146
141
147
const hasMeasurements = Object . keys ( this . _measurements ) . length > 0 ;
Original file line number Diff line number Diff line change @@ -474,4 +474,42 @@ describe('Span', () => {
474
474
expect ( baggage && getThirdPartyBaggage ( baggage ) ) . toStrictEqual ( '' ) ;
475
475
} ) ;
476
476
} ) ;
477
+
478
+ describe ( 'Transaction source' , ( ) => {
479
+ test ( 'is not included by default' , ( ) => {
480
+ const spy = jest . spyOn ( hub as any , 'captureEvent' ) as any ;
481
+ const transaction = hub . startTransaction ( { name : 'test' , sampled : true } ) ;
482
+ expect ( spy ) . toHaveBeenCalledTimes ( 0 ) ;
483
+
484
+ transaction . finish ( ) ;
485
+
486
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
487
+ expect ( spy ) . toHaveBeenLastCalledWith (
488
+ expect . not . objectContaining ( {
489
+ transaction_info : {
490
+ source : expect . any ( String ) ,
491
+ } ,
492
+ } ) ,
493
+ ) ;
494
+ } ) ;
495
+
496
+ test ( 'is included when transaction metadata is set' , ( ) => {
497
+ const spy = jest . spyOn ( hub as any , 'captureEvent' ) as any ;
498
+ const transaction = hub . startTransaction ( { name : 'test' , sampled : true } ) ;
499
+ transaction . setMetadata ( {
500
+ source : 'url' ,
501
+ } ) ;
502
+ expect ( spy ) . toHaveBeenCalledTimes ( 0 ) ;
503
+
504
+ transaction . finish ( ) ;
505
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
506
+ expect ( spy ) . toHaveBeenLastCalledWith (
507
+ expect . objectContaining ( {
508
+ transaction_info : {
509
+ source : 'url' ,
510
+ } ,
511
+ } ) ,
512
+ ) ;
513
+ } ) ;
514
+ } ) ;
477
515
} ) ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { CaptureContext } from './scope';
11
11
import { SdkInfo } from './sdkinfo' ;
12
12
import { Severity , SeverityLevel } from './severity' ;
13
13
import { Span } from './span' ;
14
+ import { TransactionSource } from './transaction' ;
14
15
import { User } from './user' ;
15
16
16
17
/** JSDoc */
@@ -46,6 +47,9 @@ export interface Event {
46
47
debug_meta ?: DebugMeta ;
47
48
// A place to stash data which is needed at some point in the SDK's event processing pipeline but which shouldn't get sent to Sentry
48
49
sdkProcessingMetadata ?: { [ key : string ] : any } ;
50
+ transaction_info ?: {
51
+ source : TransactionSource ;
52
+ } ;
49
53
}
50
54
51
55
/** JSDoc */
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ export type {
71
71
TransactionContext ,
72
72
TransactionMetadata ,
73
73
TransactionSamplingMethod ,
74
+ TransactionSource ,
74
75
} from './transaction' ;
75
76
export type {
76
77
DurationUnit ,
Original file line number Diff line number Diff line change @@ -89,6 +89,12 @@ export interface Transaction extends TransactionContext, Span {
89
89
/** Updates the current transaction with a new `TransactionContext` */
90
90
updateWithContext ( transactionContext : TransactionContext ) : this;
91
91
92
+ /**
93
+ * Set metadata for this transaction.
94
+ * @hidden
95
+ */
96
+ setMetadata ( newMetadata : TransactionMetadata ) : void ;
97
+
92
98
/** return the baggage for dynamic sampling and trace propagation */
93
99
getBaggage ( ) : Baggage ;
94
100
}
@@ -138,4 +144,27 @@ export interface TransactionMetadata {
138
144
139
145
/** For transactions tracing server-side request handling, the path of the request being tracked. */
140
146
requestPath ?: string ;
147
+
148
+ /** Information on how a transaction name was generated. */
149
+ source ?: TransactionSource ;
141
150
}
151
+
152
+ /**
153
+ * Contains information about how the name of the transaction was determined. This will be used by the server to decide
154
+ * whether or not to scrub identifiers from the transaction name, or replace the entire name with a placeholder.
155
+ */
156
+ export type TransactionSource =
157
+ /** User-defined name */
158
+ | 'custom'
159
+ /** Raw URL, potentially containing identifiers */
160
+ | 'url'
161
+ /** Parametrized URL / route */
162
+ | 'route'
163
+ /** Name of the view handling the request */
164
+ | 'view'
165
+ /** This is the default value set by Relay for legacy SDKs. */
166
+ | 'unknown'
167
+ /** Named after a software component, such as a function or class name. */
168
+ | 'component'
169
+ /** Name of a background task (e.g. a Celery task) */
170
+ | 'task' ;
You can’t perform that action at this time.
0 commit comments