From e6e6c9be0751c771ca3fb5223f9120e4209450eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Mon, 28 Apr 2025 10:02:44 +0200 Subject: [PATCH 1/8] test(trace): add expected data to trace context --- test/Sentry.Tests/Protocol/Context/TraceTests.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/Sentry.Tests/Protocol/Context/TraceTests.cs b/test/Sentry.Tests/Protocol/Context/TraceTests.cs index 27372d0d9a..b1b626d354 100644 --- a/test/Sentry.Tests/Protocol/Context/TraceTests.cs +++ b/test/Sentry.Tests/Protocol/Context/TraceTests.cs @@ -38,6 +38,7 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject() SpanId = SpanId.Parse("2000000000000000"), TraceId = SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8") }; + trace.SetData("route", "home"); // Act var actual = trace.ToJsonString(_testOutputLogger, indented: true); @@ -52,7 +53,10 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject() "trace_id": "75302ac48a024bde9a3b3734a82e36c8", "op": "op123", "origin": "auto.abc.def.ghi", - "status": "aborted" + "status": "aborted", + "": { + "route": "home" + } } """, actual); @@ -72,6 +76,7 @@ public void Clone_CopyValues() SpanId = SpanId.Parse("2000000000000000"), TraceId = SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8") }; + trace.SetData("previous_route", "home"); // Act var clone = trace.Clone(); @@ -84,6 +89,7 @@ public void Clone_CopyValues() Assert.Equal(trace.ParentSpanId, clone.ParentSpanId); Assert.Equal(trace.SpanId, clone.SpanId); Assert.Equal(trace.TraceId, clone.TraceId); + Assert.Equal(trace.Data, clone.Data); } [Fact] From f57868e9bc4fb25ec4b8ed52d9292868f6db87ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Mon, 28 Apr 2025 10:06:50 +0200 Subject: [PATCH 2/8] test(transaction): expect SetData via TransactionTracer --- test/Sentry.Tests/Protocol/SentryTransactionTests.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/Sentry.Tests/Protocol/SentryTransactionTests.cs b/test/Sentry.Tests/Protocol/SentryTransactionTests.cs index 4e0872ada1..afaf581bdc 100644 --- a/test/Sentry.Tests/Protocol/SentryTransactionTests.cs +++ b/test/Sentry.Tests/Protocol/SentryTransactionTests.cs @@ -244,6 +244,15 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject() return o; }); + + using (_ = new AssertionScope()) + { + KeyValuePair expectedData = new("extra_key", "extra_value"); + finalTransaction.Data.Should().ContainSingle().Which.Should().Be(expectedData); + finalTransaction.Contexts.Trace.Data.Should().ContainSingle().Which.Should().Be(expectedData); + actual.Data.Should().ContainSingle().Which.Should().Be(expectedData); + actual.Contexts.Trace.Data.Should().ContainSingle().Which.Should().Be(expectedData); + } } [Fact] From 31e91258960ff10bec3cf405a36753956eb5568c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Mon, 28 Apr 2025 11:03:38 +0200 Subject: [PATCH 3/8] test(transaction): expect "data" via TransactionTracer --- .../Protocol/SentryTransactionTests.cs | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/test/Sentry.Tests/Protocol/SentryTransactionTests.cs b/test/Sentry.Tests/Protocol/SentryTransactionTests.cs index afaf581bdc..25321dac52 100644 --- a/test/Sentry.Tests/Protocol/SentryTransactionTests.cs +++ b/test/Sentry.Tests/Protocol/SentryTransactionTests.cs @@ -231,7 +231,7 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject() // Act var finalTransaction = new SentryTransaction(transaction); - var actualString = finalTransaction.ToJsonString(_testOutputLogger); + var actualString = finalTransaction.ToJsonString(_testOutputLogger, indented: true); var actual = Json.Parse(actualString, SentryTransaction.FromJson); // Assert @@ -245,14 +245,29 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject() return o; }); - using (_ = new AssertionScope()) - { - KeyValuePair expectedData = new("extra_key", "extra_value"); - finalTransaction.Data.Should().ContainSingle().Which.Should().Be(expectedData); - finalTransaction.Contexts.Trace.Data.Should().ContainSingle().Which.Should().Be(expectedData); - actual.Data.Should().ContainSingle().Which.Should().Be(expectedData); - actual.Contexts.Trace.Data.Should().ContainSingle().Which.Should().Be(expectedData); - } + Assert.Contains($$""" + "contexts": { + ".NET Framework": { + ".NET Framework": "\u0022v2.0.50727\u0022, \u0022v3.0\u0022, \u0022v3.5\u0022", + ".NET Framework Client": "\u0022v4.8\u0022, \u0022v4.0.0.0\u0022", + ".NET Framework Full": "\u0022v4.8\u0022" + }, + "context_key": "context_value", + "trace": { + "type": "trace", + "span_id": "{{context.SpanId}}", + "parent_span_id": "{{context.ParentSpanId}}", + "trace_id": "{{context.TraceId}}", + "op": "op123", + "origin": "auto.serialize.transaction", + "description": "desc123", + "status": "aborted", + "data": { + "extra_key": "extra_value" + } + } + } + """, actualString); } [Fact] From 13c2a1652a992573b6877fe575aecf42af13bce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Mon, 28 Apr 2025 11:12:07 +0200 Subject: [PATCH 4/8] fix(transaction): store Data from Tracer in Context --- src/Sentry/TransactionTracer.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Sentry/TransactionTracer.cs b/src/Sentry/TransactionTracer.cs index c4da3d5933..c4dd0aa04f 100644 --- a/src/Sentry/TransactionTracer.cs +++ b/src/Sentry/TransactionTracer.cs @@ -159,15 +159,12 @@ public IReadOnlyList Fingerprint /// public IReadOnlyCollection Breadcrumbs => _breadcrumbs; - private readonly ConcurrentDictionary _data = new(); - /// [Obsolete("Use Data")] - public IReadOnlyDictionary Extra => _data; + public IReadOnlyDictionary Extra => _contexts.Trace.Data; /// - public IReadOnlyDictionary Data => _data; - + public IReadOnlyDictionary Data => _contexts.Trace.Data; private readonly ConcurrentDictionary _tags = new(); @@ -278,10 +275,10 @@ internal TransactionTracer(IHub hub, ITransactionContext context, TimeSpan? idle /// [Obsolete("Use SetData")] - public void SetExtra(string key, object? value) => _data[key] = value; + public void SetExtra(string key, object? value) => _contexts.Trace.SetData(key, value); /// - public void SetData(string key, object? value) => _data[key] = value; + public void SetData(string key, object? value) => _contexts.Trace.SetData(key, value); /// public void SetTag(string key, string value) => _tags[key] = value; From cb9e0c366e48ae89a78de5cfbd6125eb3e880efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Mon, 28 Apr 2025 11:14:27 +0200 Subject: [PATCH 5/8] test(trace): add missing name --- test/Sentry.Tests/Protocol/Context/TraceTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Sentry.Tests/Protocol/Context/TraceTests.cs b/test/Sentry.Tests/Protocol/Context/TraceTests.cs index b1b626d354..4748688ca1 100644 --- a/test/Sentry.Tests/Protocol/Context/TraceTests.cs +++ b/test/Sentry.Tests/Protocol/Context/TraceTests.cs @@ -54,7 +54,7 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject() "op": "op123", "origin": "auto.abc.def.ghi", "status": "aborted", - "": { + "data": { "route": "home" } } From 3db48763d1886d3f633b7b8a870d747094edbbb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Mon, 28 Apr 2025 11:29:14 +0200 Subject: [PATCH 6/8] test(AspNetCore): update verified --- ...ntegrationTests.Versioning.DotNet8_0.verified.txt | 12 ++++++++++-- ...ntegrationTests.Versioning.DotNet9_0.verified.txt | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet8_0.verified.txt b/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet8_0.verified.txt index 019cc1fb2d..fcb2b33a90 100644 --- a/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet8_0.verified.txt +++ b/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet8_0.verified.txt @@ -22,7 +22,11 @@ Origin: auto.http.aspnetcore, Description: , Status: Ok, - IsSampled: true + IsSampled: true, + Data: { + http.request.method: GET, + http.response.status_code: 200 + } } }, User: { @@ -80,7 +84,11 @@ route.controller: Version, route.version: 1.1 }, - IsFinished: true + IsFinished: true, + Data: { + http.request.method: GET, + http.response.status_code: 200 + } } } ] diff --git a/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet9_0.verified.txt b/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet9_0.verified.txt index 019cc1fb2d..fcb2b33a90 100644 --- a/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet9_0.verified.txt +++ b/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet9_0.verified.txt @@ -22,7 +22,11 @@ Origin: auto.http.aspnetcore, Description: , Status: Ok, - IsSampled: true + IsSampled: true, + Data: { + http.request.method: GET, + http.response.status_code: 200 + } } }, User: { @@ -80,7 +84,11 @@ route.controller: Version, route.version: 1.1 }, - IsFinished: true + IsFinished: true, + Data: { + http.request.method: GET, + http.response.status_code: 200 + } } } ] From e91052daa8b1f20708ec3369390710b682ba579c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Mon, 28 Apr 2025 11:43:59 +0200 Subject: [PATCH 7/8] docs(CHANGELOG): add entry to unreleased Fixes --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5bd7b8d71..36e66bb8e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Fixes - Work around iOS SHA1 bug ([#4143](https://github.com/getsentry/sentry-dotnet/pull/4143)) +- Include `Data` set via `ITransactionTracer` in `SentryTransaction`([TODO](TODO)) ## 5.6.0 From 3745efe4720e76fca6a6f16cddc21f813d2ad911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Mon, 28 Apr 2025 11:50:50 +0200 Subject: [PATCH 8/8] docs(CHANGELOG): set pull request --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36e66bb8e0..0dd16653e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ ### Fixes - Work around iOS SHA1 bug ([#4143](https://github.com/getsentry/sentry-dotnet/pull/4143)) -- Include `Data` set via `ITransactionTracer` in `SentryTransaction`([TODO](TODO)) +- Include `Data` set via `ITransactionTracer` in `SentryTransaction`([#4148](https://github.com/getsentry/sentry-dotnet/pull/4148)) ## 5.6.0