diff --git a/CHANGELOG.md b/CHANGELOG.md index df552003c7..e30c56d2ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Fixed an issue with the way Sentry detects build settings. This was causing Sentry to produce code that could fail at runtime in AOT compiled applications. ([#4333](https://github.com/getsentry/sentry-dotnet/pull/4333)) - Native AOT: link to static `lzma` on Linux/MUSL ([#4326](https://github.com/getsentry/sentry-dotnet/pull/4326)) - AppDomain.CurrentDomain.ProcessExit hook is now removed on shutdown ([#4323](https://github.com/getsentry/sentry-dotnet/pull/4323)) +- Include `Data` set via `ITransactionTracer` in `SentryTransaction`([#4148](https://github.com/getsentry/sentry-dotnet/pull/4148)) ### Dependencies diff --git a/src/Sentry/TransactionTracer.cs b/src/Sentry/TransactionTracer.cs index 5966a224da..6d8accc745 100644 --- a/src/Sentry/TransactionTracer.cs +++ b/src/Sentry/TransactionTracer.cs @@ -151,15 +151,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(); @@ -270,10 +267,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; 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 + } } } ] diff --git a/test/Sentry.Tests/Protocol/Context/TraceTests.cs b/test/Sentry.Tests/Protocol/Context/TraceTests.cs index 27372d0d9a..4748688ca1 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", + "data": { + "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] diff --git a/test/Sentry.Tests/Protocol/SentryTransactionTests.cs b/test/Sentry.Tests/Protocol/SentryTransactionTests.cs index eb1eaf1bbf..604e1cdda7 100644 --- a/test/Sentry.Tests/Protocol/SentryTransactionTests.cs +++ b/test/Sentry.Tests/Protocol/SentryTransactionTests.cs @@ -258,7 +258,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 @@ -278,6 +278,30 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject() return o; }); + + 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]