Skip to content

Commit

Permalink
Fix: braces from tag keys on DefaultSentryScopeStateProcessor. (#1183)
Browse files Browse the repository at this point in the history
* Trim braces from tag keys on DefaultSentryScopeStateProcessor.
  • Loading branch information
lucas-zimerman authored Sep 9, 2021
1 parent b55b55c commit a12bb9f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- Removed braces from tag keys on DefaultSentryScopeStateProcessor ([#1183](https://github.com/getsentry/sentry-dotnet/pull/1183))
- Fix SQLClient unplanned behaviors ([#1179](https://github.com/getsentry/sentry-dotnet/pull/1179))
- Add fallback to Scope Stack from AspNet ([#1180](https://github.com/getsentry/sentry-dotnet/pull/1180))

Expand Down
6 changes: 3 additions & 3 deletions src/Sentry/DefaultSentryScopeStateProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Sentry
/// </summary>
public class DefaultSentryScopeStateProcessor : ISentryScopeStateProcessor
{
private static readonly char[] TrimFilter = { '{', '}' };

/// <summary>
/// Applies state onto a scope.
/// </summary>
Expand All @@ -31,11 +33,9 @@ public void Apply(Scope scope, object state)
scope.SetTags(keyValStringObject
.Where(kv => !string.IsNullOrEmpty(kv.Value as string))
.Select(k => new KeyValuePair<string, string>(
k.Key,
k.Key.Trim(TrimFilter),
// TODO: Candidate for serialization instead. Likely Contexts is a better fit.
k.Value.ToString()!)));


break;
}
#if !NET461
Expand Down
33 changes: 33 additions & 0 deletions test/Sentry.Tests/DefaultSentryScopeStateProcessorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace Sentry.Tests
{
public class DefaultSentryScopeStateProcessorTests
{
[Theory]
[InlineData("a", "a")]
[InlineData("{}", "")]
[InlineData("{OriginalFormat}", "OriginalFormat")]
[InlineData("OriginalFormat", "OriginalFormat")]
public void Apply_KeyValuePairObjectWithBraces_TagAddedWithoutBraces(string key, string expectedKey)
{
// Arrange
var expectedValue = "some string";
var list = new List<KeyValuePair<string, object>>
{
new(key, expectedValue)
};
var scopeStateProcessor = new DefaultSentryScopeStateProcessor();
var scope = new Scope();

// Act
scopeStateProcessor.Apply(scope, list);

// Assert
Assert.Equal(expectedKey, scope.Tags.First().Key);
Assert.Equal(expectedValue, scope.Tags.First().Value);
}
}
}

0 comments on commit a12bb9f

Please sign in to comment.