From 4c00864528571e370ebf0564cbba07bafd0737e9 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 29 Jan 2025 20:39:00 +0100 Subject: [PATCH 01/35] propagate during startup --- package-dev/Runtime/SentryInitialization.cs | 4 ++++ src/Sentry.Unity.Android/SentryJava.cs | 10 ++++++++++ .../SentryNativeAndroid.cs | 18 ++++++++++++++++++ .../TestSentryJava.cs | 1 + 4 files changed, 33 insertions(+) diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs index 97591140e..d5c1d839a 100644 --- a/package-dev/Runtime/SentryInitialization.cs +++ b/package-dev/Runtime/SentryInitialization.cs @@ -86,6 +86,10 @@ public static void Init() SentryUnity.Init(options); +#if SENTRY_NATIVE_ANDROID + SentryNativeAndroid.SetTraceId(options); +#endif + #if !SENTRY_WEBGL if (options.TracesSampleRate > 0.0f && options.AutoStartupTraces) { diff --git a/src/Sentry.Unity.Android/SentryJava.cs b/src/Sentry.Unity.Android/SentryJava.cs index 679be6d71..5409029d8 100644 --- a/src/Sentry.Unity.Android/SentryJava.cs +++ b/src/Sentry.Unity.Android/SentryJava.cs @@ -13,6 +13,7 @@ internal interface ISentryJava public string? GetInstallationId(IJniExecutor jniExecutor); public bool? CrashedLastRun(IJniExecutor jniExecutor); public void Close(IJniExecutor jniExecutor); + public void ContinueTrace(IJniExecutor jniExecutor, string traceId); public void WriteScope( IJniExecutor jniExecutor, int? GpuId, @@ -170,6 +171,15 @@ public void Close(IJniExecutor jniExecutor) }); } + public void ContinueTrace(IJniExecutor jniExecutor, string traceId) + { + jniExecutor.Run(() => + { + using var sentry = GetSentryJava(); + sentry.CallStatic("continueTrace", traceId, null); + }); + } + public void WriteScope( IJniExecutor jniExecutor, int? GpuId, diff --git a/src/Sentry.Unity.Android/SentryNativeAndroid.cs b/src/Sentry.Unity.Android/SentryNativeAndroid.cs index 1c6b2e705..0152cf67d 100644 --- a/src/Sentry.Unity.Android/SentryNativeAndroid.cs +++ b/src/Sentry.Unity.Android/SentryNativeAndroid.cs @@ -132,6 +132,24 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry options.DiagnosticLogger?.LogInfo("Successfully configured the Android SDK"); } + public static void SetTraceId(SentryUnityOptions options) + { + options.DiagnosticLogger?.LogInfo("Setting Trace ID"); + + var traceId = SentrySdk.GetTraceHeader()?.TraceId; + if (traceId is null) + { + options.DiagnosticLogger?.LogInfo("fucking trace id is null"); + } + else + { + options.DiagnosticLogger?.LogInfo("Setting the trace ID on the native layer {0}", traceId); + + JniExecutor ??= new JniExecutor(options.DiagnosticLogger); + SentryJava.ContinueTrace(JniExecutor, traceId.ToString()); + } + } + /// /// Closes the native Android support. /// diff --git a/test/Sentry.Unity.Android.Tests/TestSentryJava.cs b/test/Sentry.Unity.Android.Tests/TestSentryJava.cs index 16cb0fd97..678e5e371 100644 --- a/test/Sentry.Unity.Android.Tests/TestSentryJava.cs +++ b/test/Sentry.Unity.Android.Tests/TestSentryJava.cs @@ -19,6 +19,7 @@ public void Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan public bool? CrashedLastRun(IJniExecutor jniExecutor) => IsCrashedLastRun; public void Close(IJniExecutor jniExecutor) { } + public void ContinueTrace(IJniExecutor jniExecutor, string traceId) { } public void WriteScope( IJniExecutor jniExecutor, From 3dc1d67ebafea313c25ea2f456f93fb17034d291 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Fri, 7 Feb 2025 11:27:41 +0100 Subject: [PATCH 02/35] setting trace in java --- modules/sentry-java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sentry-java b/modules/sentry-java index 2de45ebb0..c8e5c3fef 160000 --- a/modules/sentry-java +++ b/modules/sentry-java @@ -1 +1 @@ -Subproject commit 2de45ebb088ed5802dcac00781cbaca7e54ed9d9 +Subproject commit c8e5c3fef077cdb0b4b2fa4344497d691a1bd2d4 From 59976fedfee3e54589542be6d0388d6581d32bb3 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 27 Feb 2025 11:22:00 +0100 Subject: [PATCH 03/35] bump --- modules/sentry-java | 2 +- src/Sentry.Unity.Android/SentryJava.cs | 9 +++++---- .../SentryNativeAndroid.cs | 18 ++++++++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/modules/sentry-java b/modules/sentry-java index af5d4aa36..d9d43ee7f 160000 --- a/modules/sentry-java +++ b/modules/sentry-java @@ -1 +1 @@ -Subproject commit af5d4aa3646ebbe8b85ab4d6993af1f919a7f280 +Subproject commit d9d43ee7f987f62f5e00106a50a8595fdab2b817 diff --git a/src/Sentry.Unity.Android/SentryJava.cs b/src/Sentry.Unity.Android/SentryJava.cs index 5409029d8..3f4ba638f 100644 --- a/src/Sentry.Unity.Android/SentryJava.cs +++ b/src/Sentry.Unity.Android/SentryJava.cs @@ -13,7 +13,7 @@ internal interface ISentryJava public string? GetInstallationId(IJniExecutor jniExecutor); public bool? CrashedLastRun(IJniExecutor jniExecutor); public void Close(IJniExecutor jniExecutor); - public void ContinueTrace(IJniExecutor jniExecutor, string traceId); + public void SetTrace(IJniExecutor jniExecutor, string traceId, string spanId); public void WriteScope( IJniExecutor jniExecutor, int? GpuId, @@ -45,6 +45,7 @@ public void WriteScope( internal class SentryJava : ISentryJava { private static AndroidJavaObject GetSentryJava() => new AndroidJavaClass("io.sentry.Sentry"); + private static AndroidJavaObject GetInternalSentryJava() => new AndroidJavaClass("io.sentry.InternalSentrySdk"); public bool IsEnabled(IJniExecutor jniExecutor, TimeSpan timeout) { @@ -171,12 +172,12 @@ public void Close(IJniExecutor jniExecutor) }); } - public void ContinueTrace(IJniExecutor jniExecutor, string traceId) + public void SetTrace(IJniExecutor jniExecutor, string traceId, string spanId) { jniExecutor.Run(() => { - using var sentry = GetSentryJava(); - sentry.CallStatic("continueTrace", traceId, null); + using var sentry = GetInternalSentryJava(); + sentry.CallStatic("setTrace", traceId, spanId); }); } diff --git a/src/Sentry.Unity.Android/SentryNativeAndroid.cs b/src/Sentry.Unity.Android/SentryNativeAndroid.cs index 0152cf67d..a9306be98 100644 --- a/src/Sentry.Unity.Android/SentryNativeAndroid.cs +++ b/src/Sentry.Unity.Android/SentryNativeAndroid.cs @@ -137,17 +137,23 @@ public static void SetTraceId(SentryUnityOptions options) options.DiagnosticLogger?.LogInfo("Setting Trace ID"); var traceId = SentrySdk.GetTraceHeader()?.TraceId; + var spanId = SentrySdk.GetTraceHeader()?.SpanId; if (traceId is null) { - options.DiagnosticLogger?.LogInfo("fucking trace id is null"); + options.DiagnosticLogger?.LogError("trace id is null"); + return; } - else - { - options.DiagnosticLogger?.LogInfo("Setting the trace ID on the native layer {0}", traceId); - JniExecutor ??= new JniExecutor(options.DiagnosticLogger); - SentryJava.ContinueTrace(JniExecutor, traceId.ToString()); + if (spanId is null) + { + options.DiagnosticLogger?.LogError("span id is null"); + return; } + + options.DiagnosticLogger?.LogInfo("Setting the trace ID on the native layer {0}", traceId); + + JniExecutor ??= new JniExecutor(options.DiagnosticLogger); + SentryJava.SetTrace(JniExecutor, traceId.ToString(), spanId.ToString()); } /// From 43b1486308cf6ca778d3d54c1075af1939cd3d76 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 27 Feb 2025 11:22:18 +0100 Subject: [PATCH 04/35] test --- test/Sentry.Unity.Android.Tests/TestSentryJava.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Sentry.Unity.Android.Tests/TestSentryJava.cs b/test/Sentry.Unity.Android.Tests/TestSentryJava.cs index 678e5e371..be1139782 100644 --- a/test/Sentry.Unity.Android.Tests/TestSentryJava.cs +++ b/test/Sentry.Unity.Android.Tests/TestSentryJava.cs @@ -19,7 +19,7 @@ public void Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan public bool? CrashedLastRun(IJniExecutor jniExecutor) => IsCrashedLastRun; public void Close(IJniExecutor jniExecutor) { } - public void ContinueTrace(IJniExecutor jniExecutor, string traceId) { } + public void SetTrace(IJniExecutor jniExecutor, string traceId, string spanId) { } public void WriteScope( IJniExecutor jniExecutor, From 63d5a25652c712a9e8f3aa18511aed21f8685082 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Fri, 28 Feb 2025 12:38:47 +0100 Subject: [PATCH 05/35] bumped java --- modules/sentry-java | 2 +- src/Sentry.Unity.Android/SentryJava.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/sentry-java b/modules/sentry-java index d9d43ee7f..f8f097aca 160000 --- a/modules/sentry-java +++ b/modules/sentry-java @@ -1 +1 @@ -Subproject commit d9d43ee7f987f62f5e00106a50a8595fdab2b817 +Subproject commit f8f097aca547c58d02def2a357131d7ce7262ace diff --git a/src/Sentry.Unity.Android/SentryJava.cs b/src/Sentry.Unity.Android/SentryJava.cs index 3f4ba638f..2601b1a01 100644 --- a/src/Sentry.Unity.Android/SentryJava.cs +++ b/src/Sentry.Unity.Android/SentryJava.cs @@ -45,7 +45,7 @@ public void WriteScope( internal class SentryJava : ISentryJava { private static AndroidJavaObject GetSentryJava() => new AndroidJavaClass("io.sentry.Sentry"); - private static AndroidJavaObject GetInternalSentryJava() => new AndroidJavaClass("io.sentry.InternalSentrySdk"); + private static AndroidJavaObject GetInternalSentryJava() => new AndroidJavaClass("io.sentry.android.core.InternalSentrySdk"); public bool IsEnabled(IJniExecutor jniExecutor, TimeSpan timeout) { @@ -177,7 +177,7 @@ public void SetTrace(IJniExecutor jniExecutor, string traceId, string spanId) jniExecutor.Run(() => { using var sentry = GetInternalSentryJava(); - sentry.CallStatic("setTrace", traceId, spanId); + sentry.CallStatic("setTrace", traceId, spanId, (Double?)null, (Double?)null); }); } From 18c23cc8d7c0a72b2293f9ddea378571d3527a1d Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 3 Mar 2025 14:37:01 +0100 Subject: [PATCH 06/35] bumped java --- modules/sentry-java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sentry-java b/modules/sentry-java index f8f097aca..158d6889e 160000 --- a/modules/sentry-java +++ b/modules/sentry-java @@ -1 +1 @@ -Subproject commit f8f097aca547c58d02def2a357131d7ce7262ace +Subproject commit 158d6889e5a1251c2dd5dc566869594f12c80004 From 85bf6575e7f0e75987637006acfe2e0c3cdb4a13 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 5 Mar 2025 17:46:01 +0100 Subject: [PATCH 07/35] use scope observer instead --- .../AndroidJavaScopeObserver.cs | 11 ++++++++++ src/Sentry.Unity.Android/SentryJava.cs | 11 ---------- .../SentryNativeAndroid.cs | 22 ++----------------- .../NativeScopeObserver.cs | 4 ++++ src/Sentry.Unity.iOS/NativeScopeObserver.cs | 4 ++++ src/Sentry.Unity/ScopeObserver.cs | 7 +++++- src/sentry-dotnet | 2 +- 7 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs b/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs index ef54bb937..93381d6ac 100644 --- a/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs +++ b/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs @@ -1,3 +1,4 @@ +using System; using UnityEngine; namespace Sentry.Unity.Android; @@ -16,6 +17,7 @@ public AndroidJavaScopeObserver(SentryOptions options, IJniExecutor jniExecutor) } private AndroidJavaObject GetSentryJava() => new AndroidJavaClass("io.sentry.Sentry"); + private static AndroidJavaObject GetInternalSentryJava() => new AndroidJavaClass("io.sentry.android.core.InternalSentrySdk"); public override void AddBreadcrumbImpl(Breadcrumb breadcrumb) { @@ -88,4 +90,13 @@ public override void UnsetUserImpl() sentry.CallStatic("setUser", null); }); } + + public override void SetTraceImpl(SentryId traceId, SpanId parentSpanId) + { + _jniExecutor.Run(() => + { + using var sentry = GetInternalSentryJava(); + sentry.CallStatic("setTrace", traceId.ToString(), parentSpanId.ToString(), (Double?)null, (Double?)null); + }); + } } diff --git a/src/Sentry.Unity.Android/SentryJava.cs b/src/Sentry.Unity.Android/SentryJava.cs index 2601b1a01..679be6d71 100644 --- a/src/Sentry.Unity.Android/SentryJava.cs +++ b/src/Sentry.Unity.Android/SentryJava.cs @@ -13,7 +13,6 @@ internal interface ISentryJava public string? GetInstallationId(IJniExecutor jniExecutor); public bool? CrashedLastRun(IJniExecutor jniExecutor); public void Close(IJniExecutor jniExecutor); - public void SetTrace(IJniExecutor jniExecutor, string traceId, string spanId); public void WriteScope( IJniExecutor jniExecutor, int? GpuId, @@ -45,7 +44,6 @@ public void WriteScope( internal class SentryJava : ISentryJava { private static AndroidJavaObject GetSentryJava() => new AndroidJavaClass("io.sentry.Sentry"); - private static AndroidJavaObject GetInternalSentryJava() => new AndroidJavaClass("io.sentry.android.core.InternalSentrySdk"); public bool IsEnabled(IJniExecutor jniExecutor, TimeSpan timeout) { @@ -172,15 +170,6 @@ public void Close(IJniExecutor jniExecutor) }); } - public void SetTrace(IJniExecutor jniExecutor, string traceId, string spanId) - { - jniExecutor.Run(() => - { - using var sentry = GetInternalSentryJava(); - sentry.CallStatic("setTrace", traceId, spanId, (Double?)null, (Double?)null); - }); - } - public void WriteScope( IJniExecutor jniExecutor, int? GpuId, diff --git a/src/Sentry.Unity.Android/SentryNativeAndroid.cs b/src/Sentry.Unity.Android/SentryNativeAndroid.cs index a9306be98..c4c1c7a10 100644 --- a/src/Sentry.Unity.Android/SentryNativeAndroid.cs +++ b/src/Sentry.Unity.Android/SentryNativeAndroid.cs @@ -134,26 +134,8 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry public static void SetTraceId(SentryUnityOptions options) { - options.DiagnosticLogger?.LogInfo("Setting Trace ID"); - - var traceId = SentrySdk.GetTraceHeader()?.TraceId; - var spanId = SentrySdk.GetTraceHeader()?.SpanId; - if (traceId is null) - { - options.DiagnosticLogger?.LogError("trace id is null"); - return; - } - - if (spanId is null) - { - options.DiagnosticLogger?.LogError("span id is null"); - return; - } - - options.DiagnosticLogger?.LogInfo("Setting the trace ID on the native layer {0}", traceId); - - JniExecutor ??= new JniExecutor(options.DiagnosticLogger); - SentryJava.SetTrace(JniExecutor, traceId.ToString(), spanId.ToString()); + options.DiagnosticLogger?.LogInfo("Setting new Trace"); + SentrySdk.ContinueTrace(SentryId.Create().ToString(), null); } /// diff --git a/src/Sentry.Unity.Native/NativeScopeObserver.cs b/src/Sentry.Unity.Native/NativeScopeObserver.cs index 5075febca..8a3ef4306 100644 --- a/src/Sentry.Unity.Native/NativeScopeObserver.cs +++ b/src/Sentry.Unity.Native/NativeScopeObserver.cs @@ -40,6 +40,10 @@ public override void SetUserImpl(SentryUser user) } public override void UnsetUserImpl() => C.sentry_remove_user(); + public override void SetTraceImpl(SentryId traceId, SpanId parentSpanId) + { + throw new NotImplementedException(); + } private static string GetTimestamp(DateTimeOffset timestamp) => // "o": Using ISO 8601 to make sure the timestamp makes it to the bridge correctly. diff --git a/src/Sentry.Unity.iOS/NativeScopeObserver.cs b/src/Sentry.Unity.iOS/NativeScopeObserver.cs index f46d69bdf..36de7fe3e 100644 --- a/src/Sentry.Unity.iOS/NativeScopeObserver.cs +++ b/src/Sentry.Unity.iOS/NativeScopeObserver.cs @@ -25,6 +25,10 @@ public override void SetUserImpl(SentryUser user) => SentryCocoaBridgeProxy.SetUser(user.Email, user.Id, user.IpAddress, user.Username); public override void UnsetUserImpl() => SentryCocoaBridgeProxy.UnsetUser(); + public override void SetTraceImpl(SentryId traceId, SpanId parentSpanId) + { + throw new NotImplementedException(); + } internal static string GetTimestamp(DateTimeOffset timestamp) => // "o": Using ISO 8601 to make sure the timestamp makes it to the bridge correctly. diff --git a/src/Sentry.Unity/ScopeObserver.cs b/src/Sentry.Unity/ScopeObserver.cs index 1a7f0996b..b19c66e97 100644 --- a/src/Sentry.Unity/ScopeObserver.cs +++ b/src/Sentry.Unity/ScopeObserver.cs @@ -3,7 +3,7 @@ namespace Sentry.Unity; /// -/// Sentry Unity Scope Observer wrapper for the common behaviour accross platforms. +/// Sentry Unity Scope Observer wrapper for the common behaviour across platforms. /// public abstract class ScopeObserver : IScopeObserver { @@ -84,4 +84,9 @@ public void SetUser(SentryUser? user) public abstract void SetUserImpl(SentryUser user); public abstract void UnsetUserImpl(); + + public abstract void SetTraceImpl(SentryId traceId, SpanId parentSpanId); + + public void SetTrace(SentryId traceId, SpanId parentSpanId) + => SetTraceImpl(traceId, parentSpanId); } diff --git a/src/sentry-dotnet b/src/sentry-dotnet index 05ac853ae..9e7c42325 160000 --- a/src/sentry-dotnet +++ b/src/sentry-dotnet @@ -1 +1 @@ -Subproject commit 05ac853ae29c10bd76db0e382777a7122bd6b171 +Subproject commit 9e7c42325254da768ed288a7be07efb3a27c09d5 From 882eed93a4d7800265959064b428be83e3981ab4 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Fri, 28 Mar 2025 23:58:01 +0100 Subject: [PATCH 08/35] updated trace generation and sync --- src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs | 1 + src/Sentry.Unity.Android/SentryNativeAndroid.cs | 6 ------ .../Android/AndroidManifestConfiguration.cs | 4 ++++ src/Sentry.Unity/ScopeObserver.cs | 11 ++++++++--- src/Sentry.Unity/SentryUnitySDK.cs | 5 +++++ src/sentry-dotnet | 2 +- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs b/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs index 93381d6ac..f56b7060d 100644 --- a/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs +++ b/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs @@ -96,6 +96,7 @@ public override void SetTraceImpl(SentryId traceId, SpanId parentSpanId) _jniExecutor.Run(() => { using var sentry = GetInternalSentryJava(); + // We have to explicitly cast to `(Double?)` sentry.CallStatic("setTrace", traceId.ToString(), parentSpanId.ToString(), (Double?)null, (Double?)null); }); } diff --git a/src/Sentry.Unity.Android/SentryNativeAndroid.cs b/src/Sentry.Unity.Android/SentryNativeAndroid.cs index 4734c7acf..1d2122939 100644 --- a/src/Sentry.Unity.Android/SentryNativeAndroid.cs +++ b/src/Sentry.Unity.Android/SentryNativeAndroid.cs @@ -131,12 +131,6 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry options.DiagnosticLogger?.LogInfo("Successfully configured the Android SDK"); } - public static void SetTraceId(SentryUnityOptions options) - { - options.DiagnosticLogger?.LogInfo("Setting new Trace"); - SentrySdk.ContinueTrace(SentryId.Create().ToString(), null); - } - /// /// Closes the native Android support. /// diff --git a/src/Sentry.Unity.Editor/Android/AndroidManifestConfiguration.cs b/src/Sentry.Unity.Editor/Android/AndroidManifestConfiguration.cs index c61de02b9..5042f1026 100644 --- a/src/Sentry.Unity.Editor/Android/AndroidManifestConfiguration.cs +++ b/src/Sentry.Unity.Editor/Android/AndroidManifestConfiguration.cs @@ -206,6 +206,7 @@ internal void ModifyManifest(string basePath) // Disabling the native in favor of the C# layer for now androidManifest.SetNdkEnabled(_options.NdkIntegrationEnabled); androidManifest.SetNdkScopeSync(_options.NdkScopeSyncEnabled); + androidManifest.SetAutoTraceIdGeneration(false); androidManifest.SetAutoSessionTracking(false); androidManifest.SetAutoAppLifecycleBreadcrumbs(false); androidManifest.SetAnr(false); @@ -483,6 +484,9 @@ internal void SetNdkEnabled(bool enableNdk) internal void SetNdkScopeSync(bool enableNdkScopeSync) => SetMetaData($"{SentryPrefix}.ndk.scope-sync.enable", enableNdkScopeSync.ToString()); + public void SetAutoTraceIdGeneration(bool enableAutoTraceIdGeneration) + => SetMetaData($"{SentryPrefix}.traces.enable-auto-id-generation", enableAutoTraceIdGeneration.ToString()); + internal void SetDebug(bool debug) => SetMetaData($"{SentryPrefix}.debug", debug ? "true" : "false"); // https://github.com/getsentry/sentry-java/blob/db4dfc92f202b1cefc48d019fdabe24d487db923/sentry/src/main/java/io/sentry/SentryLevel.java#L4-L9 diff --git a/src/Sentry.Unity/ScopeObserver.cs b/src/Sentry.Unity/ScopeObserver.cs index b19c66e97..0a416fcdb 100644 --- a/src/Sentry.Unity/ScopeObserver.cs +++ b/src/Sentry.Unity/ScopeObserver.cs @@ -85,8 +85,13 @@ public void SetUser(SentryUser? user) public abstract void UnsetUserImpl(); - public abstract void SetTraceImpl(SentryId traceId, SpanId parentSpanId); - public void SetTrace(SentryId traceId, SpanId parentSpanId) - => SetTraceImpl(traceId, parentSpanId); + { + _options.DiagnosticLogger?.Log( + SentryLevel.Debug,"{0} Scope Sync - Setting Trace traceId:{1} parentSpanId:{2}", null, + _name, traceId, parentSpanId); + SetTraceImpl(traceId, parentSpanId); + } + + public abstract void SetTraceImpl(SentryId traceId, SpanId parentSpanId); } diff --git a/src/Sentry.Unity/SentryUnitySDK.cs b/src/Sentry.Unity/SentryUnitySDK.cs index 419a8e8d0..3f692ba60 100644 --- a/src/Sentry.Unity/SentryUnitySDK.cs +++ b/src/Sentry.Unity/SentryUnitySDK.cs @@ -51,6 +51,11 @@ private SentryUnitySdk(SentryUnityOptions options) unitySdk._dotnetSdk = SentrySdk.Init(options); + // For now, we're creating a new trace after initializing to be able to tie errors and crashes together on all + // layers. To be able to regenerate new traces based on some mechanism, this will move into some sort of + // integration i.e. scene manager. + InternalSentrySdk.SetTrace(SentryId.Create(), SpanId.Create()); + if (options.NativeContextWriter is { } contextWriter) { SentrySdk.ConfigureScope((scope) => diff --git a/src/sentry-dotnet b/src/sentry-dotnet index 65facbeeb..ba8eebd26 160000 --- a/src/sentry-dotnet +++ b/src/sentry-dotnet @@ -1 +1 @@ -Subproject commit 65facbeeb16dcd0b329de269d9c191a334164728 +Subproject commit ba8eebd26a701f30e8bc1ff0ae0b56c82c7977f5 From 84d971c4b2edb2b74b13e08fa0d5e2996fa60293 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 31 Mar 2025 11:27:56 +0200 Subject: [PATCH 09/35] removed redundant android trace start --- package-dev/Runtime/SentryInitialization.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs index f7d62ef5f..229e68fac 100644 --- a/package-dev/Runtime/SentryInitialization.cs +++ b/package-dev/Runtime/SentryInitialization.cs @@ -68,9 +68,6 @@ public static void Init() SetupNativeSdk(options, unityInfo); SentryUnity.Init(options); -#if SENTRY_NATIVE_ANDROID - SentryNativeAndroid.SetTraceId(options); -#endif SetupStartupTracing(options); } else From 559deab4f0a4cea15b8032b460431d5ae67e1ad9 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 31 Mar 2025 11:29:00 +0200 Subject: [PATCH 10/35] . --- package-dev/Runtime/SentryInitialization.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs index 229e68fac..918cc2165 100644 --- a/package-dev/Runtime/SentryInitialization.cs +++ b/package-dev/Runtime/SentryInitialization.cs @@ -67,7 +67,6 @@ public static void Init() // Configures scope sync and (by default) initializes the native SDK. SetupNativeSdk(options, unityInfo); SentryUnity.Init(options); - SetupStartupTracing(options); } else From e708ade37ee0c0116053dd6369d88c50c8286763 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 31 Mar 2025 11:30:27 +0200 Subject: [PATCH 11/35] native and ios scope observers are not there yet --- src/Sentry.Unity.Native/NativeScopeObserver.cs | 2 +- src/Sentry.Unity.iOS/NativeScopeObserver.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sentry.Unity.Native/NativeScopeObserver.cs b/src/Sentry.Unity.Native/NativeScopeObserver.cs index 8a3ef4306..e9c15797e 100644 --- a/src/Sentry.Unity.Native/NativeScopeObserver.cs +++ b/src/Sentry.Unity.Native/NativeScopeObserver.cs @@ -42,7 +42,7 @@ public override void SetUserImpl(SentryUser user) public override void UnsetUserImpl() => C.sentry_remove_user(); public override void SetTraceImpl(SentryId traceId, SpanId parentSpanId) { - throw new NotImplementedException(); + // TODO: Needs to be implemented } private static string GetTimestamp(DateTimeOffset timestamp) => diff --git a/src/Sentry.Unity.iOS/NativeScopeObserver.cs b/src/Sentry.Unity.iOS/NativeScopeObserver.cs index 36de7fe3e..862eb8ef8 100644 --- a/src/Sentry.Unity.iOS/NativeScopeObserver.cs +++ b/src/Sentry.Unity.iOS/NativeScopeObserver.cs @@ -27,7 +27,7 @@ public override void SetUserImpl(SentryUser user) => public override void UnsetUserImpl() => SentryCocoaBridgeProxy.UnsetUser(); public override void SetTraceImpl(SentryId traceId, SpanId parentSpanId) { - throw new NotImplementedException(); + // TODO: Needs to be implemented } internal static string GetTimestamp(DateTimeOffset timestamp) => From 165b425751351d3f2a137b4cfec8090e3bce6e9f Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Mon, 31 Mar 2025 09:33:36 +0000 Subject: [PATCH 12/35] Format code --- src/Sentry.Unity/ScopeObserver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sentry.Unity/ScopeObserver.cs b/src/Sentry.Unity/ScopeObserver.cs index 0a416fcdb..fb5e155d0 100644 --- a/src/Sentry.Unity/ScopeObserver.cs +++ b/src/Sentry.Unity/ScopeObserver.cs @@ -88,7 +88,7 @@ public void SetUser(SentryUser? user) public void SetTrace(SentryId traceId, SpanId parentSpanId) { _options.DiagnosticLogger?.Log( - SentryLevel.Debug,"{0} Scope Sync - Setting Trace traceId:{1} parentSpanId:{2}", null, + SentryLevel.Debug, "{0} Scope Sync - Setting Trace traceId:{1} parentSpanId:{2}", null, _name, traceId, parentSpanId); SetTraceImpl(traceId, parentSpanId); } From 256a7210b0e58f8db47602c8ad8e9e3d6e9d37cc Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 31 Mar 2025 11:36:40 +0200 Subject: [PATCH 13/35] bump .NET to get the scope observer --- src/sentry-dotnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry-dotnet b/src/sentry-dotnet index ab208ce33..ba8eebd26 160000 --- a/src/sentry-dotnet +++ b/src/sentry-dotnet @@ -1 +1 @@ -Subproject commit ab208ce33a4888fdce954cf3f2b1c4e2633b55bb +Subproject commit ba8eebd26a701f30e8bc1ff0ae0b56c82c7977f5 From 929073c7004b8d2ce8a79c3647a19617b2886b02 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 31 Mar 2025 11:48:46 +0200 Subject: [PATCH 14/35] starting a trace --- src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs | 5 +++++ src/Sentry.Unity.Native/NativeScopeObserver.cs | 3 +++ src/Sentry.Unity.iOS/NativeScopeObserver.cs | 5 +++++ src/Sentry.Unity/NativeUtils/CFunctions.cs | 3 +++ src/Sentry.Unity/ScopeObserver.cs | 12 +++++++++++- src/Sentry.Unity/SentryUnitySDK.cs | 5 +++++ 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs b/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs index ef54bb937..f9ef36604 100644 --- a/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs +++ b/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs @@ -88,4 +88,9 @@ public override void UnsetUserImpl() sentry.CallStatic("setUser", null); }); } + + public override void SetTraceImpl(SentryId traceId, SpanId parentSpanId) + { + // Todo: Needs to be implemented + } } diff --git a/src/Sentry.Unity.Native/NativeScopeObserver.cs b/src/Sentry.Unity.Native/NativeScopeObserver.cs index 5075febca..6b8b15029 100644 --- a/src/Sentry.Unity.Native/NativeScopeObserver.cs +++ b/src/Sentry.Unity.Native/NativeScopeObserver.cs @@ -41,6 +41,9 @@ public override void SetUserImpl(SentryUser user) public override void UnsetUserImpl() => C.sentry_remove_user(); + public override void SetTraceImpl(SentryId traceId, SpanId parentSpanId) => + C.sentry_set_trace(traceId.ToString(), parentSpanId.ToString()); + private static string GetTimestamp(DateTimeOffset timestamp) => // "o": Using ISO 8601 to make sure the timestamp makes it to the bridge correctly. // https://docs.microsoft.com/en-gb/dotnet/standard/base-types/standard-date-and-time-format-strings#Roundtrip diff --git a/src/Sentry.Unity.iOS/NativeScopeObserver.cs b/src/Sentry.Unity.iOS/NativeScopeObserver.cs index f46d69bdf..d4b39dd2c 100644 --- a/src/Sentry.Unity.iOS/NativeScopeObserver.cs +++ b/src/Sentry.Unity.iOS/NativeScopeObserver.cs @@ -26,6 +26,11 @@ public override void SetUserImpl(SentryUser user) => public override void UnsetUserImpl() => SentryCocoaBridgeProxy.UnsetUser(); + public override void SetTraceImpl(SentryId traceId, SpanId parentSpanId) + { + // Todo: Needs to be implemented + } + internal static string GetTimestamp(DateTimeOffset timestamp) => // "o": Using ISO 8601 to make sure the timestamp makes it to the bridge correctly. // https://docs.microsoft.com/en-gb/dotnet/standard/base-types/standard-date-and-time-format-strings#Roundtrip diff --git a/src/Sentry.Unity/NativeUtils/CFunctions.cs b/src/Sentry.Unity/NativeUtils/CFunctions.cs index 3af0f1b69..76088e02b 100644 --- a/src/Sentry.Unity/NativeUtils/CFunctions.cs +++ b/src/Sentry.Unity/NativeUtils/CFunctions.cs @@ -148,6 +148,9 @@ internal static void SetValueIfNotNull(sentry_value_t obj, string key, double? v [DllImport("sentry")] internal static extern void sentry_remove_extra(string key); + [DllImport("sentry")] + internal static extern void sentry_set_trace(string traceId, string parentSpanId); + internal static readonly Lazy> DebugImages = new(LoadDebugImages); private static IEnumerable LoadDebugImages() diff --git a/src/Sentry.Unity/ScopeObserver.cs b/src/Sentry.Unity/ScopeObserver.cs index 1a7f0996b..0abf151e2 100644 --- a/src/Sentry.Unity/ScopeObserver.cs +++ b/src/Sentry.Unity/ScopeObserver.cs @@ -3,7 +3,7 @@ namespace Sentry.Unity; /// -/// Sentry Unity Scope Observer wrapper for the common behaviour accross platforms. +/// Sentry Unity Scope Observer wrapper for the common behaviour across platforms. /// public abstract class ScopeObserver : IScopeObserver { @@ -84,4 +84,14 @@ public void SetUser(SentryUser? user) public abstract void SetUserImpl(SentryUser user); public abstract void UnsetUserImpl(); + + public void SetTrace(SentryId traceId, SpanId parentSpanId) + { + _options.DiagnosticLogger?.Log( + SentryLevel.Debug, "{0} Scope Sync - Setting Trace traceId:{1} parentSpanId:{2}", null, + _name, traceId, parentSpanId); + SetTraceImpl(traceId, parentSpanId); + } + + public abstract void SetTraceImpl(SentryId traceId, SpanId parentSpanId); } diff --git a/src/Sentry.Unity/SentryUnitySDK.cs b/src/Sentry.Unity/SentryUnitySDK.cs index 419a8e8d0..3f692ba60 100644 --- a/src/Sentry.Unity/SentryUnitySDK.cs +++ b/src/Sentry.Unity/SentryUnitySDK.cs @@ -51,6 +51,11 @@ private SentryUnitySdk(SentryUnityOptions options) unitySdk._dotnetSdk = SentrySdk.Init(options); + // For now, we're creating a new trace after initializing to be able to tie errors and crashes together on all + // layers. To be able to regenerate new traces based on some mechanism, this will move into some sort of + // integration i.e. scene manager. + InternalSentrySdk.SetTrace(SentryId.Create(), SpanId.Create()); + if (options.NativeContextWriter is { } contextWriter) { SentrySdk.ConfigureScope((scope) => From de43fd53cf64986b4e7ddc825200a7bb3e289096 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 31 Mar 2025 11:54:17 +0200 Subject: [PATCH 15/35] Updated CHANGELOG.md --- CHANGELOG.md | 4 ++++ src/Sentry.Unity.Native/NativeScopeObserver.cs | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 710930bd0..0a083643e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Features + +- When running on Windows or Linux, the SDK now links errors and events originating on different layers (managed, native errors) via `trace ID` ([#2089](https://github.com/getsentry/sentry-unity/pull/2089)) + ### Dependencies - Bump Cocoa SDK from v8.45.0 to v8.48.0 ([#2063](https://github.com/getsentry/sentry-unity/pull/2063), [#2071](https://github.com/getsentry/sentry-unity/pull/2071)) diff --git a/src/Sentry.Unity.Native/NativeScopeObserver.cs b/src/Sentry.Unity.Native/NativeScopeObserver.cs index cc1e024f8..6b8b15029 100644 --- a/src/Sentry.Unity.Native/NativeScopeObserver.cs +++ b/src/Sentry.Unity.Native/NativeScopeObserver.cs @@ -40,10 +40,6 @@ public override void SetUserImpl(SentryUser user) } public override void UnsetUserImpl() => C.sentry_remove_user(); - public override void SetTraceImpl(SentryId traceId, SpanId parentSpanId) - { - // TODO: Needs to be implemented - } public override void SetTraceImpl(SentryId traceId, SpanId parentSpanId) => C.sentry_set_trace(traceId.ToString(), parentSpanId.ToString()); From 9aeb52ebd70259691da42ba72d2c9d93cc0daabb Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 31 Mar 2025 11:55:10 +0200 Subject: [PATCH 16/35] Updated CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 710930bd0..58121096b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Features + +- When running on Android, the SDK now links errors and events originating on different layers (managed, native errors) via `trace ID` ([#1997](https://github.com/getsentry/sentry-unity/pull/1997)) + ### Dependencies - Bump Cocoa SDK from v8.45.0 to v8.48.0 ([#2063](https://github.com/getsentry/sentry-unity/pull/2063), [#2071](https://github.com/getsentry/sentry-unity/pull/2071)) From f2cfb1a3051376d5bd1359eabb3e4a02baa6bada Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 2 Apr 2025 15:06:58 +0200 Subject: [PATCH 17/35] use internal API --- src/Sentry.Unity/SentryUnitySDK.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sentry.Unity/SentryUnitySDK.cs b/src/Sentry.Unity/SentryUnitySDK.cs index 3f692ba60..fb17efe57 100644 --- a/src/Sentry.Unity/SentryUnitySDK.cs +++ b/src/Sentry.Unity/SentryUnitySDK.cs @@ -54,7 +54,7 @@ private SentryUnitySdk(SentryUnityOptions options) // For now, we're creating a new trace after initializing to be able to tie errors and crashes together on all // layers. To be able to regenerate new traces based on some mechanism, this will move into some sort of // integration i.e. scene manager. - InternalSentrySdk.SetTrace(SentryId.Create(), SpanId.Create()); + SentrySdk.SetTrace(SentryId.Create(), SpanId.Create()); if (options.NativeContextWriter is { } contextWriter) { From bb2a09a5ddaf32b281cc4b84c700fde1f7e9ad03 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 9 Apr 2025 11:57:07 +0200 Subject: [PATCH 18/35] sync for macOS --- .../Plugins/macOS/SentryNativeBridge.m | 24 +++++++++++++++++++ .../SentryCocoaBridgeProxy.cs | 3 +++ 2 files changed, 27 insertions(+) diff --git a/package-dev/Plugins/macOS/SentryNativeBridge.m b/package-dev/Plugins/macOS/SentryNativeBridge.m index 0f696675d..eb4b29d9b 100644 --- a/package-dev/Plugins/macOS/SentryNativeBridge.m +++ b/package-dev/Plugins/macOS/SentryNativeBridge.m @@ -8,6 +8,8 @@ static Class SentryBreadcrumb; static Class SentryUser; static Class SentryOptions; +static Class SentryId; +static Class SentrySpanId; static Class PrivateSentrySDKOnly; #define LOAD_CLASS_OR_BREAK(name) \ @@ -40,6 +42,8 @@ int SentryNativeBridgeLoadLibrary() LOAD_CLASS_OR_BREAK(SentryBreadcrumb) LOAD_CLASS_OR_BREAK(SentryUser) LOAD_CLASS_OR_BREAK(SentryOptions) + LOAD_CLASS_OR_BREAK(SentryId) + LOAD_CLASS_OR_BREAK(SentrySpanId) LOAD_CLASS_OR_BREAK(PrivateSentrySDKOnly) // everything above passed - mark as successfully loaded @@ -255,6 +259,26 @@ void SentryNativeBridgeUnsetUser() return cString; } +void SentryNativeBridgeSetTraceId(const char *traceId, const char *spanId) +{ + if (traceId == NULL || spanId == NULL) { + return; + } + + id sentryTraceId = [[SentryId alloc] + performSelector:@selector(initWithUUIDString:) + withObject:[NSString stringWithUTF8String:traceId]]; + + id sentrySpanId = [[SentrySpanId alloc] + performSelector:@selector(initWithValue:) + withObject:[NSString stringWithUTF8String:spanId]]; + + [PrivateSentrySDKOnly + performSelector:@selector(setTrace:spanId:) + withObject:sentryTraceId + withObject:sentrySpanId]; +} + static inline NSString *_NSStringOrNil(const char *value) { return value ? [NSString stringWithUTF8String:value] : nil; diff --git a/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs b/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs index 7c8442c98..79267360c 100644 --- a/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs +++ b/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs @@ -108,4 +108,7 @@ public static bool Init(SentryUnityOptions options) [DllImport("__Internal", EntryPoint = "SentryNativeBridgeGetInstallationId")] public static extern string GetInstallationId(); + + [DllImport("__Internal", EntryPoint = "SentryNativeBridgeSetTrace")] + public static extern string SetTrace(string traceId, string spanId); } From 6013e11b4d2dd401b2f513ec88ce8e31a24dbf77 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 9 Apr 2025 12:01:16 +0200 Subject: [PATCH 19/35] . --- src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs | 4 ++-- src/Sentry.Unity.Native/NativeScopeObserver.cs | 2 +- src/Sentry.Unity.iOS/NativeScopeObserver.cs | 2 +- src/Sentry.Unity/ScopeObserver.cs | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs b/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs index f56b7060d..ac9f38087 100644 --- a/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs +++ b/src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs @@ -91,13 +91,13 @@ public override void UnsetUserImpl() }); } - public override void SetTraceImpl(SentryId traceId, SpanId parentSpanId) + public override void SetTraceImpl(SentryId traceId, SpanId spanId) { _jniExecutor.Run(() => { using var sentry = GetInternalSentryJava(); // We have to explicitly cast to `(Double?)` - sentry.CallStatic("setTrace", traceId.ToString(), parentSpanId.ToString(), (Double?)null, (Double?)null); + sentry.CallStatic("setTrace", traceId.ToString(), spanId.ToString(), (Double?)null, (Double?)null); }); } } diff --git a/src/Sentry.Unity.Native/NativeScopeObserver.cs b/src/Sentry.Unity.Native/NativeScopeObserver.cs index e9c15797e..3499e38d8 100644 --- a/src/Sentry.Unity.Native/NativeScopeObserver.cs +++ b/src/Sentry.Unity.Native/NativeScopeObserver.cs @@ -40,7 +40,7 @@ public override void SetUserImpl(SentryUser user) } public override void UnsetUserImpl() => C.sentry_remove_user(); - public override void SetTraceImpl(SentryId traceId, SpanId parentSpanId) + public override void SetTraceImpl(SentryId traceId, SpanId spanId) { // TODO: Needs to be implemented } diff --git a/src/Sentry.Unity.iOS/NativeScopeObserver.cs b/src/Sentry.Unity.iOS/NativeScopeObserver.cs index 862eb8ef8..836a8532e 100644 --- a/src/Sentry.Unity.iOS/NativeScopeObserver.cs +++ b/src/Sentry.Unity.iOS/NativeScopeObserver.cs @@ -25,7 +25,7 @@ public override void SetUserImpl(SentryUser user) => SentryCocoaBridgeProxy.SetUser(user.Email, user.Id, user.IpAddress, user.Username); public override void UnsetUserImpl() => SentryCocoaBridgeProxy.UnsetUser(); - public override void SetTraceImpl(SentryId traceId, SpanId parentSpanId) + public override void SetTraceImpl(SentryId traceId, SpanId spanId) { // TODO: Needs to be implemented } diff --git a/src/Sentry.Unity/ScopeObserver.cs b/src/Sentry.Unity/ScopeObserver.cs index fb5e155d0..9055ff55e 100644 --- a/src/Sentry.Unity/ScopeObserver.cs +++ b/src/Sentry.Unity/ScopeObserver.cs @@ -85,13 +85,13 @@ public void SetUser(SentryUser? user) public abstract void UnsetUserImpl(); - public void SetTrace(SentryId traceId, SpanId parentSpanId) + public void SetTrace(SentryId traceId, SpanId spanId) { _options.DiagnosticLogger?.Log( - SentryLevel.Debug, "{0} Scope Sync - Setting Trace traceId:{1} parentSpanId:{2}", null, - _name, traceId, parentSpanId); - SetTraceImpl(traceId, parentSpanId); + SentryLevel.Debug, "{0} Scope Sync - Setting Trace traceId:{1} spanId:{2}", null, + _name, traceId, spanId); + SetTraceImpl(traceId, spanId); } - public abstract void SetTraceImpl(SentryId traceId, SpanId parentSpanId); + public abstract void SetTraceImpl(SentryId traceId, SpanId spanId); } From 04eb2987e2d78accd2060e2cb4b4d6315f122da1 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 9 Apr 2025 14:00:34 +0200 Subject: [PATCH 20/35] implemented observer --- src/Sentry.Unity.iOS/NativeScopeObserver.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Sentry.Unity.iOS/NativeScopeObserver.cs b/src/Sentry.Unity.iOS/NativeScopeObserver.cs index a75b4ed3a..f5270c6bd 100644 --- a/src/Sentry.Unity.iOS/NativeScopeObserver.cs +++ b/src/Sentry.Unity.iOS/NativeScopeObserver.cs @@ -26,10 +26,8 @@ public override void SetUserImpl(SentryUser user) => public override void UnsetUserImpl() => SentryCocoaBridgeProxy.UnsetUser(); - public override void SetTraceImpl(SentryId traceId, SpanId spanId) - { - // Todo: Needs to be implemented - } + public override void SetTraceImpl(SentryId traceId, SpanId spanId) => + SentryCocoaBridgeProxy.SetTrace(traceId.ToString(), spanId.ToString()); internal static string GetTimestamp(DateTimeOffset timestamp) => // "o": Using ISO 8601 to make sure the timestamp makes it to the bridge correctly. From 41a625f2f84bf1ed83ea46337ba38834b0f0eff7 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 9 Apr 2025 14:00:54 +0200 Subject: [PATCH 21/35] pause --- .../Plugins/macOS/SentryNativeBridge.m | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/package-dev/Plugins/macOS/SentryNativeBridge.m b/package-dev/Plugins/macOS/SentryNativeBridge.m index eb4b29d9b..1883a2c5b 100644 --- a/package-dev/Plugins/macOS/SentryNativeBridge.m +++ b/package-dev/Plugins/macOS/SentryNativeBridge.m @@ -19,6 +19,13 @@ break; \ } +#define LOAD_SWIFT_CLASS_OR_BREAK(name, mangled_name) \ + name = (__bridge Class)dlsym(dylib, "OBJC_CLASS_$_" #mangled_name); \ + if (!name) { \ + NSLog(@"Sentry (bridge): Couldn't load class '" #name "' from the dynamic library"); \ + break; \ + } + // Returns (bool): 0 on failure, 1 on success // WARNING: you may only call other Sentry* functions AFTER calling this AND only if it returned "1" int SentryNativeBridgeLoadLibrary() @@ -42,8 +49,8 @@ int SentryNativeBridgeLoadLibrary() LOAD_CLASS_OR_BREAK(SentryBreadcrumb) LOAD_CLASS_OR_BREAK(SentryUser) LOAD_CLASS_OR_BREAK(SentryOptions) - LOAD_CLASS_OR_BREAK(SentryId) - LOAD_CLASS_OR_BREAK(SentrySpanId) + // LOAD_SWIFT_CLASS_OR_BREAK(SentryId, _TtC6Sentry8SentryId) + // LOAD_CLASS_OR_BREAK(SentrySpanId) LOAD_CLASS_OR_BREAK(PrivateSentrySDKOnly) // everything above passed - mark as successfully loaded @@ -259,24 +266,24 @@ void SentryNativeBridgeUnsetUser() return cString; } -void SentryNativeBridgeSetTraceId(const char *traceId, const char *spanId) +void SentryNativeBridgeSetTrace(const char *traceId, const char *spanId) { if (traceId == NULL || spanId == NULL) { return; } - id sentryTraceId = [[SentryId alloc] - performSelector:@selector(initWithUUIDString:) - withObject:[NSString stringWithUTF8String:traceId]]; + // id sentryTraceId = [[SentryId alloc] + // performSelector:@selector(initWithUUIDString:) + // withObject:[NSString stringWithUTF8String:traceId]]; - id sentrySpanId = [[SentrySpanId alloc] - performSelector:@selector(initWithValue:) - withObject:[NSString stringWithUTF8String:spanId]]; + // id sentrySpanId = [[SentrySpanId alloc] + // performSelector:@selector(initWithValue:) + // withObject:[NSString stringWithUTF8String:spanId]]; - [PrivateSentrySDKOnly - performSelector:@selector(setTrace:spanId:) - withObject:sentryTraceId - withObject:sentrySpanId]; + // [PrivateSentrySDKOnly + // performSelector:@selector(setTrace:spanId:) + // withObject:sentryTraceId + // withObject:sentrySpanId]; } static inline NSString *_NSStringOrNil(const char *value) From 675c3ae5f3e75ec1a8722975c6af88c39af0c97d Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 9 Apr 2025 15:23:15 +0200 Subject: [PATCH 22/35] . --- src/Sentry.Unity.iOS/NativeScopeObserver.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Sentry.Unity.iOS/NativeScopeObserver.cs b/src/Sentry.Unity.iOS/NativeScopeObserver.cs index f5270c6bd..2dd920223 100644 --- a/src/Sentry.Unity.iOS/NativeScopeObserver.cs +++ b/src/Sentry.Unity.iOS/NativeScopeObserver.cs @@ -26,8 +26,10 @@ public override void SetUserImpl(SentryUser user) => public override void UnsetUserImpl() => SentryCocoaBridgeProxy.UnsetUser(); - public override void SetTraceImpl(SentryId traceId, SpanId spanId) => - SentryCocoaBridgeProxy.SetTrace(traceId.ToString(), spanId.ToString()); + public override void SetTraceImpl(SentryId traceId, SpanId spanId) + { + // SentryCocoaBridgeProxy.SetTrace(traceId.ToString(), spanId.ToString()); + } internal static string GetTimestamp(DateTimeOffset timestamp) => // "o": Using ISO 8601 to make sure the timestamp makes it to the bridge correctly. From c05d4253368ae1022252b0fde1a93b28f6471aeb Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 9 Apr 2025 15:25:01 +0200 Subject: [PATCH 23/35] return success state --- package-dev/Plugins/macOS/SentryNativeBridge.m | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/package-dev/Plugins/macOS/SentryNativeBridge.m b/package-dev/Plugins/macOS/SentryNativeBridge.m index 0f696675d..9deca8dae 100644 --- a/package-dev/Plugins/macOS/SentryNativeBridge.m +++ b/package-dev/Plugins/macOS/SentryNativeBridge.m @@ -72,14 +72,22 @@ void SentryNativeBridgeOptionsSetInt(const void *options, const char *name, int3 dictOptions[[NSString stringWithUTF8String:name]] = [NSNumber numberWithInt:value]; } -void SentryNativeBridgeStartWithOptions(const void *options) +int SentryNativeBridgeStartWithOptions(const void *options) { NSMutableDictionary *dictOptions = (__bridge_transfer NSMutableDictionary *)options; + NSError *error = nil; + id sentryOptions = [[SentryOptions alloc] performSelector:@selector(initWithDict:didFailWithError:) - withObject:dictOptions withObject:nil]; + withObject:dictOptions withObject:&error]; + + if (error != nil) + { + return 0; + } [SentrySDK performSelector:@selector(startWithOptions:) withObject:sentryOptions]; + return 1; } void SentryConfigureScope(void (^callback)(id)) From a1d1c27c7b27411abfa134e44ff74548a2ceb9c1 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 9 Apr 2025 21:38:17 +0200 Subject: [PATCH 24/35] . --- .../Plugins/macOS/SentryNativeBridge.m | 20 ++++++++----------- src/Sentry.Unity.iOS/NativeScopeObserver.cs | 2 +- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/package-dev/Plugins/macOS/SentryNativeBridge.m b/package-dev/Plugins/macOS/SentryNativeBridge.m index 30843c3c0..fab06d153 100644 --- a/package-dev/Plugins/macOS/SentryNativeBridge.m +++ b/package-dev/Plugins/macOS/SentryNativeBridge.m @@ -49,8 +49,8 @@ int SentryNativeBridgeLoadLibrary() LOAD_CLASS_OR_BREAK(SentryBreadcrumb) LOAD_CLASS_OR_BREAK(SentryUser) LOAD_CLASS_OR_BREAK(SentryOptions) - // LOAD_SWIFT_CLASS_OR_BREAK(SentryId, _TtC6Sentry8SentryId) - // LOAD_CLASS_OR_BREAK(SentrySpanId) + LOAD_SWIFT_CLASS_OR_BREAK(SentryId, _TtC6Sentry8SentryId) + LOAD_CLASS_OR_BREAK(SentrySpanId) LOAD_CLASS_OR_BREAK(PrivateSentrySDKOnly) // everything above passed - mark as successfully loaded @@ -276,17 +276,13 @@ void SentryNativeBridgeUnsetUser() void SentryNativeBridgeSetTrace(const char *traceId, const char *spanId) { - if (traceId == NULL || spanId == NULL) { - return; - } - - // id sentryTraceId = [[SentryId alloc] - // performSelector:@selector(initWithUUIDString:) - // withObject:[NSString stringWithUTF8String:traceId]]; + id sentryTraceId = [[SentryId alloc] + performSelector:@selector(initWithUUIDString:) + withObject:[NSString stringWithUTF8String:traceId]]; - // id sentrySpanId = [[SentrySpanId alloc] - // performSelector:@selector(initWithValue:) - // withObject:[NSString stringWithUTF8String:spanId]]; + id sentrySpanId = [[SentrySpanId alloc] + performSelector:@selector(initWithValue:) + withObject:[NSString stringWithUTF8String:spanId]]; // [PrivateSentrySDKOnly // performSelector:@selector(setTrace:spanId:) diff --git a/src/Sentry.Unity.iOS/NativeScopeObserver.cs b/src/Sentry.Unity.iOS/NativeScopeObserver.cs index 2dd920223..14f899e53 100644 --- a/src/Sentry.Unity.iOS/NativeScopeObserver.cs +++ b/src/Sentry.Unity.iOS/NativeScopeObserver.cs @@ -28,7 +28,7 @@ public override void SetUserImpl(SentryUser user) => public override void SetTraceImpl(SentryId traceId, SpanId spanId) { - // SentryCocoaBridgeProxy.SetTrace(traceId.ToString(), spanId.ToString()); + SentryCocoaBridgeProxy.SetTrace(traceId.ToString(), spanId.ToString()); } internal static string GetTimestamp(DateTimeOffset timestamp) => From 6084429b21ad620dc8d9239645821bb2cc42049e Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 10 Apr 2025 14:32:08 +0200 Subject: [PATCH 25/35] enable setTrace in bridge --- package-dev/Plugins/macOS/SentryNativeBridge.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package-dev/Plugins/macOS/SentryNativeBridge.m b/package-dev/Plugins/macOS/SentryNativeBridge.m index fab06d153..921f06ccc 100644 --- a/package-dev/Plugins/macOS/SentryNativeBridge.m +++ b/package-dev/Plugins/macOS/SentryNativeBridge.m @@ -284,10 +284,10 @@ void SentryNativeBridgeSetTrace(const char *traceId, const char *spanId) performSelector:@selector(initWithValue:) withObject:[NSString stringWithUTF8String:spanId]]; - // [PrivateSentrySDKOnly - // performSelector:@selector(setTrace:spanId:) - // withObject:sentryTraceId - // withObject:sentrySpanId]; + [PrivateSentrySDKOnly + performSelector:@selector(setTrace:spanId:) + withObject:sentryTraceId + withObject:sentrySpanId]; } static inline NSString *_NSStringOrNil(const char *value) From 451ab78e66336be6aa308096a78584af8e1e4e5e Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 10 Apr 2025 14:39:53 +0200 Subject: [PATCH 26/35] fixed conflicts --- src/Sentry.Unity.Native/NativeScopeObserver.cs | 4 ---- src/Sentry.Unity.iOS/NativeScopeObserver.cs | 9 --------- 2 files changed, 13 deletions(-) diff --git a/src/Sentry.Unity.Native/NativeScopeObserver.cs b/src/Sentry.Unity.Native/NativeScopeObserver.cs index b126bd008..a133213e0 100644 --- a/src/Sentry.Unity.Native/NativeScopeObserver.cs +++ b/src/Sentry.Unity.Native/NativeScopeObserver.cs @@ -40,10 +40,6 @@ public override void SetUserImpl(SentryUser user) } public override void UnsetUserImpl() => C.sentry_remove_user(); - public override void SetTraceImpl(SentryId traceId, SpanId spanId) - { - // TODO: Needs to be implemented - } public override void SetTraceImpl(SentryId traceId, SpanId spanId) => C.sentry_set_trace(traceId.ToString(), spanId.ToString()); diff --git a/src/Sentry.Unity.iOS/NativeScopeObserver.cs b/src/Sentry.Unity.iOS/NativeScopeObserver.cs index 41665db81..14f899e53 100644 --- a/src/Sentry.Unity.iOS/NativeScopeObserver.cs +++ b/src/Sentry.Unity.iOS/NativeScopeObserver.cs @@ -25,15 +25,6 @@ public override void SetUserImpl(SentryUser user) => SentryCocoaBridgeProxy.SetUser(user.Email, user.Id, user.IpAddress, user.Username); public override void UnsetUserImpl() => SentryCocoaBridgeProxy.UnsetUser(); - public override void SetTraceImpl(SentryId traceId, SpanId spanId) - { - // TODO: Needs to be implemented - } - - public override void SetTraceImpl(SentryId traceId, SpanId spanId) - { - // Todo: Needs to be implemented - } public override void SetTraceImpl(SentryId traceId, SpanId spanId) { From 250aed7f1f9f0c535fda5031cc619c53acc6ac3d Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 10 Apr 2025 14:40:17 +0200 Subject: [PATCH 27/35] more merge conflicts --- src/Sentry.Unity.Native/NativeScopeObserver.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Sentry.Unity.Native/NativeScopeObserver.cs b/src/Sentry.Unity.Native/NativeScopeObserver.cs index a133213e0..a5201125f 100644 --- a/src/Sentry.Unity.Native/NativeScopeObserver.cs +++ b/src/Sentry.Unity.Native/NativeScopeObserver.cs @@ -41,9 +41,6 @@ public override void SetUserImpl(SentryUser user) public override void UnsetUserImpl() => C.sentry_remove_user(); - public override void SetTraceImpl(SentryId traceId, SpanId spanId) => - C.sentry_set_trace(traceId.ToString(), spanId.ToString()); - public override void SetTraceImpl(SentryId traceId, SpanId spanId) => C.sentry_set_trace(traceId.ToString(), spanId.ToString()); From f001e3ab7bbeb43d96f285098088ee72ac209142 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 10 Apr 2025 14:48:21 +0200 Subject: [PATCH 28/35] missing bridge code --- package-dev/Plugins/iOS/SentryNativeBridge.m | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/package-dev/Plugins/iOS/SentryNativeBridge.m b/package-dev/Plugins/iOS/SentryNativeBridge.m index 98982997d..d95d9f539 100644 --- a/package-dev/Plugins/iOS/SentryNativeBridge.m +++ b/package-dev/Plugins/iOS/SentryNativeBridge.m @@ -169,6 +169,22 @@ void SentryNativeBridgeUnsetUser() return cString; } +void SentryNativeBridgeSetTrace(const char *traceId, const char *spanId) +{ + id sentryTraceId = [[SentryId alloc] + performSelector:@selector(initWithUUIDString:) + withObject:[NSString stringWithUTF8String:traceId]]; + + id sentrySpanId = [[SentrySpanId alloc] + performSelector:@selector(initWithValue:) + withObject:[NSString stringWithUTF8String:spanId]]; + + [PrivateSentrySDKOnly + performSelector:@selector(setTrace:spanId:) + withObject:sentryTraceId + withObject:sentrySpanId]; +} + static inline NSString *_NSStringOrNil(const char *value) { return value ? [NSString stringWithUTF8String:value] : nil; From 7953bd7063384d67594f103a98862ab83ddf850d Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 10 Apr 2025 14:48:56 +0200 Subject: [PATCH 29/35] nope bridge --- package-dev/Plugins/iOS/SentryNativeBridgeNoOp.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package-dev/Plugins/iOS/SentryNativeBridgeNoOp.m b/package-dev/Plugins/iOS/SentryNativeBridgeNoOp.m index e9688495f..14f05c2c9 100644 --- a/package-dev/Plugins/iOS/SentryNativeBridgeNoOp.m +++ b/package-dev/Plugins/iOS/SentryNativeBridgeNoOp.m @@ -28,6 +28,8 @@ void SentryNativeBridgeUnsetUser() { } char *SentryNativeBridgeGetInstallationId() { return NULL; } +void SentryNativeBridgeSetTrace(const char *traceId, const char *spanId) { } + void SentryNativeBridgeWriteScope( // clang-format off // // const char *AppStartTime, // const char *AppBuildType, From f92679880014d069e6716aab7e2445874f730b2f Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Fri, 11 Apr 2025 23:24:09 +0200 Subject: [PATCH 30/35] adapt the iOS bridge --- package-dev/Plugins/iOS/SentryNativeBridge.m | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/package-dev/Plugins/iOS/SentryNativeBridge.m b/package-dev/Plugins/iOS/SentryNativeBridge.m index d95d9f539..086918c10 100644 --- a/package-dev/Plugins/iOS/SentryNativeBridge.m +++ b/package-dev/Plugins/iOS/SentryNativeBridge.m @@ -1,6 +1,8 @@ #import #import #import +#import +#import NS_ASSUME_NONNULL_BEGIN @@ -171,18 +173,13 @@ void SentryNativeBridgeUnsetUser() void SentryNativeBridgeSetTrace(const char *traceId, const char *spanId) { - id sentryTraceId = [[SentryId alloc] - performSelector:@selector(initWithUUIDString:) - withObject:[NSString stringWithUTF8String:traceId]]; - - id sentrySpanId = [[SentrySpanId alloc] - performSelector:@selector(initWithValue:) - withObject:[NSString stringWithUTF8String:spanId]]; + NSString *traceIdStr = [NSString stringWithUTF8String:traceId]; + NSString *spanIdStr = [NSString stringWithUTF8String:spanId]; - [PrivateSentrySDKOnly - performSelector:@selector(setTrace:spanId:) - withObject:sentryTraceId - withObject:sentrySpanId]; + SentryId *sentryTraceId = [[SentryId alloc] initWithUUIDString:traceIdStr]; + SentrySpanId *sentrySpanId = [[SentrySpanId alloc] initWithValue:spanIdStr]; + + [PrivateSentrySDKOnly setTrace:sentryTraceId spanId:sentrySpanId]; } static inline NSString *_NSStringOrNil(const char *value) From 147395688430b6b29619100c275670086e74b52f Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Fri, 11 Apr 2025 23:36:14 +0200 Subject: [PATCH 31/35] fixed the iOS bridge (fr this time) --- package-dev/Plugins/iOS/SentryNativeBridge.m | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/package-dev/Plugins/iOS/SentryNativeBridge.m b/package-dev/Plugins/iOS/SentryNativeBridge.m index 086918c10..e453a1f67 100644 --- a/package-dev/Plugins/iOS/SentryNativeBridge.m +++ b/package-dev/Plugins/iOS/SentryNativeBridge.m @@ -176,10 +176,16 @@ void SentryNativeBridgeSetTrace(const char *traceId, const char *spanId) NSString *traceIdStr = [NSString stringWithUTF8String:traceId]; NSString *spanIdStr = [NSString stringWithUTF8String:spanId]; - SentryId *sentryTraceId = [[SentryId alloc] initWithUUIDString:traceIdStr]; - SentrySpanId *sentrySpanId = [[SentrySpanId alloc] initWithValue:spanIdStr]; + // This is a workaround to deal with SentryId living inside the Swift header + Class sentryIdClass = NSClassFromString(@"SentryId"); + Class sentrySpanIdClass = NSClassFromString(@"SentrySpanId"); - [PrivateSentrySDKOnly setTrace:sentryTraceId spanId:sentrySpanId]; + if (sentryIdClass && sentrySpanIdClass) { + id sentryTraceId = [[sentryIdClass alloc] initWithUUIDString:traceIdStr]; + id sentrySpanId = [[sentrySpanIdClass alloc] initWithValue:spanIdStr]; + + [PrivateSentrySDKOnly setTrace:sentryTraceId spanId:sentrySpanId]; + } } static inline NSString *_NSStringOrNil(const char *value) From 53f81c6b6b186afbd201335ad8611ecd0249f4d4 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 14 Apr 2025 11:57:24 +0200 Subject: [PATCH 32/35] proxy fix. ios bridge sentryid lookup --- package-dev/Plugins/iOS/SentryNativeBridge.m | 12 ++++++++---- package-dev/Plugins/macOS/SentryNativeBridge.m | 4 ++++ src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/package-dev/Plugins/iOS/SentryNativeBridge.m b/package-dev/Plugins/iOS/SentryNativeBridge.m index e453a1f67..a609ce31a 100644 --- a/package-dev/Plugins/iOS/SentryNativeBridge.m +++ b/package-dev/Plugins/iOS/SentryNativeBridge.m @@ -1,8 +1,6 @@ #import #import #import -#import -#import NS_ASSUME_NONNULL_BEGIN @@ -173,18 +171,24 @@ void SentryNativeBridgeUnsetUser() void SentryNativeBridgeSetTrace(const char *traceId, const char *spanId) { + if (traceId == NULL || spanId == NULL) { + return; + } + NSString *traceIdStr = [NSString stringWithUTF8String:traceId]; NSString *spanIdStr = [NSString stringWithUTF8String:spanId]; // This is a workaround to deal with SentryId living inside the Swift header - Class sentryIdClass = NSClassFromString(@"SentryId"); + Class sentryIdClass = NSClassFromString(@"_TtC6Sentry8SentryId"); Class sentrySpanIdClass = NSClassFromString(@"SentrySpanId"); if (sentryIdClass && sentrySpanIdClass) { id sentryTraceId = [[sentryIdClass alloc] initWithUUIDString:traceIdStr]; id sentrySpanId = [[sentrySpanIdClass alloc] initWithValue:spanIdStr]; - [PrivateSentrySDKOnly setTrace:sentryTraceId spanId:sentrySpanId]; + if (sentryTraceId && sentrySpanId) { + [PrivateSentrySDKOnly setTrace:sentryTraceId spanId:sentrySpanId]; + } } } diff --git a/package-dev/Plugins/macOS/SentryNativeBridge.m b/package-dev/Plugins/macOS/SentryNativeBridge.m index 921f06ccc..9bcc1e8f8 100644 --- a/package-dev/Plugins/macOS/SentryNativeBridge.m +++ b/package-dev/Plugins/macOS/SentryNativeBridge.m @@ -276,6 +276,10 @@ void SentryNativeBridgeUnsetUser() void SentryNativeBridgeSetTrace(const char *traceId, const char *spanId) { + if (traceId == NULL || spanId == NULL) { + return; + } + id sentryTraceId = [[SentryId alloc] performSelector:@selector(initWithUUIDString:) withObject:[NSString stringWithUTF8String:traceId]]; diff --git a/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs b/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs index 79267360c..894a58652 100644 --- a/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs +++ b/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs @@ -110,5 +110,5 @@ public static bool Init(SentryUnityOptions options) public static extern string GetInstallationId(); [DllImport("__Internal", EntryPoint = "SentryNativeBridgeSetTrace")] - public static extern string SetTrace(string traceId, string spanId); + public static extern void SetTrace(string traceId, string spanId); } From 37945663f3521151d3593b7647af4a83af7612fd Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Tue, 22 Apr 2025 18:04:29 +0200 Subject: [PATCH 33/35] bump cocoa --- modules/sentry-cocoa.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sentry-cocoa.properties b/modules/sentry-cocoa.properties index 002085e06..52f92f3b6 100644 --- a/modules/sentry-cocoa.properties +++ b/modules/sentry-cocoa.properties @@ -1,2 +1,2 @@ -version = 8.49.0 +version = 8.49.1 repo = https://github.com/getsentry/sentry-cocoa From f697a37cca75c97082ef23aa0e421887fa1cda84 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Tue, 22 Apr 2025 18:08:29 +0200 Subject: [PATCH 34/35] Updated CHANGELOG.md --- CHANGELOG.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7510145b3..4eebecee3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,7 @@ ### Features -- When running on Windows or Linux, the SDK now links errors and events originating on different layers (managed, native errors) via `trace ID` ([#2089](https://github.com/getsentry/sentry-unity/pull/2089)) -- When running on Android, the SDK now links errors and events originating on different layers (managed, native errors) via `trace ID` ([#1997](https://github.com/getsentry/sentry-unity/pull/1997)) +- The SDK now links errors and events (managed and native errors) via `trace ID`. This allows you to correlate events captured from different layers of your game ([#1997](https://github.com/getsentry/sentry-unity/pull/1997), [#2089](https://github.com/getsentry/sentry-unity/pull/2089), [#2106](https://github.com/getsentry/sentry-unity/pull/2106)) - Drastically improved performance of scope sync when targeting Android ([#2107](https://github.com/getsentry/sentry-unity/pull/2107)) - When running on Android, Windows or Linux, the SDK now links errors and events originating on different layers (managed, native errors) via `trace ID` ([#1997](https://github.com/getsentry/sentry-unity/pull/1997), [#2089](https://github.com/getsentry/sentry-unity/pull/2089)) - The SDK now reports the game's name as part of the app context ([2083](https://github.com/getsentry/sentry-unity/pull/2083)) @@ -17,9 +16,9 @@ ### Dependencies -- Bump Cocoa SDK from v8.45.0 to v8.49.0 ([#2063](https://github.com/getsentry/sentry-unity/pull/2063), [#2071](https://github.com/getsentry/sentry-unity/pull/2071), [#2105](https://github.com/getsentry/sentry-unity/pull/2105)) - - [changelog](https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#8490) - - [diff](https://github.com/getsentry/sentry-cocoa/compare/8.45.0...8.49.0) +- Bump Cocoa SDK from v8.45.0 to v8.49.1 ([#2063](https://github.com/getsentry/sentry-unity/pull/2063), [#2071](https://github.com/getsentry/sentry-unity/pull/2071), [#2105](https://github.com/getsentry/sentry-unity/pull/2105), [#2106](https://github.com/getsentry/sentry-unity/pull/2106)) + - [changelog](https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#8491) + - [diff](https://github.com/getsentry/sentry-cocoa/compare/8.45.0...8.49.1) - Bump Java SDK from v8.3.0 to v8.8.0 ([#2066](https://github.com/getsentry/sentry-unity/pull/2066), [#2075](https://github.com/getsentry/sentry-unity/pull/2075), [#2092](https://github.com/getsentry/sentry-unity/pull/2092), [#2103](https://github.com/getsentry/sentry-unity/pull/2103), [#2111](https://github.com/getsentry/sentry-unity/pull/2111)) - [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#880) - [diff](https://github.com/getsentry/sentry-java/compare/8.3.0...8.8.0) From 5a49697005c037a64dc16708a1db3c3737f4712c Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Tue, 22 Apr 2025 18:13:20 +0200 Subject: [PATCH 35/35] Updated CHANGELOG.md --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57e88e084..a31d01397 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,6 @@ - The SDK now links errors and events (managed and native errors) via `trace ID`. This allows you to correlate events captured from different layers of your game ([#1997](https://github.com/getsentry/sentry-unity/pull/1997), [#2089](https://github.com/getsentry/sentry-unity/pull/2089), [#2106](https://github.com/getsentry/sentry-unity/pull/2106)) - Drastically improved performance of scope sync when targeting Android ([#2107](https://github.com/getsentry/sentry-unity/pull/2107)) -- When running on Android, Windows or Linux, the SDK now links errors and events originating on different layers (managed, native errors) via `trace ID` ([#1997](https://github.com/getsentry/sentry-unity/pull/1997), [#2089](https://github.com/getsentry/sentry-unity/pull/2089)) - The SDK now reports the game's name as part of the app context ([2083](https://github.com/getsentry/sentry-unity/pull/2083)) - The SDK now reports the active scene's name as part of the `Unity Context` ([2084](https://github.com/getsentry/sentry-unity/pull/2084))