@@ -74,37 +74,33 @@ protected override void HandleOnNext(KeyValuePair<string, object> kv)
74
74
}
75
75
switch ( kv . Key )
76
76
{
77
- case "Microsoft.AspNetCore.Diagnostics.UnhandledException" : //Called when exception handler is registered
77
+ case "Microsoft.AspNetCore.Diagnostics.UnhandledException" :
78
+ HandleException ( _defaultHttpContextFetcher , _exceptionContextPropertyFetcher , kv , false ) ;
79
+ break ;
78
80
case "Microsoft.AspNetCore.Diagnostics.HandledException" :
79
- if ( ! ( _defaultHttpContextFetcher . Fetch ( kv . Value ) is DefaultHttpContext httpContextDiagnosticsUnhandledException ) )
80
- return ;
81
- if ( ! ( _exceptionContextPropertyFetcher . Fetch ( kv . Value ) is Exception diagnosticsException ) )
82
- return ;
83
- if ( ! ProcessingRequests . TryGetValue ( httpContextDiagnosticsUnhandledException , out var iDiagnosticsTransaction ) )
84
- return ;
85
-
86
- if ( iDiagnosticsTransaction is Transaction diagnosticsTransaction )
87
- {
88
- diagnosticsTransaction . CollectRequestBody ( true , new AspNetCoreHttpRequest ( httpContextDiagnosticsUnhandledException . Request ) , Logger ) ;
89
- diagnosticsTransaction . CaptureException ( diagnosticsException ) ;
90
- }
91
-
81
+ HandleException ( _defaultHttpContextFetcher , _exceptionContextPropertyFetcher , kv , true ) ;
92
82
break ;
93
83
case "Microsoft.AspNetCore.Hosting.UnhandledException" : // Not called when exception handler registered
94
- if ( ! ( _hostDefaultHttpContextFetcher . Fetch ( kv . Value ) is DefaultHttpContext httpContextUnhandledException ) )
95
- return ;
96
- if ( ! ( _hostExceptionContextPropertyFetcher . Fetch ( kv . Value ) is Exception exception ) )
97
- return ;
98
- if ( ! ProcessingRequests . TryGetValue ( httpContextUnhandledException , out var iCurrentTransaction ) )
99
- return ;
100
-
101
- if ( iCurrentTransaction is Transaction currentTransaction )
102
- {
103
- currentTransaction . CollectRequestBody ( true , new AspNetCoreHttpRequest ( httpContextUnhandledException . Request ) , Logger ) ;
104
- currentTransaction . CaptureException ( exception ) ;
105
- }
84
+ HandleException ( _hostDefaultHttpContextFetcher , _hostExceptionContextPropertyFetcher , kv , false ) ;
106
85
break ;
107
86
}
108
87
}
88
+
89
+ private bool HandleException ( PropertyFetcher propertyFetcher , PropertyFetcher exceptionPropertyFetcher , KeyValuePair < string , object > kv , bool isHandled )
90
+ {
91
+ if ( propertyFetcher . Fetch ( kv . Value ) is not DefaultHttpContext exception )
92
+ return false ;
93
+ if ( exceptionPropertyFetcher . Fetch ( kv . Value ) is not Exception httpContextException )
94
+ return false ;
95
+ if ( ! ProcessingRequests . TryGetValue ( exception , out var iTransaction ) )
96
+ return false ;
97
+ if ( iTransaction is Transaction transaction )
98
+ {
99
+ transaction . CollectRequestBody ( true , new AspNetCoreHttpRequest ( exception . Request ) , Logger ) ;
100
+ transaction . CaptureException ( httpContextException , isHandled : isHandled ) ;
101
+ }
102
+
103
+ return true ;
104
+ }
109
105
}
110
106
}
0 commit comments