-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathSentryUnityOptionsExtensions.cs
More file actions
108 lines (92 loc) · 3.71 KB
/
SentryUnityOptionsExtensions.cs
File metadata and controls
108 lines (92 loc) · 3.71 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using Sentry.Extensibility;
using Sentry.Unity.Integrations;
namespace Sentry.Unity;
public static class SentryUnityOptionsExtensions
{
public static bool ShouldInitializeSdk(this SentryUnityOptions? options) => ShouldInitializeSdk(options, null);
internal static bool ShouldInitializeSdk(this SentryUnityOptions? options, IApplication? application = null)
{
if (options is null)
{
return false;
}
if (!IsValid(options))
{
return false;
}
application ??= ApplicationAdapter.Instance;
if (!options!.CaptureInEditor && application.IsEditor)
{
options.DiagnosticLogger?.LogInfo("Disabled while in the Editor.");
return false;
}
return true;
}
internal static bool IsValid(this SentryUnityOptions options)
{
if (!options.Enabled)
{
options.DiagnosticLogger?.LogDebug("Sentry SDK has been disabled." +
"\nYou can disable this log by raising the debug verbosity level above 'Debug'.");
return false;
}
if (string.IsNullOrWhiteSpace(options.Dsn))
{
options.DiagnosticLogger?.LogWarning("No Sentry DSN configured. Sentry will be disabled.");
return false;
}
return true;
}
internal static void SetupUnityLogging(this SentryUnityOptions options)
{
if (options.Debug)
{
if (options.DiagnosticLogger is null)
{
options.DiagnosticLogger = new UnityLogger(options);
options.DiagnosticLogger.LogDebug("Logging enabled with 'UnityLogger' min level: {0}", options.DiagnosticLevel);
}
}
else
{
options.DiagnosticLogger = null;
}
}
internal static void AddIl2CppExceptionProcessor(this SentryUnityOptions options, ISentryUnityInfo unityInfo)
{
if (unityInfo.Il2CppMethods is not null)
{
options.AddExceptionProcessor(new UnityIl2CppEventExceptionProcessor(options, unityInfo));
}
else
{
options.DiagnosticLogger?.LogWarning("Failed to find required IL2CPP methods - Skipping line number support");
}
}
/// <summary>
/// Disables the capture of errors through <see cref="UnityLogHandlerIntegration"/>.
/// </summary>
/// <param name="options">The SentryUnityOptions to remove the integration from.</param>
public static void DisableUnityApplicationLoggingIntegration(this SentryUnityOptions options) =>
options.RemoveIntegration<UnityLogHandlerIntegration>();
/// <summary>
/// Disables the application-not-responding detection.
/// </summary>
public static void DisableAnrIntegration(this SentryUnityOptions options) =>
options.RemoveIntegration<AnrIntegration>();
/// <summary>
/// Disables the automatic filtering of Bad Gateway exception of type Exception.
/// </summary>
public static void DisableBadGatewayExceptionFilter(this SentryUnityOptions options) =>
options.RemoveExceptionFilter<UnityBadGatewayExceptionFilter>();
/// <summary>
/// Disables the automatic filtering of System.Net.WebException.
/// </summary>
public static void DisableWebExceptionFilter(this SentryUnityOptions options) =>
options.RemoveExceptionFilter<UnityWebExceptionFilter>();
/// <summary>
/// Disables the automatic filtering of System.Net.Sockets.SocketException with error code 10049.
/// </summary>
public static void DisableSocketExceptionFilter(this SentryUnityOptions options) =>
options.RemoveExceptionFilter<UnitySocketExceptionFilter>();
}