From 19b5a7eb76ced4820b6de3398ac77c11aff939d8 Mon Sep 17 00:00:00 2001 From: Tomasz Cielecki <249719+Cheesebaron@users.noreply.github.com> Date: Tue, 11 Feb 2025 23:14:23 +0100 Subject: [PATCH] Ignore null value on CocoaScopeObserver.SetTag (#3948) --- CHANGELOG.md | 1 + .../Platforms/Cocoa/CocoaScopeObserver.cs | 6 ++++++ test/Sentry.Tests/ScopeTests.cs | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 674e18a1f8..844ba4106e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Fixed envelopes with oversized attachments getting stuck in __processing ([#3938](https://github.com/getsentry/sentry-dotnet/pull/3938)) - Unknown stack frames in profiles on .NET 8+ ([#3942](https://github.com/getsentry/sentry-dotnet/pull/3942)) - Deduplicate profiling stack frames ([#3941](https://github.com/getsentry/sentry-dotnet/pull/3941)) +- Ignore null value on CocoaScopeObserver.SetTag ([#3948](https://github.com/getsentry/sentry-dotnet/pull/3948)) ## 5.1.0 diff --git a/src/Sentry/Platforms/Cocoa/CocoaScopeObserver.cs b/src/Sentry/Platforms/Cocoa/CocoaScopeObserver.cs index 2e96952516..f36271f320 100644 --- a/src/Sentry/Platforms/Cocoa/CocoaScopeObserver.cs +++ b/src/Sentry/Platforms/Cocoa/CocoaScopeObserver.cs @@ -67,6 +67,12 @@ public void SetExtra(string key, object? value) public void SetTag(string key, string value) { + if (value is null) + { + _options.LogDebug("Tag with key '{0}' was null. Use Unset to remove tags instead.", key); + return; + } + try { SentryCocoaSdk.ConfigureScope(scope => scope.SetTagValue(value, key)); diff --git a/test/Sentry.Tests/ScopeTests.cs b/test/Sentry.Tests/ScopeTests.cs index 5815cdb68c..ece48d5170 100644 --- a/test/Sentry.Tests/ScopeTests.cs +++ b/test/Sentry.Tests/ScopeTests.cs @@ -615,6 +615,24 @@ public void Filtered_tags_are_not_set() scope.Tags.Should().OnlyContain(pair => pair.Key == "AzFunctions" && pair.Value == "rule"); } + + [Fact] + public void SetTag_NullValue_DoesNotThrowArgumentNullException() + { + var scope = new Scope(); + + ArgumentNullException exception = null; + try + { + scope.SetTag("IAmNull", null); + } + catch (ArgumentNullException e) + { + exception = e; + } + + Assert.Null(exception); + } } public static class ScopeTestExtensions