-
-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathSentryAspNetCoreOptionsSetup.cs
More file actions
88 lines (78 loc) · 3.05 KB
/
SentryAspNetCoreOptionsSetup.cs
File metadata and controls
88 lines (78 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging.Configuration;
using Microsoft.Extensions.Options;
using Sentry.Extensions.Logging;
using Sentry.Internal;
namespace Sentry.AspNetCore;
/// <summary>
/// Sets up ASP.NET Core option for Sentry.
/// </summary>
#if NETSTANDARD2_0
internal sealed class SentryAspNetCoreOptionsSetup : ConfigureFromConfigurationOptions<SentryAspNetCoreOptions>
{
/// <summary>
/// Creates a new instance of <see cref="SentryAspNetCoreOptionsSetup"/>.
/// </summary>
public SentryAspNetCoreOptionsSetup(
ILoggerProviderConfiguration<SentryAspNetCoreLoggerProvider> providerConfiguration)
: base(providerConfiguration.Configuration)
{
}
/// <summary>
/// Configures the <see cref="SentryAspNetCoreOptions"/>.
/// </summary>
public override void Configure(SentryAspNetCoreOptions options)
{
base.Configure(options);
options.AddDiagnosticSourceIntegration();
options.DeduplicateUnhandledException();
options.AddTransactionProcessor(new TraceIgnoreStatusCodeTransactionProcessor(options));
}
}
#else
internal sealed class SentryAspNetCoreOptionsSetup : IConfigureOptions<SentryAspNetCoreOptions>
{
private readonly IConfiguration _config;
/// <summary>
/// Creates a new instance of <see cref="SentryAspNetCoreOptionsSetup"/>.
/// </summary>
public SentryAspNetCoreOptionsSetup(ILoggerProviderConfiguration<SentryAspNetCoreLoggerProvider> providerConfiguration)
: this(providerConfiguration.Configuration)
{
}
/// <summary>
/// Creates a new instance of <see cref="SentryAspNetCoreOptionsSetup"/>.
/// </summary>
internal SentryAspNetCoreOptionsSetup(IConfiguration config)
{
ArgumentNullException.ThrowIfNull(config);
_config = config;
}
/// <summary>
/// Configures the <see cref="SentryAspNetCoreOptions"/>.
/// </summary>
public void Configure(SentryAspNetCoreOptions options)
{
ArgumentNullException.ThrowIfNull(options);
var bindable = new BindableSentryAspNetCoreOptions();
_config.Bind(bindable);
bindable.ApplyTo(options);
options.DeduplicateUnhandledException();
options.AddTransactionProcessor(new TraceIgnoreStatusCodeTransactionProcessor(options));
}
}
#endif
internal static class SentryAspNetCoreOptionsExtensions
{
internal static void DeduplicateUnhandledException(this SentryAspNetCoreOptions options)
{
options.AddLogEntryFilter((category, _, eventId, _)
// https://github.com/aspnet/KestrelHttpServer/blob/0aff4a0440c2f393c0b98e9046a8e66e30a56cb0/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs#L33
// 13 = Application unhandled exception, which is captured by the middleware so the LogError of kestrel ends up as a duplicate with less info
=> eventId.Id == 13
&& string.Equals(
category,
"Microsoft.AspNetCore.Server.Kestrel",
StringComparison.Ordinal));
}
}