File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,12 @@ public static IApplicationBuilder UseSentry(this IApplicationBuilder app)
3838 o . DiagnosticLogger = new MelDiagnosticLogger ( logger , o . DiagnosticsLevel ) ;
3939 }
4040
41+ var stackTraceFactory = app . ApplicationServices . GetService < ISentryStackTraceFactory > ( ) ;
42+ if ( stackTraceFactory != null )
43+ {
44+ o . UseStackTraceFactory ( stackTraceFactory ) ;
45+ }
46+
4147 if ( app . ApplicationServices . GetService < IEnumerable < ISentryEventProcessor > > ( ) . Any ( ) )
4248 {
4349 o . AddEventProcessorProvider ( app . ApplicationServices . GetServices < ISentryEventProcessor > ) ;
Original file line number Diff line number Diff line change @@ -120,6 +120,24 @@ public static IEnumerable<ISentryEventProcessor> GetAllEventProcessors(this Sent
120120 public static IEnumerable < ISentryEventExceptionProcessor > GetAllExceptionProcessors ( this SentryOptions options )
121121 => options . ExceptionProcessorsProviders . SelectMany ( p => p ( ) ) ;
122122
123+ /// <summary>
124+ /// Use custom <see cref="ISentryStackTraceFactory" />
125+ /// </summary>
126+ /// <param name="options">The SentryOptions to hold the processor provider.</param>
127+ /// <param name="sentryStackTraceFactory">The stack trace factory.</param>
128+ public static SentryOptions UseStackTraceFactory ( this SentryOptions options , ISentryStackTraceFactory sentryStackTraceFactory )
129+ {
130+ if ( sentryStackTraceFactory == null ) throw new ArgumentNullException ( nameof ( sentryStackTraceFactory ) ) ;
131+
132+ options . EventProcessors = options . EventProcessors . RemoveAt ( 1 )
133+ . Insert ( 1 , new MainSentryEventProcessor ( options , sentryStackTraceFactory ) ) ;
134+
135+ options . ExceptionProcessors = options . ExceptionProcessors . RemoveAt ( 0 )
136+ . Insert ( 0 , new MainExceptionProcessor ( options , sentryStackTraceFactory ) ) ;
137+
138+ return options ;
139+ }
140+
123141 internal static void SetupLogging ( this SentryOptions options )
124142 {
125143 if ( options . Debug )
Original file line number Diff line number Diff line change 1+ using System ;
12using System . Linq ;
23using NSubstitute ;
34using Sentry . Extensibility ;
@@ -187,6 +188,32 @@ public void GetAllEventProcessors_NoAdding_SecondReturned_MainSentryEventProcess
187188 Assert . IsType < MainSentryEventProcessor > ( Sut . GetAllEventProcessors ( ) . Skip ( 1 ) . First ( ) ) ;
188189 }
189190
191+ [ Fact ]
192+ public void UseStackTraceFactory ( )
193+ {
194+ var eventProcessor1 = Sut . GetAllEventProcessors ( ) . Skip ( 1 ) . First ( ) ;
195+ var exceptionProcessor1 = Sut . GetAllExceptionProcessors ( ) . First ( ) ;
196+
197+ Sut . UseStackTraceFactory ( Substitute . For < ISentryStackTraceFactory > ( ) ) ;
198+
199+ var eventProcessor2 = Sut . GetAllEventProcessors ( ) . Skip ( 1 ) . First ( ) ;
200+ var exceptionProcessor2 = Sut . GetAllExceptionProcessors ( ) . First ( ) ;
201+
202+ Assert . IsType < MainSentryEventProcessor > ( eventProcessor1 ) ;
203+ Assert . IsType < MainExceptionProcessor > ( exceptionProcessor1 ) ;
204+ Assert . IsType < MainSentryEventProcessor > ( eventProcessor2 ) ;
205+ Assert . IsType < MainExceptionProcessor > ( exceptionProcessor2 ) ;
206+
207+ Assert . NotEqual ( eventProcessor1 , eventProcessor2 ) ;
208+ Assert . NotEqual ( exceptionProcessor1 , exceptionProcessor2 ) ;
209+ }
210+
211+ [ Fact ]
212+ public void UseStackTraceFactory_NotNull ( )
213+ {
214+ Assert . Throws < ArgumentNullException > ( ( ) => Sut . UseStackTraceFactory ( null ) ) ;
215+ }
216+
190217 [ Fact ]
191218 public void GetAllEventProcessors_AddingMore_FirstReturned_DuplicateDetectionProcessor ( )
192219 {
You can’t perform that action at this time.
0 commit comments