-
-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathEnricher.cs
More file actions
84 lines (71 loc) · 2.82 KB
/
Enricher.cs
File metadata and controls
84 lines (71 loc) · 2.82 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
using System;
using System.Runtime.InteropServices;
using Sentry.PlatformAbstractions;
using OperatingSystem = Sentry.Protocol.OperatingSystem;
using Runtime = Sentry.Protocol.Runtime;
namespace Sentry.Internal
{
internal class Enricher
{
private readonly SentryOptions _options;
private readonly Lazy<Runtime> _runtimeLazy = new(() =>
{
var current = PlatformAbstractions.Runtime.Current;
return new Runtime
{
Name = current.Name,
Version = current.Version,
RawDescription = current.Raw
};
});
public Enricher(SentryOptions options) => _options = options;
public void Apply(IEventLike eventLike)
{
// Runtime
if (!eventLike.Contexts.ContainsKey(Runtime.Type))
{
eventLike.Contexts[Runtime.Type] = _runtimeLazy.Value;
}
// Operating System
if (!eventLike.Contexts.ContainsKey(OperatingSystem.Type))
{
// RuntimeInformation.OSDescription is throwing on Mono 5.12
if (!PlatformAbstractions.Runtime.Current.IsMono())
{
eventLike.Contexts.OperatingSystem.RawDescription = RuntimeInformation.OSDescription;
}
}
// SDK
// SDK Name/Version might have be already set by an outer package
// e.g: ASP.NET Core can set itself as the SDK
if (eventLike.Sdk.Version is null && eventLike.Sdk.Name is null)
{
eventLike.Sdk.Name = Constants.SdkName;
eventLike.Sdk.Version = SdkVersion.Instance.Version;
}
if (SdkVersion.Instance.Version is not null)
{
eventLike.Sdk.AddPackage("nuget:" + SdkVersion.Instance.Name, SdkVersion.Instance.Version);
}
// Release
eventLike.Release ??= ReleaseLocator.Resolve(_options);
// Environment
eventLike.Environment ??= EnvironmentLocator.Resolve(_options);
// User
// Report local user if opt-in PII, no user was already set to event and feature not opted-out:
if (_options.SendDefaultPii)
{
if (_options.IsEnvironmentUser && !eventLike.HasUser())
{
eventLike.User.Username = Environment.UserName;
}
eventLike.User.IpAddress ??= "{{auto}}";
}
//Apply App startup and Boot time
eventLike.Contexts.App.StartTime ??= ProcessInfo.Instance?.StartupTime;
eventLike.Contexts.Device.BootTime ??= ProcessInfo.Instance?.BootTime;
// Default tags
_options.ApplyDefaultTags(eventLike);
}
}
}