-
-
Notifications
You must be signed in to change notification settings - Fork 211
/
Copy pathMainSentryEventProcessor.cs
145 lines (124 loc) · 5.11 KB
/
MainSentryEventProcessor.cs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using Sentry.Extensibility;
using Sentry.PlatformAbstractions;
using Sentry.Protocol;
using Sentry.Reflection;
using OperatingSystem = Sentry.Protocol.OperatingSystem;
using Runtime = Sentry.Protocol.Runtime;
namespace Sentry.Internal
{
internal class MainSentryEventProcessor : ISentryEventProcessor
{
private readonly Lazy<string> _release = new Lazy<string>(ReleaseLocator.GetCurrent);
private readonly Lazy<Runtime> _runtime = new Lazy<Runtime>(() =>
{
var current = PlatformAbstractions.Runtime.Current;
return current != null
? new Runtime
{
Name = current.Name,
Version = current.Version,
RawDescription = current.Raw
}
: null;
});
private static readonly SdkVersion NameAndVersion
= typeof(ISentryClient).Assembly.GetNameAndVersion();
private static readonly string ProtocolPackageName = "nuget:" + NameAndVersion.Name;
private readonly SentryOptions _options;
internal Func<ISentryStackTraceFactory> SentryStackTraceFactoryAccessor { get; }
internal string Release => _release.Value;
internal Runtime Runtime => _runtime.Value;
public MainSentryEventProcessor(
SentryOptions options,
Func<ISentryStackTraceFactory> sentryStackTraceFactoryAccessor)
{
Debug.Assert(options != null);
Debug.Assert(sentryStackTraceFactoryAccessor != null);
_options = options;
SentryStackTraceFactoryAccessor = sentryStackTraceFactoryAccessor;
}
public SentryEvent Process(SentryEvent @event)
{
_options.DiagnosticLogger?.LogDebug("Running main event processor on: Event {0}", @event.EventId);
if ([email protected](Runtime.Type))
{
@event.Contexts[Runtime.Type] = Runtime;
}
if ([email protected](OperatingSystem.Type))
{
// RuntimeInformation.OSDescription is throwing on Mono 5.12
if (!PlatformAbstractions.Runtime.Current.IsMono())
{
@event.Contexts.OperatingSystem.RawDescription = RuntimeInformation.OSDescription;
}
}
@event.Platform = Protocol.Constants.Platform;
// SDK Name/Version might have be already set by an outer package
// e.g: ASP.NET Core can set itself as the SDK
if (@event.Sdk.Version == null && @event.Sdk.Name == null)
{
@event.Sdk.Name = Constants.SdkName;
@event.Sdk.Version = NameAndVersion.Version;
}
@event.Sdk.AddPackage(ProtocolPackageName, NameAndVersion.Version);
// Report local user if opt-in PII, no user was already set to event and feature not opted-out:
if (_options.SendDefaultPii && _options.IsEnvironmentUser && [email protected]())
{
@event.User.Username = System.Environment.UserName;
}
if (@event.ServerName == null && _options.SendDefaultPii)
{
@event.ServerName = System.Environment.MachineName;
}
if (@event.Level == null)
{
@event.Level = SentryLevel.Error;
}
if (@event.Release == null)
{
@event.Release = _options.Release ?? Release;
}
if (@event.Environment == null)
{
@event.Environment = _options.Environment ?? EnvironmentLocator.Locate();
}
if (@event.Exception == null)
{
var stackTrace = SentryStackTraceFactoryAccessor().Create(@event.Exception);
if (stackTrace != null)
{
var thread = new SentryThread
{
Crashed = false,
Current = true,
Name = Thread.CurrentThread.Name,
Id = Thread.CurrentThread.ManagedThreadId,
Stacktrace = stackTrace
};
@event.SentryThreads = @event.SentryThreads.Any()
? new List<SentryThread>(@event.SentryThreads) { thread }
: new[] { thread } as IEnumerable<SentryThread>;
}
}
if (_options.ReportAssemblies)
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (assembly.IsDynamic)
{
continue;
}
var asmName = assembly.GetName();
@event.Modules[asmName.Name] = asmName.Version.ToString();
}
}
return @event;
}
}
}