File tree Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 5
5
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
6
6
- [ react] feat: Add @sentry/react package (#2631 )
7
7
- [ browser] Change XHR instrumentation order to handle ` onreadystatechange ` breadcrumbs correctly (#2643 )
8
+ - [ apm] fix: Re-add TraceContext for all events (#2656 )
8
9
9
10
## 5.16.1
10
11
Original file line number Diff line number Diff line change @@ -436,6 +436,9 @@ export class Tracing implements Integration {
436
436
...transactionContext ,
437
437
} ) as Transaction ;
438
438
439
+ // We set the transaction here on the scope so error events pick up the trace context and attach it to the error
440
+ hub . configureScope ( scope => scope . setSpan ( Tracing . _activeTransaction ) ) ;
441
+
439
442
// The reason we do this here is because of cached responses
440
443
// If we start and transaction without an activity it would never finish since there is no activity
441
444
const id = Tracing . pushActivity ( 'idleTransactionStarted' ) ;
Original file line number Diff line number Diff line change @@ -377,6 +377,12 @@ export class Scope implements ScopeInterface {
377
377
if ( this . _transaction ) {
378
378
event . transaction = this . _transaction ;
379
379
}
380
+ // We want to set the trace context for normal events only if there isn't already
381
+ // a trace context on the event. There is a product feature in place where we link
382
+ // errors with transaction and it relys on that.
383
+ if ( this . _span ) {
384
+ event . contexts = { trace : this . _span . getTraceContext ( ) , ...event . contexts } ;
385
+ }
380
386
381
387
this . _applyFingerprint ( event ) ;
382
388
Original file line number Diff line number Diff line change @@ -265,6 +265,38 @@ describe('Scope', () => {
265
265
} ) ;
266
266
} ) ;
267
267
268
+ test ( 'applyToEvent trace context' , async ( ) => {
269
+ expect . assertions ( 1 ) ;
270
+ const scope = new Scope ( ) ;
271
+ const span = {
272
+ fake : 'span' ,
273
+ getTraceContext : ( ) => ( { a : 'b' } ) ,
274
+ } as any ;
275
+ scope . setSpan ( span ) ;
276
+ const event : Event = { } ;
277
+ return scope . applyToEvent ( event ) . then ( processedEvent => {
278
+ expect ( ( processedEvent ! . contexts ! . trace as any ) . a ) . toEqual ( 'b' ) ;
279
+ } ) ;
280
+ } ) ;
281
+
282
+ test ( 'applyToEvent existing trace context in event should be stronger' , async ( ) => {
283
+ expect . assertions ( 1 ) ;
284
+ const scope = new Scope ( ) ;
285
+ const span = {
286
+ fake : 'span' ,
287
+ getTraceContext : ( ) => ( { a : 'b' } ) ,
288
+ } as any ;
289
+ scope . setSpan ( span ) ;
290
+ const event : Event = {
291
+ contexts : {
292
+ trace : { a : 'c' } ,
293
+ } ,
294
+ } ;
295
+ return scope . applyToEvent ( event ) . then ( processedEvent => {
296
+ expect ( ( processedEvent ! . contexts ! . trace as any ) . a ) . toEqual ( 'c' ) ;
297
+ } ) ;
298
+ } ) ;
299
+
268
300
test ( 'clear' , ( ) => {
269
301
const scope = new Scope ( ) ;
270
302
scope . setExtra ( 'a' , 2 ) ;
38A8
code>
You can’t perform that action at this time.
0 commit comments