-
-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathSentryEventHelper.cs
More file actions
77 lines (69 loc) · 2.52 KB
/
SentryEventHelper.cs
File metadata and controls
77 lines (69 loc) · 2.52 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
using Sentry.Extensibility;
namespace Sentry.Internal;
internal static class SentryEventHelper
{
public static SentryEvent? ProcessEvent(SentryEvent? evt, IEnumerable<ISentryEventProcessor> processors,
SentryHint? hint, SentryOptions options, DataCategory dataCategory)
{
if (evt == null)
{
return evt;
}
var processedEvent = evt;
var effectiveHint = hint ?? new SentryHint(options);
foreach (var processor in processors)
{
processedEvent = processor.DoProcessEvent(processedEvent, effectiveHint);
if (processedEvent == null)
{
options.ClientReportRecorder.RecordDiscardedEvent(DiscardReason.EventProcessor, dataCategory);
options.LogInfo("Event dropped by processor {0}", processor.GetType().Name);
break;
}
}
return processedEvent;
}
#if NET6_0_OR_GREATER
[UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AotHelper.AvoidAtRuntime)]
#endif
public static SentryEvent? DoBeforeSend(SentryEvent? @event, SentryHint hint, SentryOptions options)
{
if (@event is null || options.BeforeSendInternal is null)
{
return @event;
}
options.LogDebug("Calling the BeforeSend callback.");
try
{
@event = options.BeforeSendInternal?.Invoke(@event, hint);
if (@event == null) // Rejected event
{
options.ClientReportRecorder.RecordDiscardedEvent(DiscardReason.BeforeSend, DataCategory.Error);
options.LogInfo("Event dropped by BeforeSend callback.");
}
}
catch (Exception e)
{
if (!AotHelper.IsTrimmed)
{
// Attempt to demystify exceptions before adding them as breadcrumbs.
e.Demystify();
}
options.LogError(e, "The BeforeSend callback threw an exception. It will be added as breadcrumb and continue.");
var data = new Dictionary<string, string>
{
{"message", e.Message}
};
if (e.StackTrace is not null)
{
data.Add("stackTrace", e.StackTrace);
}
@event?.AddBreadcrumb(
"BeforeSend callback failed.",
category: "SentryClient",
data: data,
level: BreadcrumbLevel.Error);
}
return @event;
}
}