Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: braces from tag keys on DefaultSentryScopeStateProcessor. #1183

Merged
merged 8 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
- Add fallback to Scope Stack from AspNet ([#1180](https://github.com/getsentry/sentry-dotnet/pull/1180))

## 3.9.0
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 char[] _trimFilter = new[] { '{', '}' };
lucas-zimerman marked this conversation as resolved.
Show resolved Hide resolved

/// <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);
}
}
}