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 55- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
66- [ react] feat: Add @sentry/react package (#2631 )
77- [ browser] Change XHR instrumentation order to handle ` onreadystatechange ` breadcrumbs correctly (#2643 )
8+ - [ apm] fix: Re-add TraceContext for all events (#2656 )
89
910## 5.16.1
1011
Original file line number Diff line number Diff line change @@ -436,6 +436,9 @@ export class Tracing implements Integration {
436436 ...transactionContext ,
437437 } ) as Transaction ;
438438
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+
439442 // The reason we do this here is because of cached responses
440443 // If we start and transaction without an activity it would never finish since there is no activity
441444 const id = Tracing . pushActivity ( 'idleTransactionStarted' ) ;
Original file line number Diff line number Diff line change @@ -377,6 +377,12 @@ export class Scope implements ScopeInterface {
377377 if ( this . _transaction ) {
378378 event . transaction = this . _transaction ;
379379 }
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+ }
380386
381387 this . _applyFingerprint ( event ) ;
382388
Original file line number Diff line number Diff line change @@ -265,6 +265,38 @@ describe('Scope', () => {
265265 } ) ;
266266 } ) ;
267267
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+
268300 test ( 'clear' , ( ) => {
269301 const scope = new Scope ( ) ;
270302 scope . setExtra ( 'a' , 2 ) ;
You can’t perform that action at this time.
0 commit comments