File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
test/Sentry.Tests/Internals Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -83,8 +83,8 @@ public SentryEvent Process(SentryEvent @event)
8383 @event . Release ??= Release ;
8484 @event . Distribution ??= Distribution ;
8585
86- // if there's no exception with a stack trace, then get the current stack trace
87- if ( @event . Exception ? . StackTrace is null )
86+ // If there's no current thread on the event and there is no exception with a stack trace, get the current stack trace
87+ if ( @event . Exception ? . StackTrace is null && @event . SentryThreads ? . Any ( t => t . Current == true ) != true )
8888 {
8989 var stackTrace = @event . SentryExceptions ? . FirstOrDefault ( ) ? . Stacktrace
9090 ?? SentryStackTraceFactoryAccessor ( ) . Create ( ) ;
Original file line number Diff line number Diff line change @@ -491,6 +491,34 @@ public void Process_AttachStacktraceTrueAndExistentThreadInEvent_AddsNewThread()
491491 Assert . Equal ( "second" , evt . SentryThreads . Last ( ) . Name ) ;
492492 }
493493
494+ [ Fact ]
495+ public void Process_AttachStacktraceTrueAndCurrentThreadAlreadyExists_DoesNotAddAnotherThread ( )
496+ {
497+ var existingStackTrace = new SentryStackTrace ( ) ;
498+ _fixture . SentryOptions . AttachStacktrace = true ;
499+ var sut = _fixture . GetSut ( ) ;
500+
501+ var evt = new SentryEvent
502+ {
503+ SentryThreads = new [ ]
504+ {
505+ new SentryThread
506+ {
507+ Name = "existing-thread" ,
508+ Current = true ,
509+ Stacktrace = existingStackTrace
510+ }
511+ }
512+ } ;
513+ _ = sut . Process ( evt ) ;
514+
515+ Assert . Single ( evt . SentryThreads ) ;
516+ Assert . Equal ( "existing-thread" , evt . SentryThreads . First ( ) . Name ) ;
517+ Assert . True ( evt . SentryThreads . First ( ) . Current ) ;
518+ Assert . Same ( existingStackTrace , evt . SentryThreads . First ( ) . Stacktrace ) ;
519+ _ = _fixture . SentryStackTraceFactory . DidNotReceive ( ) . Create ( ) ;
520+ }
521+
494522 [ Fact ]
495523 public void Process_CultureInfoAndCultureInfoAreEqual_OnlyCultureInfoSet ( )
496524 {
You can’t perform that action at this time.
0 commit comments