44using System . Linq ;
55using System . Reflection ;
66using System . Text . RegularExpressions ;
7- using Sentry . Extensibility ;
87using Sentry . Protocol ;
98
10- namespace Sentry . Internal
9+ namespace Sentry . Extensibility
1110{
12- internal class SentryStackTraceFactory : ISentryStackTraceFactory
11+ public class SentryStackTraceFactory : ISentryStackTraceFactory
1312 {
1413 private readonly SentryOptions _options ;
1514
@@ -27,13 +26,12 @@ public SentryStackTrace Create(Exception exception = null)
2726
2827 _options . DiagnosticLogger ? . LogDebug ( "Creating SentryStackTrace. isCurrentStackTrace: {0}." , isCurrentStackTrace ) ;
2928
30- var stackTrace = isCurrentStackTrace
31- ? new StackTrace ( true )
32- : new StackTrace ( exception , true ) ;
33-
34- return Create ( stackTrace , isCurrentStackTrace ) ;
29+ return Create ( CreateStackTrace ( exception ) , isCurrentStackTrace ) ;
3530 }
3631
32+ protected virtual StackTrace CreateStackTrace ( Exception exception ) =>
33+ exception == null ? new StackTrace ( true ) : new StackTrace ( exception , true ) ;
34+
3735 internal SentryStackTrace Create ( StackTrace stackTrace , bool isCurrentStackTrace )
3836 {
3937 var frames = CreateFrames ( stackTrace , isCurrentStackTrace )
@@ -77,19 +75,23 @@ internal IEnumerable<SentryStackFrame> CreateFrames(StackTrace stackTrace, bool
7775
7876 firstFrames = false ;
7977
80- var frame = CreateFrame ( stackFrame ) ;
78+ var frame = CreateFrame ( stackFrame , isCurrentStackTrace ) ;
8179 if ( frame != null )
8280 {
8381 yield return frame ;
8482 }
8583 }
8684 }
8785
88- internal SentryStackFrame CreateFrame ( StackFrame stackFrame )
86+ internal SentryStackFrame CreateFrame ( StackFrame stackFrame ) => InternalCreateFrame ( stackFrame , true ) ;
87+
88+ protected virtual SentryStackFrame CreateFrame ( StackFrame stackFrame , bool isCurrentStackTrace ) => InternalCreateFrame ( stackFrame , true ) ;
89+
90+ protected SentryStackFrame InternalCreateFrame ( StackFrame stackFrame , bool demangle )
8991 {
9092 const string unknownRequiredField = "(unknown)" ;
9193 var frame = new SentryStackFrame ( ) ;
92- if ( stackFrame . GetMethod ( ) is MethodBase method )
94+ if ( GetMethod ( stackFrame ) is MethodBase method )
9395 {
9496 // TODO: SentryStackFrame.TryParse and skip frame instead of these unknown values:
9597 frame . Module = method . DeclaringType ? . FullName ?? unknownRequiredField ;
@@ -120,13 +122,17 @@ internal SentryStackFrame CreateFrame(StackFrame stackFrame)
120122 frame . ColumnNumber = colNo ;
121123 }
122124
123- // TODO: Consider Ben.Demystifier
124- DemangleAsyncFunctionName ( frame ) ;
125- DemangleAnonymousFunction ( frame ) ;
125+ if ( demangle )
126+ {
127+ DemangleAsyncFunctionName ( frame ) ;
128+ DemangleAnonymousFunction ( frame ) ;
129+ }
126130
127131 return frame ;
128132 }
129133
134+ protected virtual MethodBase GetMethod ( StackFrame stackFrame ) => stackFrame . GetMethod ( ) ;
135+
130136 private bool IsSystemModuleName ( string moduleName )
131137 {
132138 if ( string . IsNullOrEmpty ( moduleName ) )
0 commit comments