Skip to content

Commit 44d8dd2

Browse files
authored
Fixed a bug where exceptions converted into 404's were not being run through exclusions
2 parents e409637 + cff7d29 commit 44d8dd2

File tree

10 files changed

+63
-46
lines changed

10 files changed

+63
-46
lines changed

src/Exceptionless/Extensions/EventExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static bool IsLog(this Event ev) {
6868
public static bool IsFeatureUsage(this Event ev) {
6969
return ev.Type == Event.KnownTypes.FeatureUsage;
7070
}
71-
71+
7272
/// <summary>
7373
/// Returns true if the event type is session start.
7474
/// </summary>
@@ -85,7 +85,7 @@ public static void AddRequestInfo(this Event ev, RequestInfo request) {
8585

8686
ev.Data[Event.KnownDataKeys.RequestInfo] = request;
8787
}
88-
88+
8989
/// <summary>
9090
/// Sets the version that the event happened on.
9191
/// </summary>
@@ -97,14 +97,14 @@ public static void SetVersion(this Event ev, string version) {
9797

9898
ev.Data[Event.KnownDataKeys.Version] = version.Trim();
9999
}
100-
100+
101101
/// <summary>
102102
/// Gets the user info object from extended data.
103103
/// </summary>
104104
public static UserInfo GetUserIdentity(this Event ev, IJsonSerializer serializer = null) {
105105
return ev.GetDataValue<UserInfo>(Event.KnownDataKeys.UserInfo, serializer);
106106
}
107-
107+
108108
/// <summary>
109109
/// Sets the user's identity (ie. email address, username, user id) that the event happened to.
110110
/// </summary>
@@ -187,7 +187,7 @@ public static void SetGeo(this Event ev, string coordinates) {
187187
else
188188
throw new ArgumentException("Must be either lat,lon or an IP address.", "coordinates");
189189
}
190-
190+
191191
/// <summary>
192192
/// Sets the event geo coordinates.
193193
/// </summary>
@@ -312,7 +312,7 @@ public static void SetManualStackingKey(this Event ev, string manualStackingKey)
312312
public static void SetManualStackingKey(this Event ev, string title, string manualStackingKey) {
313313
if (String.IsNullOrWhiteSpace(title) || String.IsNullOrWhiteSpace(manualStackingKey))
314314
return;
315-
315+
316316
ev.Data[Event.KnownDataKeys.ManualStackingInfo] = new ManualStackingInfo(title, new Dictionary<string, string> { { "ManualStackingKey", manualStackingKey } });
317317
}
318318

src/Exceptionless/Extensions/ExceptionlessClientExtensions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace Exceptionless {
1212
public static class ExceptionlessClientExtensions {
1313
/// <summary>
14-
/// Reads configuration settings, configures various plugins and wires up to platform specific exception handlers.
14+
/// Reads configuration settings, configures various plugins and wires up to platform specific exception handlers.
1515
/// </summary>
1616
/// <param name="client">The ExceptionlessClient.</param>
1717
/// <param name="apiKey">The API key that will be used when sending events to the server.</param>
@@ -21,7 +21,7 @@ public static void Startup(this ExceptionlessClient client, string apiKey = null
2121

2222
if (!String.IsNullOrEmpty(apiKey))
2323
client.Configuration.ApiKey = apiKey;
24-
24+
2525
client.Configuration.ReadAllConfig();
2626

2727
#if !PORTABLE && !NETSTANDARD1_2
@@ -38,7 +38,7 @@ public static void Startup(this ExceptionlessClient client, string apiKey = null
3838
client.RegisterOnProcessExitHandler();
3939
#endif
4040
client.RegisterTaskSchedulerUnobservedTaskExceptionHandler();
41-
41+
4242
if (client.Configuration.SessionsEnabled)
4343
client.SubmitSessionStart();
4444
}
@@ -56,12 +56,12 @@ public static void Shutdown(this ExceptionlessClient client) {
5656
client.UnregisterOnProcessExitHandler();
5757
#endif
5858
client.UnregisterTaskSchedulerUnobservedTaskExceptionHandler();
59-
59+
6060
client.ProcessQueue();
6161
if (client.Configuration.SessionsEnabled)
6262
client.SubmitSessionEnd();
6363
}
64-
64+
6565
#region Submission Extensions
6666

6767
/// <summary>
@@ -369,7 +369,7 @@ public static void RegisterAppDomainUnhandledExceptionHandler(this Exceptionless
369369

370370
// process queue immediately since the app is about to exit.
371371
client.ProcessQueue();
372-
372+
373373
if (client.Configuration.SessionsEnabled)
374374
client.SubmitSessionEnd();
375375
};
@@ -389,7 +389,7 @@ public static void UnregisterAppDomainUnhandledExceptionHandler(this Exceptionle
389389

390390
if (_onAppDomainUnhandledException == null)
391391
return;
392-
392+
393393
AppDomain.CurrentDomain.UnhandledException -= _onAppDomainUnhandledException;
394394
_onAppDomainUnhandledException = null;
395395
}

src/Platforms/Exceptionless.AspNetCore/ExceptionlessAspNetCorePlugin.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Exceptionless.Extensions;
66
using Exceptionless.Logging;
77
using Exceptionless.Models;
8-
using Exceptionless.AspNetCore;
98

109
namespace Exceptionless.AspNetCore {
1110
[Priority(90)]
@@ -32,13 +31,17 @@ public void Run(EventPluginContext context) {
3231
if (ri == null)
3332
return;
3433

34+
context.Event.AddRequestInfo(ri);
3535
var error = context.Event.GetError(serializer);
36-
if (error != null && error.Code == "404") {
37-
context.Event.Type = Event.KnownTypes.NotFound;
38-
context.Event.Source = ri.GetFullPath(includeHttpMethod: true, includeHost: false, includeQueryString: false);
39-
}
36+
if (error == null || error.Code != "404")
37+
return;
4038

41-
context.Event.AddRequestInfo(ri);
39+
context.Event.Type = Event.KnownTypes.NotFound;
40+
context.Event.Source = ri.GetFullPath(includeHttpMethod: true, includeHost: false, includeQueryString: false);
41+
if (!context.Client.Configuration.Settings.GetTypeAndSourceEnabled(context.Event.Type, context.Event.Source)) {
42+
context.Log.Info(String.Format("Cancelling event from excluded type: {0} and source: {1}", context.Event.Type, context.Event.Source));
43+
context.Cancel = true;
44+
}
4245
}
4346

4447
private static void AddUser(EventPluginContext context, HttpContext httpContext, IJsonSerializer serializer) {

src/Platforms/Exceptionless.AspNetCore/ExceptionlessExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static IApplicationBuilder UseExceptionless(this IApplicationBuilder app,
2121
client.Configuration.AddPlugin<ExceptionlessAspNetCorePlugin>();
2222
client.Configuration.AddPlugin<IgnoreUserAgentPlugin>();
2323
//client.Configuration.Resolver.Register<ILastReferenceIdManager, WebLastReferenceIdManager>();
24-
24+
2525
var diagnosticListener = app.ApplicationServices.GetRequiredService<DiagnosticListener>();
2626
diagnosticListener?.SubscribeWithAdapter(new ExceptionlessDiagnosticListener(client));
2727

src/Platforms/Exceptionless.Mvc/ExceptionlessModule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public virtual void Init(HttpApplication app) {
1717
ExceptionlessClient.Default.Configuration.AddPlugin<ExceptionlessWebPlugin>();
1818
ExceptionlessClient.Default.Configuration.AddPlugin<IgnoreUserAgentPlugin>();
1919
ExceptionlessClient.Default.Configuration.Resolver.Register<ILastReferenceIdManager, WebLastReferenceIdManager>();
20-
20+
2121
_app = app;
2222

2323
if (!GlobalFilters.Filters.Any(f => f.Instance is ExceptionlessSendErrorsAttribute))
@@ -26,7 +26,7 @@ public virtual void Init(HttpApplication app) {
2626

2727
public void Dispose() {
2828
ExceptionlessClient.Default.Shutdown();
29-
ExceptionlessClient.Default.RegisterHttpApplicationErrorHandler(_app);
29+
ExceptionlessClient.Default.UnregisterHttpApplicationErrorHandler(_app);
3030
}
3131
}
3232
}

src/Platforms/Exceptionless.Nancy/ExceptionlessNancyPlugin.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,25 @@ public void Run(EventPluginContext context) {
1818
if (nancyContext.CurrentUser != null && context.Client.Configuration.IncludePrivateInformation)
1919
context.Event.SetUserIdentity(nancyContext.CurrentUser.UserName);
2020

21-
RequestInfo requestInfo = null;
21+
RequestInfo ri = null;
2222
try {
23-
requestInfo = nancyContext.GetRequestInfo(context.Client.Configuration);
23+
ri = nancyContext.GetRequestInfo(context.Client.Configuration);
2424
} catch (Exception ex) {
2525
context.Log.Error(typeof(ExceptionlessNancyPlugin), ex, "Error adding request info.");
2626
}
2727

28-
if (requestInfo == null)
28+
if (ri == null)
2929
return;
3030

31-
if (context.Event.Type == Event.KnownTypes.NotFound)
32-
context.Event.Source = requestInfo.GetFullPath(includeHttpMethod: true, includeHost: false, includeQueryString: false);
31+
context.Event.AddRequestInfo(ri);
32+
if (context.Event.Type != Event.KnownTypes.NotFound)
33+
return;
3334

34-
context.Event.AddRequestInfo(requestInfo);
35+
context.Event.Source = ri.GetFullPath(includeHttpMethod: true, includeHost: false, includeQueryString: false);
36+
if (!context.Client.Configuration.Settings.GetTypeAndSourceEnabled(context.Event.Type, context.Event.Source)) {
37+
context.Log.Info(String.Format("Cancelling event from excluded type: {0} and source: {1}", context.Event.Type, context.Event.Source));
38+
context.Cancel = true;
39+
}
3540
}
3641
}
3742
}

src/Platforms/Exceptionless.Web/ExceptionlessClientExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static void RegisterHttpApplicationErrorHandler(this ExceptionlessClient
3737
}
3838
}
3939

40-
public static void UnregisterHttpApplicationErrorExceptionHandler(this ExceptionlessClient client, HttpApplication app) {
40+
public static void UnregisterHttpApplicationErrorHandler(this ExceptionlessClient client, HttpApplication app) {
4141
if (client == null)
4242
throw new ArgumentNullException(nameof(client));
4343

src/Platforms/Exceptionless.Web/ExceptionlessModule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ public virtual void Init(HttpApplication app) {
1414
ExceptionlessClient.Default.Configuration.AddPlugin<ExceptionlessWebPlugin>();
1515
ExceptionlessClient.Default.Configuration.AddPlugin<IgnoreUserAgentPlugin>();
1616
ExceptionlessClient.Default.Configuration.Resolver.Register<ILastReferenceIdManager, WebLastReferenceIdManager>();
17-
17+
1818
_app = app;
1919
}
2020

2121
public void Dispose() {
2222
ExceptionlessClient.Default.Shutdown();
23-
ExceptionlessClient.Default.UnregisterHttpApplicationErrorExceptionHandler(_app);
23+
ExceptionlessClient.Default.UnregisterHttpApplicationErrorHandler(_app);
2424
}
2525
}
2626
}

src/Platforms/Exceptionless.Web/ExceptionlessWebPlugin.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void Run(EventPluginContext context) {
1818
// if the context is not passed in, try and grab it
1919
if (httpContext == null && HttpContext.Current != null)
2020
httpContext = HttpContext.Current.ToWrapped();
21-
21+
2222
var serializer = context.Client.Configuration.Resolver.GetJsonSerializer();
2323
if (context.Client.Configuration.IncludePrivateInformation)
2424
AddUser(context, httpContext, serializer);
@@ -29,7 +29,7 @@ public void Run(EventPluginContext context) {
2929
var tags = httpContext.Items[TAGS_HTTP_CONTEXT_NAME] as TagSet;
3030
if (tags != null)
3131
context.Event.Tags.UnionWith(tags);
32-
32+
3333
var ri = context.Event.GetRequestInfo(serializer);
3434
if (ri != null)
3535
return;
@@ -43,16 +43,21 @@ public void Run(EventPluginContext context) {
4343
if (ri == null)
4444
return;
4545

46+
context.Event.AddRequestInfo(ri);
4647
var httpException = context.ContextData.GetException() as HttpException;
47-
if (httpException != null) {
48-
int httpCode = httpException.GetHttpCode();
49-
if (httpCode == 404) {
50-
context.Event.Type = Event.KnownTypes.NotFound;
51-
context.Event.Source = ri.GetFullPath(includeHttpMethod: true, includeHost: false, includeQueryString: false);
52-
}
53-
}
48+
if (httpException == null)
49+
return;
5450

55-
context.Event.AddRequestInfo(ri);
51+
int httpCode = httpException.GetHttpCode();
52+
if (httpCode != 404)
53+
return;
54+
55+
context.Event.Type = Event.KnownTypes.NotFound;
56+
context.Event.Source = ri.GetFullPath(includeHttpMethod: true, includeHost: false, includeQueryString: false);
57+
if (!context.Client.Configuration.Settings.GetTypeAndSourceEnabled(context.Event.Type, context.Event.Source)) {
58+
context.Log.Info(String.Format("Cancelling event from excluded type: {0} and source: {1}", context.Event.Type, context.Event.Source));
59+
context.Cancel = true;
60+
}
5661
}
5762

5863
private static void AddUser(EventPluginContext context, HttpContextBase httpContext, IJsonSerializer serializer) {

src/Platforms/Exceptionless.WebApi/ExceptionlessWebApiPlugin.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,17 @@ public void Run(EventPluginContext context) {
3737
if (ri == null)
3838
return;
3939

40+
context.Event.AddRequestInfo(ri);
4041
var error = context.Event.GetError(serializer);
41-
if (error != null && error.Code == "404") {
42-
context.Event.Type = Event.KnownTypes.NotFound;
43-
context.Event.Source = ri.GetFullPath(includeHttpMethod: true, includeHost: false, includeQueryString: false);
44-
}
42+
if (error == null || error.Code != "404")
43+
return;
4544

46-
context.Event.AddRequestInfo(ri);
45+
context.Event.Type = Event.KnownTypes.NotFound;
46+
context.Event.Source = ri.GetFullPath(includeHttpMethod: true, includeHost: false, includeQueryString: false);
47+
if (!context.Client.Configuration.Settings.GetTypeAndSourceEnabled(context.Event.Type, context.Event.Source)) {
48+
context.Log.Info(String.Format("Cancelling event from excluded type: {0} and source: {1}", context.Event.Type, context.Event.Source));
49+
context.Cancel = true;
50+
}
4751
}
4852

4953
private static void AddUser(EventPluginContext context, HttpActionContext actionContext, IJsonSerializer serializer) {

0 commit comments

Comments
 (0)