Skip to content

Commit

Permalink
Ignore null value on CocoaScopeObserver.SetTag (#3948)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheesebaron authored Feb 11, 2025
1 parent aa5c432 commit 19b5a7e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/Sentry/Platforms/Cocoa/CocoaScopeObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
18 changes: 18 additions & 0 deletions test/Sentry.Tests/ScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 19b5a7e

Please sign in to comment.