diff --git a/CHANGELOG.md b/CHANGELOG.md
index 307f3b097..4e297c67a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@
### Fixes
+- Fixed IL2CPP line number support for 32-bit Windows and Linux ([#2514](https://github.com/getsentry/sentry-unity/pull/2514))
- The SDK now specifies the files and directories targeted for debug symbol upload instead of pointing sentry-cli at the build output directory ([#2485](https://github.com/getsentry/sentry-unity/pull/2485))
- The 'SceneManagerTracingIntegration' properly respects the `AutoSceneTracing` flag again ([#2496](https://github.com/getsentry/sentry-unity/pull/2496))
- When targeting Android, the capturing native SDK now has its name correctly set ([#2476](https://github.com/getsentry/sentry-unity/pull/2476))
diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs
index 3e46e5384..db340bc7f 100644
--- a/package-dev/Runtime/SentryInitialization.cs
+++ b/package-dev/Runtime/SentryInitialization.cs
@@ -3,7 +3,7 @@
#define SENTRY_NATIVE_COCOA
#elif UNITY_ANDROID && ENABLE_IL2CPP
#define SENTRY_NATIVE_ANDROID
-#elif UNITY_64 && (UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX)
+#elif UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX
#define SENTRY_NATIVE
#elif UNITY_GAMECORE
#define SENTRY_NATIVE
@@ -176,20 +176,20 @@ void SwapHexByte(IntPtr buffer, Int32 offset1, Int32 offset2)
// Available in Unity `2013.3.12f1` (and later)
// Il2CppObject* il2cpp_gchandle_get_target(Il2CppGCHandle gchandle)
- [DllImport("__Internal")]
+ [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr il2cpp_gchandle_get_target(IntPtr gchandle);
#else
private static IntPtr Il2CppGcHandleGetTargetShim(IntPtr gchandle) => il2cpp_gchandle_get_target(gchandle.ToInt32());
// Available in Unity `2019.4.34f1` (and later)
// Il2CppObject* il2cpp_gchandle_get_target(uint32_t gchandle)
- [DllImport("__Internal")]
+ [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr il2cpp_gchandle_get_target(int gchandle);
#endif
// Available in Unity `2019.4.34f1` (and later)
// void il2cpp_free(void* ptr)
- [DllImport("__Internal")]
+ [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
private static extern void il2cpp_free(IntPtr ptr);
private static void Il2CppNativeStackTraceShim(IntPtr exc, out IntPtr addresses, out int numFrames, out string? imageUUID, out string? imageName)
@@ -212,7 +212,7 @@ private static void Il2CppNativeStackTraceShim(IntPtr exc, out IntPtr addresses,
// Definition from Unity `2021.3` (and later):
// void il2cpp_native_stack_trace(const Il2CppException * ex, uintptr_t** addresses, int* numFrames, char** imageUUID, char** imageName)
- [DllImport("__Internal")]
+ [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
private static extern void il2cpp_native_stack_trace(IntPtr exc, out IntPtr addresses, out int numFrames, out IntPtr imageUUID, out IntPtr imageName);
#pragma warning restore 8632
diff --git a/samples/unity-of-bugs/Assets/Scripts/NativeSupport/NativeButtons.cs b/samples/unity-of-bugs/Assets/Scripts/NativeSupport/NativeButtons.cs
index 28ce26844..20bafe367 100644
--- a/samples/unity-of-bugs/Assets/Scripts/NativeSupport/NativeButtons.cs
+++ b/samples/unity-of-bugs/Assets/Scripts/NativeSupport/NativeButtons.cs
@@ -31,13 +31,13 @@ private void Start()
public void CrashInC() => crash_in_c();
// CppPlugin.cpp
- [DllImport("__Internal")]
+ [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
private static extern void throw_cpp();
- [DllImport("__Internal")]
+ [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
private static extern void crash_in_cpp();
// CPlugin.c
- [DllImport("__Internal")]
+ [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
private static extern void crash_in_c();
public void CatchViaCallback() => call_into_csharp(new callback_t(csharpCallback));
@@ -45,7 +45,7 @@ private void Start()
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void callback_t(int code);
- [DllImport("__Internal")]
+ [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
private static extern void call_into_csharp(callback_t callback);
// This method is called from the C library.
diff --git a/src/Sentry.Unity.Android/SentryNativeAndroid.cs b/src/Sentry.Unity.Android/SentryNativeAndroid.cs
index f93367a66..f86fbb456 100644
--- a/src/Sentry.Unity.Android/SentryNativeAndroid.cs
+++ b/src/Sentry.Unity.Android/SentryNativeAndroid.cs
@@ -16,55 +16,59 @@ public static class SentryNativeAndroid
// parameter on `Configure` due SentryNativeAndroid being public
internal static ISentryJava? SentryJava;
+ private static IDiagnosticLogger? Logger;
+
///
/// Configures the native Android support.
///
/// The Sentry Unity options to use.
public static void Configure(SentryUnityOptions options)
{
- options.DiagnosticLogger?.LogInfo("Attempting to configure native support via the Android SDK");
+ Logger = options.DiagnosticLogger;
+
+ Logger?.LogInfo("Attempting to configure native support via the Android SDK");
if (!options.AndroidNativeSupportEnabled)
{
- options.DiagnosticLogger?.LogDebug("Native support is disabled for Android");
+ Logger?.LogDebug("Native support is disabled for Android");
return;
}
- options.DiagnosticLogger?.LogDebug("Checking whether the Android SDK is present.");
+ Logger?.LogDebug("Checking whether the Android SDK is present.");
// If it's not been set (in a test)
- SentryJava ??= new SentryJava(options.DiagnosticLogger);
+ SentryJava ??= new SentryJava(Logger);
if (!SentryJava.IsSentryJavaPresent())
{
- options.DiagnosticLogger?.LogError("Android Native Support has been enabled but the " +
+ Logger?.LogError("Android Native Support has been enabled but the " +
"Android SDK is missing. This could have been caused by a mismatching" +
"build time / runtime configuration. Please make sure you have " +
"Android Native Support enabled during build time.");
return;
}
- options.DiagnosticLogger?.LogDebug("Checking whether the Android SDK has already been initialized");
+ Logger?.LogDebug("Checking whether the Android SDK has already been initialized");
if (SentryJava.IsEnabled() is true)
{
- options.DiagnosticLogger?.LogDebug("The Android SDK is already initialized");
+ Logger?.LogDebug("The Android SDK is already initialized");
}
else
{
- options.DiagnosticLogger?.LogInfo("Initializing the Android SDK");
+ Logger?.LogInfo("Initializing the Android SDK");
SentryJava.Init(options);
- options.DiagnosticLogger?.LogDebug("Validating Android SDK initialization");
+ Logger?.LogDebug("Validating Android SDK initialization");
if (SentryJava.IsEnabled() is not true)
{
- options.DiagnosticLogger?.LogError("Failed to initialize Android Native Support");
+ Logger?.LogError("Failed to initialize Android Native Support");
return;
}
}
- options.DiagnosticLogger?.LogDebug("Configuring scope sync");
+ Logger?.LogDebug("Configuring scope sync");
options.NativeContextWriter = new NativeContextWriter(SentryJava);
options.ScopeObserver = new AndroidJavaScopeObserver(options, SentryJava);
@@ -72,20 +76,20 @@ public static void Configure(SentryUnityOptions options)
options.NativeDebugImageProvider = new Native.NativeDebugImageProvider();
options.CrashedLastRun = () =>
{
- options.DiagnosticLogger?.LogDebug("Checking for 'CrashedLastRun'");
+ Logger?.LogDebug("Checking for 'CrashedLastRun'");
var crashedLastRun = SentryJava.CrashedLastRun();
if (crashedLastRun is null)
{
// Could happen if the Android SDK wasn't initialized before the .NET layer.
- options.DiagnosticLogger?
+ Logger?
.LogWarning(
"Unclear from the native SDK if the previous run was a crash. Assuming it was not.");
crashedLastRun = false;
}
else
{
- options.DiagnosticLogger?.LogDebug("Native SDK reported: 'crashedLastRun': '{0}'", crashedLastRun);
+ Logger?.LogDebug("Native SDK reported: 'crashedLastRun': '{0}'", crashedLastRun);
}
return crashedLastRun.Value;
@@ -93,7 +97,7 @@ public static void Configure(SentryUnityOptions options)
try
{
- options.DiagnosticLogger?.LogDebug("Reinstalling native backend.");
+ Logger?.LogDebug("Reinstalling native backend.");
// At this point Unity has taken the signal handler and will not invoke the original handler (Sentry)
// So we register our backend once more to make sure user-defined data is available in the crash report.
@@ -101,19 +105,19 @@ public static void Configure(SentryUnityOptions options)
}
catch (Exception e)
{
- options.DiagnosticLogger?.LogError(
+ Logger?.LogError(
e, "Failed to reinstall backend. Captured native crashes will miss scope data and tag.");
}
options.NativeSupportCloseCallback = () => Close(options);
- options.DiagnosticLogger?.LogDebug("Fetching installation ID");
+ Logger?.LogDebug("Fetching installation ID");
options.DefaultUserId = SentryJava.GetInstallationId();
if (string.IsNullOrEmpty(options.DefaultUserId))
{
// In case we can't get an installation ID we create one and sync that down to the native layer
- options.DiagnosticLogger?.LogDebug(
+ Logger?.LogDebug(
"Failed to fetch 'Installation ID' from the native SDK. Creating new 'Default User ID'.");
// We fall back to Unity's Analytics Session Info: https://docs.unity3d.com/ScriptReference/Analytics.AnalyticsSessionInfo-userId.html
@@ -126,11 +130,11 @@ public static void Configure(SentryUnityOptions options)
}
else
{
- options.DiagnosticLogger?.LogDebug("Failed to create new 'Default User ID'.");
+ Logger?.LogDebug("Failed to create new 'Default User ID'.");
}
}
- options.DiagnosticLogger?.LogInfo("Successfully configured the Android SDK");
+ Logger?.LogInfo("Successfully configured the Android SDK");
}
///
@@ -138,21 +142,21 @@ public static void Configure(SentryUnityOptions options)
///
public static void Close(SentryUnityOptions options)
{
- options.DiagnosticLogger?.LogInfo("Attempting to close the Android SDK");
+ Logger?.LogInfo("Attempting to close the Android SDK");
if (!options.IsNativeSupportEnabled())
{
- options.DiagnosticLogger?.LogDebug("Android Native Support is not enabled. Skipping closing the Android SDK");
+ Logger?.LogDebug("Android Native Support is not enabled. Skipping closing the Android SDK");
return;
}
if (SentryJava?.IsSentryJavaPresent() is not true)
{
- options.DiagnosticLogger?.LogDebug("Failed to find Sentry Java. Skipping closing the Android SDK");
+ Logger?.LogDebug("Failed to find Sentry Java. Skipping closing the Android SDK");
return;
}
- options.DiagnosticLogger?.LogDebug("Closing the Android SDK");
+ Logger?.LogDebug("Closing the Android SDK");
SentryJava.Close();
}
}
diff --git a/src/Sentry.Unity.Editor/Il2CppBuildPreProcess.cs b/src/Sentry.Unity.Editor/Il2CppBuildPreProcess.cs
index 70c40fa60..5c41aa1cd 100644
--- a/src/Sentry.Unity.Editor/Il2CppBuildPreProcess.cs
+++ b/src/Sentry.Unity.Editor/Il2CppBuildPreProcess.cs
@@ -9,6 +9,7 @@ namespace Sentry.Unity.Editor;
internal class Il2CppBuildPreProcess : IPreprocessBuildWithReport
{
internal const string SourceMappingArgument = "--emit-source-mapping";
+ private static IDiagnosticLogger? Logger;
public int callbackOrder => 0;
@@ -20,14 +21,15 @@ public void OnPreprocessBuild(BuildReport report)
return;
}
-
var options = SentryScriptableObject.LoadOptions(isBuilding: true);
-
if (options is null)
{
return;
}
+ Logger = options.DiagnosticLogger;
+ Logger?.LogInfo("IL2CPP build detected. Handling additional IL2CPP arguments.");
+
SetAdditionalIl2CppArguments(options,
PlayerSettings.GetAdditionalIl2CppArgs,
PlayerSettings.SetAdditionalIl2CppArgs);
@@ -37,12 +39,12 @@ internal static void SetAdditionalIl2CppArguments(SentryUnityOptions options, Fu
{
if (options.Il2CppLineNumberSupportEnabled)
{
- options.DiagnosticLogger?.LogDebug("IL2CPP line number support enabled - Adding additional IL2CPP arguments.");
+ Logger?.LogDebug("IL2CPP line number support enabled - Adding additional IL2CPP arguments.");
var arguments = getArguments.Invoke();
if (arguments.Contains(SourceMappingArgument))
{
- options.DiagnosticLogger?.LogDebug("Additional argument '{0}' already present.", SourceMappingArgument);
+ Logger?.LogDebug("Additional argument '{0}' already present.", SourceMappingArgument);
return;
}
@@ -53,7 +55,7 @@ internal static void SetAdditionalIl2CppArguments(SentryUnityOptions options, Fu
var arguments = getArguments.Invoke();
if (arguments.Contains(SourceMappingArgument))
{
- options.DiagnosticLogger?.LogDebug("IL2CPP line number support disabled - Removing additional IL2CPP arguments.");
+ Logger?.LogDebug("IL2CPP line number support disabled - Removing additional IL2CPP arguments.");
arguments = arguments.Replace(SourceMappingArgument, "");
setArguments.Invoke(arguments);
diff --git a/src/Sentry.Unity.Native/SentryNativeBridge.cs b/src/Sentry.Unity.Native/SentryNativeBridge.cs
index 797d13c03..f3d018e33 100644
--- a/src/Sentry.Unity.Native/SentryNativeBridge.cs
+++ b/src/Sentry.Unity.Native/SentryNativeBridge.cs
@@ -2,7 +2,6 @@
using System.IO;
using System.Runtime.InteropServices;
using Sentry.Extensibility;
-using Sentry.Unity.Integrations;
using UnityEngine;
using AOT;
@@ -20,12 +19,18 @@ internal static class SentryNativeBridge
private const string SentryLib = "sentry";
#endif
+ private static IDiagnosticLogger? Logger; // This is also the logger we're forwarding native messages to.
+ private static bool UseLibC;
+ private static bool IsWindows;
+
public static bool Init(SentryUnityOptions options)
{
- _useLibC = Application.platform
+ Logger = options.DiagnosticLogger;
+
+ UseLibC = Application.platform
is RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxServer
or RuntimePlatform.PS5 or RuntimePlatform.Switch;
- _isWindows = Application.platform is RuntimePlatform.WindowsPlayer or RuntimePlatform.WindowsServer;
+ IsWindows = Application.platform is RuntimePlatform.WindowsPlayer or RuntimePlatform.WindowsServer;
var cOptions = sentry_options_new();
@@ -34,73 +39,64 @@ is RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxServer
if (options.Release is not null)
{
- options.DiagnosticLogger?.LogDebug("Setting Release: {0}", options.Release);
+ Logger?.LogDebug("Setting Release: {0}", options.Release);
sentry_options_set_release(cOptions, options.Release);
}
if (options.Environment is not null)
{
- options.DiagnosticLogger?.LogDebug("Setting Environment: {0}", options.Environment);
+ Logger?.LogDebug("Setting Environment: {0}", options.Environment);
sentry_options_set_environment(cOptions, options.Environment);
}
- options.DiagnosticLogger?.LogDebug("Setting Debug: {0}", options.Debug);
+ Logger?.LogDebug("Setting Debug: {0}", options.Debug);
sentry_options_set_debug(cOptions, options.Debug ? 1 : 0);
if (options.SampleRate.HasValue)
{
- options.DiagnosticLogger?.LogDebug("Setting Sample Rate: {0}", options.SampleRate.Value);
+ Logger?.LogDebug("Setting Sample Rate: {0}", options.SampleRate.Value);
sentry_options_set_sample_rate(cOptions, options.SampleRate.Value);
}
// Disabling the native in favor of the C# layer for now
- options.DiagnosticLogger?.LogDebug("Disabling native auto session tracking");
+ Logger?.LogDebug("Disabling native auto session tracking");
sentry_options_set_auto_session_tracking(cOptions, 0);
- if (_isWindows)
+ if (IsWindows)
{
- options.DiagnosticLogger?.LogDebug("Setting AttachScreenshot: {0}", options.AttachScreenshot);
+ Logger?.LogDebug("Setting AttachScreenshot: {0}", options.AttachScreenshot);
sentry_options_set_attach_screenshot(cOptions, options.AttachScreenshot ? 1 : 0);
}
var dir = GetCacheDirectory(options);
#if SENTRY_NATIVE_SWITCH
- options.DiagnosticLogger?.LogDebug("Setting CacheDirectoryPath: {0}", dir);
+ Logger?.LogDebug("Setting CacheDirectoryPath: {0}", dir);
sentry_options_set_database_path(cOptions, dir);
#else
// Note: don't use RuntimeInformation.IsOSPlatform - it will report windows on WSL.
- if (_isWindows)
+ if (IsWindows)
{
- options.DiagnosticLogger?.LogDebug("Setting CacheDirectoryPath on Windows: {0}", dir);
+ Logger?.LogDebug("Setting CacheDirectoryPath on Windows: {0}", dir);
sentry_options_set_database_pathw(cOptions, dir);
}
else
{
- options.DiagnosticLogger?.LogDebug("Setting CacheDirectoryPath: {0}", dir);
+ Logger?.LogDebug("Setting CacheDirectoryPath: {0}", dir);
sentry_options_set_database_path(cOptions, dir);
}
#endif
- if (options.DiagnosticLogger is null)
+ if (options.UnityInfo.IL2CPP)
{
- _logger?.LogDebug("Unsetting the current native logger");
- _logger = null;
+ Logger?.LogDebug("Setting the native logger");
+ sentry_options_set_logger(cOptions, new sentry_logger_function_t(nativeLog), IntPtr.Zero);
}
else
{
- if (options.UnityInfo.IL2CPP)
- {
- options.DiagnosticLogger.LogDebug($"{(_logger is null ? "Setting a" : "Replacing the")} native logger");
- _logger = options.DiagnosticLogger;
- sentry_options_set_logger(cOptions, new sentry_logger_function_t(nativeLog), IntPtr.Zero);
- }
- else
- {
- options.DiagnosticLogger.LogInfo("Passing the native logs back to the C# layer is not supported on Mono - skipping native logger.");
- }
+ Logger?.LogInfo("Passing the native logs back to the C# layer is not supported on Mono - skipping native logger.");
}
- options.DiagnosticLogger?.LogDebug("Initializing sentry native");
+ Logger?.LogDebug("Initializing sentry native");
return 0 == sentry_init(cOptions);
}
@@ -169,11 +165,6 @@ internal static string GetCacheDirectory(SentryUnityOptions options)
[DllImport(SentryLib)]
private static extern void sentry_options_set_logger(IntPtr options, sentry_logger_function_t logger, IntPtr userData);
- // The logger we should forward native messages to. This is referenced by nativeLog() which in turn for.
- private static IDiagnosticLogger? _logger;
- private static bool _useLibC = false;
- private static bool _isWindows = false;
-
// This method is called from the C library and forwards incoming messages to the currently set _logger.
[MonoPInvokeCallback(typeof(sentry_logger_function_t))]
private static void nativeLog(int cLevel, IntPtr format, IntPtr args, IntPtr userData)
@@ -190,7 +181,7 @@ private static void nativeLog(int cLevel, IntPtr format, IntPtr args, IntPtr use
private static void nativeLogImpl(int cLevel, IntPtr format, IntPtr args, IntPtr userData)
{
- var logger = _logger;
+ var logger = Logger;
if (logger is null || format == IntPtr.Zero || args == IntPtr.Zero)
{
return;
@@ -217,7 +208,7 @@ private static void nativeLogImpl(int cLevel, IntPtr format, IntPtr args, IntPtr
{
// We cannot access C var-arg (va_list) in c# thus we pass it back to vsnprintf to do the formatting.
// For Linux and PlayStation, we must make a copy of the VaList to be able to pass it back...
- if (_useLibC)
+ if (UseLibC)
{
var argsStruct = Marshal.PtrToStructure(args);
var formattedLength = 0;
@@ -278,7 +269,7 @@ private static int vsnprintf(IntPtr buffer, UIntPtr bufferSize, IntPtr format, I
#if SENTRY_NATIVE_PLAYSTATION || SENTRY_NATIVE_SWITCH
return vsnprintf_sentry(buffer, bufferSize, format, args);
#else
- return _isWindows
+ return IsWindows
? vsnprintf_windows(buffer, bufferSize, format, args)
: vsnprintf_linux(buffer, bufferSize, format, args);
#endif
diff --git a/src/Sentry.Unity.Native/SentryNativeSwitch.cs b/src/Sentry.Unity.Native/SentryNativeSwitch.cs
index 72e6f6264..0f18277b2 100644
--- a/src/Sentry.Unity.Native/SentryNativeSwitch.cs
+++ b/src/Sentry.Unity.Native/SentryNativeSwitch.cs
@@ -36,7 +36,7 @@ public static class SentryNativeSwitch
/// The Sentry Unity options to use.
public static void Configure(SentryUnityOptions options) =>
Configure(options, ApplicationAdapter.Instance.Platform);
-
+
// For testing
internal static void Configure(SentryUnityOptions options, RuntimePlatform platform)
{
@@ -50,18 +50,18 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf
if (options.Il2CppLineNumberSupportEnabled)
{
options.Il2CppLineNumberSupportEnabled = false;
- options.DiagnosticLogger?.LogWarning("IL2CPP line number support is not available on Nintendo Switch - disabling.");
+ Logger?.LogWarning("IL2CPP line number support is not available on Nintendo Switch - disabling.");
}
if (options.AutoSessionTracking)
{
- options.DiagnosticLogger?.LogDebug("Disabling automatic session tracking on Switch due to limited file access.");
+ Logger?.LogDebug("Disabling automatic session tracking on Switch due to limited file access.");
options.AutoSessionTracking = false;
}
if (options.BackgroundWorker is null)
{
- options.DiagnosticLogger?.LogDebug("Setting WebBackgroundWorker as background.");
+ Logger?.LogDebug("Setting WebBackgroundWorker as background.");
options.BackgroundWorker = new WebBackgroundWorker(options, SentryMonoBehaviour.Instance);
}
@@ -72,11 +72,11 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf
return;
}
- options.DiagnosticLogger?.LogDebug("Mounting temporary storage for sentry-switch.");
+ Logger?.LogDebug("Mounting temporary storage for sentry-switch.");
if (sentry_switch_utils_mount() != 1)
{
- options.DiagnosticLogger?.LogError(
+ Logger?.LogError(
"Failed to mount temporary storage - Native scope sync will be disabled. " +
"Ensure 'TemporaryStorageSize' is set in the '.nmeta file'.");
return;
@@ -85,38 +85,38 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf
var cachePath = Marshal.PtrToStringAnsi(sentry_switch_utils_get_cache_path());
if (string.IsNullOrEmpty(cachePath))
{
- options.DiagnosticLogger?.LogError("Failed to get cache path from mounted storage - Native scope sync will be disabled.");
+ Logger?.LogError("Failed to get cache path from mounted storage - Native scope sync will be disabled.");
return;
}
- options.DiagnosticLogger?.LogDebug("Setting native cache directory: {0}", cachePath);
+ Logger?.LogDebug("Setting native cache directory: {0}", cachePath);
options.CacheDirectoryPath = cachePath;
try
{
- options.DiagnosticLogger?.LogDebug("Initializing the native SDK.");
+ Logger?.LogDebug("Initializing the native SDK.");
if (!SentryNativeBridge.Init(options))
{
- options.DiagnosticLogger?.LogError("Failed to initialize sentry-switch - Native scope sync will be disabled.");
+ Logger?.LogError("Failed to initialize sentry-switch - Native scope sync will be disabled.");
sentry_switch_utils_unmount();
return;
}
}
catch (Exception e)
{
- options.DiagnosticLogger?.LogError(e, "Sentry native initialization failed - Native scope sync will be disabled.");
+ Logger?.LogError(e, "Sentry native initialization failed - Native scope sync will be disabled.");
sentry_switch_utils_unmount();
return;
}
ApplicationAdapter.Instance.Quitting += () =>
{
- options.DiagnosticLogger?.LogDebug("Closing the sentry-switch SDK.");
+ Logger?.LogDebug("Closing the sentry-switch SDK.");
SentryNativeBridge.Close();
sentry_switch_utils_unmount();
};
- options.DiagnosticLogger?.LogDebug("Setting up native scope sync.");
+ Logger?.LogDebug("Setting up native scope sync.");
options.ScopeObserver = new NativeScopeObserver(options);
options.EnableScopeSync = true;
options.NativeContextWriter = new NativeContextWriter();
@@ -126,7 +126,7 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf
var defaultUserId = Marshal.PtrToStringAnsi(defaultUserIdPtr);
if (!string.IsNullOrEmpty(defaultUserId))
{
- options.DiagnosticLogger?.LogDebug("Using Default User ID: {0}", defaultUserId);
+ Logger?.LogDebug("Using Default User ID: {0}", defaultUserId);
options.DefaultUserId = defaultUserId;
}
}
diff --git a/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs b/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs
index fae303c38..58ce488d4 100644
--- a/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs
+++ b/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs
@@ -13,6 +13,7 @@ namespace Sentry.Unity.iOS;
///
internal static class SentryCocoaBridgeProxy
{
+ private static IDiagnosticLogger? Logger;
public static bool IsEnabled() => SentryNativeBridgeIsEnabled() == 1;
public static bool Init(SentryUnityOptions options)
@@ -22,6 +23,8 @@ public static bool Init(SentryUnityOptions options)
return false;
}
+ Logger = options.DiagnosticLogger;
+
var cOptions = OptionsNew();
// Note: DSN is not null because options.IsValid() must have returned true for this to be called.
@@ -29,41 +32,41 @@ public static bool Init(SentryUnityOptions options)
if (options.Release is not null)
{
- options.DiagnosticLogger?.LogDebug("Setting Release: {0}", options.Release);
+ Logger?.LogDebug("Setting Release: {0}", options.Release);
OptionsSetString(cOptions, "release", options.Release);
}
if (options.Environment is not null)
{
- options.DiagnosticLogger?.LogDebug("Setting Environment: {0}", options.Environment);
+ Logger?.LogDebug("Setting Environment: {0}", options.Environment);
OptionsSetString(cOptions, "environment", options.Environment);
}
- options.DiagnosticLogger?.LogDebug("Setting Debug: {0}", options.Debug);
+ Logger?.LogDebug("Setting Debug: {0}", options.Debug);
OptionsSetInt(cOptions, "debug", options.Debug ? 1 : 0);
var diagnosticLevel = options.DiagnosticLevel.ToString().ToLowerInvariant();
- options.DiagnosticLogger?.LogDebug("Setting DiagnosticLevel: {0}", diagnosticLevel);
+ Logger?.LogDebug("Setting DiagnosticLevel: {0}", diagnosticLevel);
OptionsSetString(cOptions, "diagnosticLevel", diagnosticLevel);
- options.DiagnosticLogger?.LogDebug("Setting SendDefaultPii: {0}", options.SendDefaultPii);
+ Logger?.LogDebug("Setting SendDefaultPii: {0}", options.SendDefaultPii);
OptionsSetInt(cOptions, "sendDefaultPii", options.SendDefaultPii ? 1 : 0);
// macOS screenshots currently don't work, because there's no UIKit. Cocoa logs: "Sentry - info:: NO UIKit"
- // options.DiagnosticLogger?.LogDebug("Setting AttachScreenshot: {0}", options.AttachScreenshot);
+ // Logger?.LogDebug("Setting AttachScreenshot: {0}", options.AttachScreenshot);
// OptionsSetInt(cOptions, "attachScreenshot", options.AttachScreenshot ? 1 : 0);
OptionsSetInt(cOptions, "attachScreenshot", 0);
- options.DiagnosticLogger?.LogDebug("Setting MaxBreadcrumbs: {0}", options.MaxBreadcrumbs);
+ Logger?.LogDebug("Setting MaxBreadcrumbs: {0}", options.MaxBreadcrumbs);
OptionsSetInt(cOptions, "maxBreadcrumbs", options.MaxBreadcrumbs);
- options.DiagnosticLogger?.LogDebug("Setting MaxCacheItems: {0}", options.MaxCacheItems);
+ Logger?.LogDebug("Setting MaxCacheItems: {0}", options.MaxCacheItems);
OptionsSetInt(cOptions, "maxCacheItems", options.MaxCacheItems);
// See https://github.com/getsentry/sentry-unity/issues/1658
OptionsSetInt(cOptions, "enableNetworkBreadcrumbs", 0);
- options.DiagnosticLogger?.LogDebug("Setting EnableWatchdogTerminationTracking: {0}", options.IosWatchdogTerminationIntegrationEnabled);
+ Logger?.LogDebug("Setting EnableWatchdogTerminationTracking: {0}", options.IosWatchdogTerminationIntegrationEnabled);
OptionsSetInt(cOptions, "enableWatchdogTerminationTracking", options.IosWatchdogTerminationIntegrationEnabled ? 1 : 0);
var result = StartWithOptions(cOptions);
diff --git a/src/Sentry.Unity.iOS/SentryNativeCocoa.cs b/src/Sentry.Unity.iOS/SentryNativeCocoa.cs
index 7581c931a..566332d3e 100644
--- a/src/Sentry.Unity.iOS/SentryNativeCocoa.cs
+++ b/src/Sentry.Unity.iOS/SentryNativeCocoa.cs
@@ -10,6 +10,8 @@ namespace Sentry.Unity.iOS;
///
public static class SentryNativeCocoa
{
+ private static IDiagnosticLogger? Logger;
+
///
/// Configures the native support.
///
@@ -20,11 +22,12 @@ public static void Configure(SentryUnityOptions options) =>
// For testing
internal static void Configure(SentryUnityOptions options, RuntimePlatform platform)
{
- options.DiagnosticLogger?.LogInfo("Attempting to configure native support via the Cocoa SDK");
+ Logger = options.DiagnosticLogger;
+ Logger?.LogInfo("Attempting to configure native support via the Cocoa SDK");
if (!options.IsNativeSupportEnabled(platform))
{
- options.DiagnosticLogger?.LogDebug("Native support is disabled for: '{0}'", platform);
+ Logger?.LogDebug("Native support is disabled for: '{0}'", platform);
return;
}
@@ -32,11 +35,11 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf
{
if (SentryCocoaBridgeProxy.IsEnabled())
{
- options.DiagnosticLogger?.LogDebug("The native SDK is already initialized");
+ Logger?.LogDebug("The native SDK is already initialized");
}
else if (!SentryCocoaBridgeProxy.Init(options))
{
- options.DiagnosticLogger?.LogWarning("Failed to initialize the native SDK");
+ Logger?.LogWarning("Failed to initialize the native SDK");
return;
}
@@ -46,7 +49,7 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf
{
if (!SentryCocoaBridgeProxy.Init(options))
{
- options.DiagnosticLogger?.LogWarning("Failed to initialize the native SDK");
+ Logger?.LogWarning("Failed to initialize the native SDK");
return;
}
options.ScopeObserver = new NativeScopeObserver("macOS", options);
@@ -58,10 +61,10 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf
options.EnableScopeSync = true;
options.CrashedLastRun = () =>
{
- options.DiagnosticLogger?.LogDebug("Checking for 'CrashedLastRun'");
+ Logger?.LogDebug("Checking for 'CrashedLastRun'");
var crashedLastRun = SentryCocoaBridgeProxy.CrashedLastRun() == 1;
- options.DiagnosticLogger?.LogDebug("Native SDK reported: 'crashedLastRun': '{0}'", crashedLastRun);
+ Logger?.LogDebug("Native SDK reported: 'crashedLastRun': '{0}'", crashedLastRun);
return crashedLastRun;
};
@@ -73,7 +76,7 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf
if (string.IsNullOrEmpty(options.DefaultUserId))
{
// In case we can't get an installation ID we create one and sync that down to the native layer
- options.DiagnosticLogger?.LogDebug("Failed to fetch 'Installation ID' from the native SDK. Creating new 'Default User ID'.");
+ Logger?.LogDebug("Failed to fetch 'Installation ID' from the native SDK. Creating new 'Default User ID'.");
// We fall back to Unity's Analytics Session Info: https://docs.unity3d.com/ScriptReference/Analytics.AnalyticsSessionInfo-userId.html
// It's a randomly generated GUID that gets created immediately after installation helping
@@ -85,12 +88,12 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf
}
else
{
- options.DiagnosticLogger?.LogDebug("Failed to create new 'Default User ID'.");
+ Logger?.LogDebug("Failed to create new 'Default User ID'.");
}
}
}
- options.DiagnosticLogger?.LogInfo("Successfully configured the native SDK");
+ Logger?.LogInfo("Successfully configured the native SDK");
}
///
@@ -98,15 +101,15 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf
///
public static void Close(SentryUnityOptions options)
{
- options.DiagnosticLogger?.LogInfo("Attempting to close the Cocoa SDK");
+ Logger?.LogInfo("Attempting to close the Cocoa SDK");
if (!options.IsNativeSupportEnabled())
{
- options.DiagnosticLogger?.LogDebug("Cocoa Native Support is not enable. Skipping closing the Cocoa SDK");
+ Logger?.LogDebug("Cocoa Native Support is not enable. Skipping closing the Cocoa SDK");
return;
}
- options.DiagnosticLogger?.LogDebug("Closing the Cocoa SDK");
+ Logger?.LogDebug("Closing the Cocoa SDK");
SentryCocoaBridgeProxy.Close();
}
}
diff --git a/src/Sentry.Unity/Il2CppEventProcessor.cs b/src/Sentry.Unity/Il2CppEventProcessor.cs
index 44a09025b..2f0698ce6 100644
--- a/src/Sentry.Unity/Il2CppEventProcessor.cs
+++ b/src/Sentry.Unity/Il2CppEventProcessor.cs
@@ -29,7 +29,7 @@ public UnityIl2CppEventExceptionProcessor(SentryUnityOptions options)
public void Process(Exception incomingException, SentryEvent sentryEvent)
{
- Options.DiagnosticLogger?.LogDebug("Running Unity IL2CPP event exception processor on: Event {0}", sentryEvent.EventId);
+ Options.LogDebug("Running Unity IL2CPP event exception processor on: Event {0}", sentryEvent.EventId);
var sentryExceptions = sentryEvent.SentryExceptions;
if (sentryExceptions == null)
@@ -67,7 +67,7 @@ public void Process(Exception incomingException, SentryEvent sentryEvent)
var nativeStackTrace = GetNativeStackTrace(exception);
- Options.DiagnosticLogger?.LogDebug("NativeStackTrace Image: '{0}' (UUID: {1})", nativeStackTrace.ImageName, nativeStackTrace.ImageUuid);
+ Options.LogDebug("NativeStackTrace Image: '{0}' (UUID: {1})", nativeStackTrace.ImageName, nativeStackTrace.ImageUuid);
// Unity by definition only builds a single library which we add once to our list of debug images.
// We use this when we encounter stack frames with relative addresses.
@@ -84,7 +84,7 @@ public void Process(Exception incomingException, SentryEvent sentryEvent)
var eventLen = sentryStacktrace.Frames.Count;
if (nativeLen != eventLen)
{
- Options.DiagnosticLogger?.LogWarning(
+ Options.LogWarning(
"Native and sentry stack trace lengths don't match '({0} != {1})' - this may cause invalid stack traces.",
nativeLen, eventLen);
}
@@ -133,7 +133,7 @@ public void Process(Exception incomingException, SentryEvent sentryEvent)
{
if (mainImageUUID is null)
{
- Options.DiagnosticLogger?.LogWarning("Couldn't process stack trace - main image UUID reported as NULL by Unity");
+ Options.LogWarning("Couldn't process stack trace - main image UUID reported as NULL by Unity");
continue;
}
@@ -180,7 +180,7 @@ public void Process(Exception incomingException, SentryEvent sentryEvent)
}
}
- Options.DiagnosticLogger?.Log(logLevel, "Stack frame '{0}' at {1:X8} (originally {2:X8}) belongs to {3} {4}",
+ Options.Log(logLevel, "Stack frame '{0}' at {1:X8} (originally {2:X8}) belongs to {3} {4}",
null, frame.Function, instructionAddress, nativeFrame.ToInt64(), image.CodeFile, notes ?? "");
_ = usedImages.Add(image);
@@ -236,9 +236,9 @@ public DebugImageInfo(DebugImage image)
{
if (image.ImageSize is null)
{
- Options.DiagnosticLogger?.Log(SentryLevel.Debug,
+ Options.LogDebug(
"Skipping debug image '{0}' (CodeId {1} | DebugId: {2}) because its size is NULL",
- null, image.CodeFile, image.CodeId, image.DebugId);
+ image.CodeFile, image.CodeId, image.DebugId);
continue;
}
@@ -254,7 +254,7 @@ public DebugImageInfo(DebugImage image)
}
result.Insert(i, info);
- Options.DiagnosticLogger?.Log(SentryLevel.Debug,
+ Options.Log(SentryLevel.Debug,
"Found debug image '{0}' (CodeId {1} | DebugId: {2}) with addresses between {3:X8} and {4:X8}",
null, image.CodeFile, image.CodeId, image.DebugId, info.StartAddress, info.EndAddress);
}
diff --git a/src/Sentry.Unity/Integrations/AnrIntegration.cs b/src/Sentry.Unity/Integrations/AnrIntegration.cs
index 4de1ce203..21903f0b2 100644
--- a/src/Sentry.Unity/Integrations/AnrIntegration.cs
+++ b/src/Sentry.Unity/Integrations/AnrIntegration.cs
@@ -139,9 +139,9 @@ private void Run()
{
var reportThreshold = DetectionTimeoutMs / SleepIntervalMs;
- Logger?.Log(SentryLevel.Info,
+ Logger?.LogInfo(
"Starting an ANR WatchDog - detection timeout: {0} ms, check every {1} ms => report after {2} failed checks",
- null, DetectionTimeoutMs, SleepIntervalMs, reportThreshold);
+ DetectionTimeoutMs, SleepIntervalMs, reportThreshold);
while (!_stop)
{
@@ -165,7 +165,7 @@ private void Run()
}
catch (Exception e)
{
- Logger?.Log(SentryLevel.Error, "Exception in the ANR watchdog.", e);
+ Logger?.LogError(e, "Exception in the ANR watchdog.");
}
}
}
diff --git a/src/Sentry.Unity/Integrations/LifeCycleIntegration.cs b/src/Sentry.Unity/Integrations/LifeCycleIntegration.cs
index 1df774592..7112850df 100644
--- a/src/Sentry.Unity/Integrations/LifeCycleIntegration.cs
+++ b/src/Sentry.Unity/Integrations/LifeCycleIntegration.cs
@@ -47,7 +47,7 @@ public void Register(IHub hub, SentryOptions sentryOptions)
data: ForegroundData,
level: BreadcrumbLevel.Info));
- _options.DiagnosticLogger?.LogDebug("Resuming session.");
+ _options.LogDebug("Resuming session.");
hub.ResumeSession();
};
@@ -64,7 +64,7 @@ public void Register(IHub hub, SentryOptions sentryOptions)
data: BackgroundData,
level: BreadcrumbLevel.Info));
- _options.DiagnosticLogger?.LogDebug("Pausing session.");
+ _options.LogDebug("Pausing session.");
hub.PauseSession();
};
diff --git a/src/Sentry.Unity/Integrations/TraceGenerationIntegration.cs b/src/Sentry.Unity/Integrations/TraceGenerationIntegration.cs
index d43feede5..63e327f84 100644
--- a/src/Sentry.Unity/Integrations/TraceGenerationIntegration.cs
+++ b/src/Sentry.Unity/Integrations/TraceGenerationIntegration.cs
@@ -31,7 +31,7 @@ public void Register(IHub hub, SentryOptions sentryOptions)
// Create initial trace context if tracing is disabled or startup tracing is disabled
if (!isTracingEnabled || !options.AutoStartupTraces)
{
- options.DiagnosticLogger?.LogDebug("Startup. Creating new Trace.");
+ options.LogDebug("Startup. Creating new Trace.");
hub.ConfigureScope(scope => scope.SetPropagationContext(new SentryPropagationContext()));
}
}
diff --git a/src/Sentry.Unity/Integrations/UnityLogHandlerIntegration.cs b/src/Sentry.Unity/Integrations/UnityLogHandlerIntegration.cs
index fe1d39200..655b0284f 100644
--- a/src/Sentry.Unity/Integrations/UnityLogHandlerIntegration.cs
+++ b/src/Sentry.Unity/Integrations/UnityLogHandlerIntegration.cs
@@ -26,7 +26,7 @@ public void Register(IHub hub, SentryOptions sentryOptions)
// original handler loghandler and endlessly forward to itself
if (Debug.unityLogger.logHandler == this)
{
- _options.DiagnosticLogger?.LogWarning("UnityLogHandlerIntegration has already been registered.");
+ _options.LogWarning("UnityLogHandlerIntegration has already been registered.");
return;
}
diff --git a/src/Sentry.Unity/ScopeObserver.cs b/src/Sentry.Unity/ScopeObserver.cs
index 9055ff55e..556a83da4 100644
--- a/src/Sentry.Unity/ScopeObserver.cs
+++ b/src/Sentry.Unity/ScopeObserver.cs
@@ -1,3 +1,4 @@
+using Sentry.Extensibility;
using Sentry.Unity.Json;
namespace Sentry.Unity;
@@ -19,8 +20,7 @@ public ScopeObserver(
public void AddBreadcrumb(Breadcrumb breadcrumb)
{
- _options.DiagnosticLogger?.Log(SentryLevel.Debug,
- "{0} Scope Sync - Adding breadcrumb m:\"{1}\" l:\"{2}\"", null, _name,
+ _options.LogDebug("{0} Scope Sync - Adding breadcrumb m:\"{1}\" l:\"{2}\"", _name,
breadcrumb.Message, breadcrumb.Level);
AddBreadcrumbImpl(breadcrumb);
}
@@ -32,14 +32,12 @@ public void SetExtra(string key, object? value)
var serialized = value is null ? null : SafeSerializer.SerializeSafely(value);
if (value is not null && serialized is null)
{
- _options.DiagnosticLogger?.Log(SentryLevel.Warning,
- "{0} Scope Sync - SetExtra k:\"{1}\" v:\"{2}\" - value was serialized as null",
- null, _name, key, value);
+ _options.LogWarning("{0} Scope Sync - SetExtra k:\"{1}\" v:\"{2}\" - value was serialized as null",
+ _name, key, value);
}
else
{
- _options.DiagnosticLogger?.Log(SentryLevel.Debug,
- "{0} Scope Sync - Setting Extra k:\"{1}\" v:\"{2}\"", null, _name, key, value);
+ _options.LogDebug("{0} Scope Sync - Setting Extra k:\"{1}\" v:\"{2}\"", _name, key, value);
}
SetExtraImpl(key, serialized);
}
@@ -48,8 +46,7 @@ public void SetExtra(string key, object? value)
public void SetTag(string key, string value)
{
- _options.DiagnosticLogger?.Log(SentryLevel.Debug,
- "{0} Scope Sync - Setting Tag k:\"{1}\" v:\"{2}\"", null, _name, key, value);
+ _options.LogDebug("{0} Scope Sync - Setting Tag k:\"{1}\" v:\"{2}\"", _name, key, value);
SetTagImpl(key, value);
}
@@ -57,8 +54,7 @@ public void SetTag(string key, string value)
public void UnsetTag(string key)
{
- _options.DiagnosticLogger?.Log(
- SentryLevel.Debug, "{0} Scope Sync - Unsetting Tag k:\"{1}\"", null, _name, key);
+ _options.LogDebug("{0} Scope Sync - Unsetting Tag k:\"{1}\"", _name, key);
UnsetTagImpl(key);
}
@@ -68,14 +64,12 @@ public void SetUser(SentryUser? user)
{
if (user is null)
{
- _options.DiagnosticLogger?.Log(
- SentryLevel.Debug, "{0} Scope Sync - Unsetting User", null, _name);
+ _options.LogDebug("{0} Scope Sync - Unsetting User", _name);
UnsetUserImpl();
}
else
{
- _options.DiagnosticLogger?.Log(SentryLevel.Debug,
- "{0} Scope Sync - Setting User i:\"{1}\" n:\"{2}\"", null, _name, user.Id,
+ _options.LogDebug("{0} Scope Sync - Setting User i:\"{1}\" n:\"{2}\"", _name, user.Id,
user.Username);
SetUserImpl(user);
}
@@ -87,9 +81,7 @@ public void SetUser(SentryUser? user)
public void SetTrace(SentryId traceId, SpanId spanId)
{
- _options.DiagnosticLogger?.Log(
- SentryLevel.Debug, "{0} Scope Sync - Setting Trace traceId:{1} spanId:{2}", null,
- _name, traceId, spanId);
+ _options.LogDebug("{0} Scope Sync - Setting Trace traceId:{1} spanId:{2}", _name, traceId, spanId);
SetTraceImpl(traceId, spanId);
}
diff --git a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs
index d2d908b90..5c9386e6d 100644
--- a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs
+++ b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs
@@ -257,7 +257,7 @@ internal SentryUnityOptions ToSentryUnityOptions(
if (OptionsConfiguration != null)
{
- options.DiagnosticLogger?.LogDebug("OptionsConfiguration found. Calling configure.");
+ options.LogDebug("OptionsConfiguration found. Calling configure.");
OptionsConfiguration.Configure(options);
}
diff --git a/src/Sentry.Unity/SentryUnityOptions.cs b/src/Sentry.Unity/SentryUnityOptions.cs
index 736ee6c4f..7690ce845 100644
--- a/src/Sentry.Unity/SentryUnityOptions.cs
+++ b/src/Sentry.Unity/SentryUnityOptions.cs
@@ -345,11 +345,11 @@ internal string? DefaultUserId
_defaultUserId = value;
if (_defaultUserId is null)
{
- DiagnosticLogger?.LogWarning("Couldn't set the default user ID - the value is NULL.");
+ this.LogWarning("Couldn't set the default user ID - the value is NULL.");
}
else
{
- DiagnosticLogger?.LogDebug("Setting '{0}' as the default user ID.", _defaultUserId);
+ this.LogDebug("Setting '{0}' as the default user ID.", _defaultUserId);
}
}
}
diff --git a/src/Sentry.Unity/SentryUnityOptionsExtensions.cs b/src/Sentry.Unity/SentryUnityOptionsExtensions.cs
index bb3df576d..38652449e 100644
--- a/src/Sentry.Unity/SentryUnityOptionsExtensions.cs
+++ b/src/Sentry.Unity/SentryUnityOptionsExtensions.cs
@@ -23,7 +23,7 @@ internal static bool ShouldInitializeSdk(this SentryUnityOptions? options, IAppl
application ??= ApplicationAdapter.Instance;
if (!options!.CaptureInEditor && application.IsEditor)
{
- options.DiagnosticLogger?.LogInfo("Disabled while in the Editor.");
+ options.LogInfo("Disabled while in the Editor.");
return false;
}
@@ -34,14 +34,14 @@ 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'.");
+ options.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.");
+ options.LogWarning("No Sentry DSN configured. Sentry will be disabled.");
return false;
}
diff --git a/src/Sentry.Unity/SentryUnitySdk.cs b/src/Sentry.Unity/SentryUnitySdk.cs
index 5d741c9ad..5e957cdec 100644
--- a/src/Sentry.Unity/SentryUnitySdk.cs
+++ b/src/Sentry.Unity/SentryUnitySdk.cs
@@ -49,7 +49,7 @@ private SentryUnitySdk(SentryUnityOptions options)
{
if (t.Exception is not null)
{
- options.DiagnosticLogger?.LogWarning(
+ options.LogWarning(
"Failed to synchronize scope to the native SDK: {0}", t.Exception);
}
});
@@ -63,7 +63,7 @@ private SentryUnitySdk(SentryUnityOptions options)
public void Close()
{
- _options.DiagnosticLogger?.LogDebug("Closing the sentry-dotnet SDK");
+ _options.LogDebug("Closing the sentry-dotnet SDK");
try
{
ApplicationAdapter.Instance.Quitting -= Close;
@@ -74,8 +74,8 @@ public void Close()
}
catch (Exception ex)
{
- _options.DiagnosticLogger?.Log(SentryLevel.Warning,
- "Exception while closing the .NET SDK.", ex);
+ _options.LogWarning(ex,
+ "Exception while closing the .NET SDK.");
}
try
@@ -85,8 +85,8 @@ public void Close()
}
catch (Exception ex)
{
- _options.DiagnosticLogger?.Log(SentryLevel.Warning,
- "Exception while releasing the lockfile on the config directory.", ex);
+ _options.LogWarning(ex,
+ "Exception while releasing the lockfile on the config directory.");
}
}
@@ -96,13 +96,13 @@ public SentrySdk.CrashedLastRun CrashedLastRun()
{
if (ApplicationAdapter.Instance.Platform == RuntimePlatform.WebGLPlayer)
{
- _options.DiagnosticLogger?.LogDebug("Currently, the Sentry SDK for Unity provides no native support for WebGL." +
- "LastRunState is `Unknown`.");
+ _options.LogDebug("Currently, the Sentry SDK for Unity provides no native support for WebGL." +
+ "LastRunState is `Unknown`.");
}
else
{
- _options.DiagnosticLogger?.LogDebug("The SDK does not have a 'CrashedLastRun' set. " +
- "This might be due to a missing or disabled native integration.");
+ _options.LogDebug("The SDK does not have a 'CrashedLastRun' set. " +
+ "This might be due to a missing or disabled native integration.");
}
return SentrySdk.CrashedLastRun.Unknown;
@@ -171,8 +171,8 @@ internal static void SetUpWindowsPlayerCaching(SentryUnitySdk unitySdk, SentryUn
}
catch (Exception ex)
{
- options.DiagnosticLogger?.LogWarning("An exception was thrown while trying to " +
- "acquire a lockfile on the config directory: .NET event cache will be disabled.", ex);
+ options.LogWarning(ex, "An exception was thrown while trying to " +
+ "acquire a lockfile on the config directory: .NET event cache will be disabled.");
options.CacheDirectoryPath = null;
options.AutoSessionTracking = false;
}
@@ -199,7 +199,7 @@ internal static void AddIntegrations(SentryUnityOptions options)
}
else
{
- options.DiagnosticLogger?.LogWarning("Failed to find required IL2CPP methods - Skipping line number support");
+ options.LogWarning("Failed to find required IL2CPP methods - Skipping line number support");
}
}
}
@@ -214,14 +214,14 @@ internal static void ConfigureUnsupportedPlatformFallbacks(SentryUnityOptions op
// Requires file access, see https://github.com/getsentry/sentry-unity/issues/290#issuecomment-1163608988
if (options.AutoSessionTracking)
{
- options.DiagnosticLogger?.LogDebug("Platform support for automatic session tracking is unknown: disabling.");
+ options.LogDebug("Platform support for automatic session tracking is unknown: disabling.");
options.AutoSessionTracking = false;
}
// This is only provided on a best-effort basis for other than the explicitly supported platforms.
if (options.BackgroundWorker is null)
{
- options.DiagnosticLogger?.LogDebug("Platform support for background thread execution is unknown: using WebBackgroundWorker.");
+ options.LogDebug("Platform support for background thread execution is unknown: using WebBackgroundWorker.");
options.BackgroundWorker = new WebBackgroundWorker(options, SentryMonoBehaviour.Instance);
}
}
diff --git a/src/Sentry.Unity/UnityEventProcessor.cs b/src/Sentry.Unity/UnityEventProcessor.cs
index 1bdbff173..0274b8b13 100644
--- a/src/Sentry.Unity/UnityEventProcessor.cs
+++ b/src/Sentry.Unity/UnityEventProcessor.cs
@@ -62,7 +62,7 @@ private void SetEventContext(IEventLike sentryEvent)
}
catch (Exception exception)
{
- _sentryOptions.DiagnosticLogger?.LogError(exception: exception, "{0} processing failed.", nameof(SentryEvent));
+ _sentryOptions.LogError(exception, "{0} processing failed.", nameof(SentryEvent));
}
}
diff --git a/src/Sentry.Unity/UnityWebRequestTransport.cs b/src/Sentry.Unity/UnityWebRequestTransport.cs
index 49b1d333d..467a5f92f 100644
--- a/src/Sentry.Unity/UnityWebRequestTransport.cs
+++ b/src/Sentry.Unity/UnityWebRequestTransport.cs
@@ -91,7 +91,7 @@ private UnityWebRequest CreateWebRequest(HttpRequestMessage message)
{
if (www.result == UnityWebRequest.Result.ConnectionError)
{
- _options.DiagnosticLogger?.LogWarning("Failed to send request: {0}", www.error);
+ _options.LogWarning("Failed to send request: {0}", www.error);
return null;
}
@@ -108,7 +108,7 @@ private UnityWebRequest CreateWebRequest(HttpRequestMessage message)
}
catch (InvalidOperationException e)
{
- _options.DiagnosticLogger?.LogError(e, "Failed to extract response header: {0}", header.Key);
+ _options.LogError(e, "Failed to extract response header: {0}", header.Key);
}
}
response.Content = new StringContent(www.downloadHandler.text);
diff --git a/src/Sentry.Unity/ViewHierarchyEventProcessor.cs b/src/Sentry.Unity/ViewHierarchyEventProcessor.cs
index 9cf4ab9f0..1f2df0bc0 100644
--- a/src/Sentry.Unity/ViewHierarchyEventProcessor.cs
+++ b/src/Sentry.Unity/ViewHierarchyEventProcessor.cs
@@ -26,13 +26,13 @@ public ViewHierarchyEventProcessor(SentryUnityOptions sentryOptions)
{
if (!MainThreadData.IsMainThread())
{
- _options.DiagnosticLogger?.LogDebug("Hierarchy capture skipped. Can't capture hierarchy on other than the main thread.");
+ _options.LogDebug("Hierarchy capture skipped. Can't capture hierarchy on other than the main thread.");
return @event;
}
if (_options.BeforeCaptureViewHierarchyInternal?.Invoke(@event) is false)
{
- _options.DiagnosticLogger?.LogInfo("Hierarchy capture skipped by BeforeCaptureViewHierarchy callback.");
+ _options.LogInfo("Hierarchy capture skipped by BeforeCaptureViewHierarchy callback.");
return @event;
}
@@ -47,7 +47,7 @@ public ViewHierarchyEventProcessor(SentryUnityOptions sentryOptions)
if (viewHierarchy == null)
{
- _options.DiagnosticLogger?.LogInfo("View hierarchy discarded by BeforeSendViewHierarchy callback.");
+ _options.LogInfo("View hierarchy discarded by BeforeSendViewHierarchy callback.");
return @event;
}
}
diff --git a/src/Sentry.Unity/WebGL/SentryWebGL.cs b/src/Sentry.Unity/WebGL/SentryWebGL.cs
index 38050acff..fd3dca9de 100644
--- a/src/Sentry.Unity/WebGL/SentryWebGL.cs
+++ b/src/Sentry.Unity/WebGL/SentryWebGL.cs
@@ -15,7 +15,7 @@ public static class SentryWebGL
/// The Sentry Unity options to use.
public static void Configure(SentryUnityOptions options)
{
- options.DiagnosticLogger?.LogDebug("Updating configuration for Unity WebGL.");
+ options.LogDebug("Updating configuration for Unity WebGL.");
// Note: we need to use a custom background worker which actually doesn't work in the background
// because Unity doesn't support async (multithreading) yet. This may change in the future so let's watch
@@ -35,15 +35,15 @@ public static void Configure(SentryUnityOptions options)
if (options.AttachScreenshot)
{
options.AttachScreenshot = false;
- options.DiagnosticLogger?.LogWarning("Attaching screenshots is unsupported on WebGL - disabling. " +
- "Currently, it produces blank screenshots mid-frame.");
+ options.LogWarning("Attaching screenshots is unsupported on WebGL - disabling. " +
+ "Currently, it produces blank screenshots mid-frame.");
}
// On WebGL, the IL2CPP backend does not provide the API required to make the IL2CPP Event Processor work
if (options.Il2CppLineNumberSupportEnabled)
{
options.Il2CppLineNumberSupportEnabled = false;
- options.DiagnosticLogger?.LogWarning("IL2CPP line number support is unsupported on WebGL - disabling.");
+ options.LogWarning("IL2CPP line number support is unsupported on WebGL - disabling.");
}
// Use AnalyticsSessionInfo.userId as the default UserID
diff --git a/test/Scripts.Integration.Test/Scripts/SmokeTester.cs b/test/Scripts.Integration.Test/Scripts/SmokeTester.cs
index 501e408c3..3657b5039 100644
--- a/test/Scripts.Integration.Test/Scripts/SmokeTester.cs
+++ b/test/Scripts.Integration.Test/Scripts/SmokeTester.cs
@@ -321,7 +321,7 @@ private static void RemoveContext()
}
// CppPlugin.cpp
- [DllImport("__Internal")]
+ [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
private static extern void throw_cpp();
internal class TestHandler : HttpClientHandler