-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathSentryUnityOptionsExtensions.cs
More file actions
126 lines (109 loc) · 4.89 KB
/
SentryUnityOptionsExtensions.cs
File metadata and controls
126 lines (109 loc) · 4.89 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using Sentry.Extensibility;
using Sentry.Unity.Integrations;
using UnityEngine;
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 bool IsNativeSupportEnabled(this SentryUnityOptions options, RuntimePlatform? platform = null)
{
platform ??= ApplicationAdapter.Instance.Platform;
return platform switch
{
RuntimePlatform.Android => options.AndroidNativeSupportEnabled,
RuntimePlatform.IPhonePlayer => options.IosNativeSupportEnabled,
RuntimePlatform.WindowsPlayer or RuntimePlatform.WindowsServer => options.WindowsNativeSupportEnabled,
RuntimePlatform.OSXPlayer or RuntimePlatform.OSXServer => options.MacosNativeSupportEnabled,
RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxServer => options.LinuxNativeSupportEnabled,
RuntimePlatform.GameCoreXboxSeries or RuntimePlatform.GameCoreXboxOne => options.XboxNativeSupportEnabled,
RuntimePlatform.PS5 => options.PlayStationNativeSupportEnabled,
RuntimePlatform.Switch => options.SwitchNativeSupportEnabled,
_ => false
};
}
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;
}
}
/// <summary>
/// Disables the capture of logs, warnings, errors, breadcrumbs, and structured logs through
/// <see cref="UnityApplicationLoggingIntegration"/>.
/// </summary>
/// <param name="options">The SentryUnityOptions to remove the integration from.</param>
public static void DisableUnityLoggingIntegration(this SentryUnityOptions options) =>
options.RemoveIntegration<UnityApplicationLoggingIntegration>();
/// <summary>
/// Disables the capture of unhandled exceptions. This removes both <see cref="UnityLogHandlerIntegration"/>
/// (non-WebGL platforms) and <see cref="UnityWebGLExceptionHandler"/> (WebGL platform).
/// </summary>
/// <param name="options">The SentryUnityOptions to remove the integration from.</param>
public static void DisableUnhandledExceptionCapture(this SentryUnityOptions options)
{
options.RemoveIntegration<UnityLogHandlerIntegration>();
options.RemoveIntegration<UnityWebGLExceptionHandler>();
}
/// <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>();
}