diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c9be5fac1..9f67b2750f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- Fix `ParentSampledId` being reset on `Transaction` ([#1130](https://github.com/getsentry/sentry-dotnet/pull/1130)) - Add IsParentSampled to ITransactionContext ([#1128]https://github.com/getsentry/sentry-dotnet/pull/1128) ## 3.8.1 diff --git a/src/Sentry/Transaction.cs b/src/Sentry/Transaction.cs index 0f471fd686..e049b47465 100644 --- a/src/Sentry/Transaction.cs +++ b/src/Sentry/Transaction.cs @@ -200,11 +200,15 @@ public Transaction(string name, string operation) /// Initializes an instance of . /// public Transaction(ITransaction tracer) - : this(tracer.Name, tracer.Operation) + : this(tracer.Name) { + // Contexts have to be set first because other fields use that + Contexts = tracer.Contexts; + ParentSpanId = tracer.ParentSpanId; SpanId = tracer.SpanId; TraceId = tracer.TraceId; + Operation = tracer.Operation; Platform = tracer.Platform; Release = tracer.Release; StartTimestamp = tracer.StartTimestamp; @@ -214,7 +218,6 @@ public Transaction(ITransaction tracer) IsSampled = tracer.IsSampled; Level = tracer.Level; Request = tracer.Request; - Contexts = tracer.Contexts; User = tracer.User; Environment = tracer.Environment; Sdk = tracer.Sdk; diff --git a/test/Sentry.AspNetCore.Tests/SentryTracingMiddlewareTests.cs b/test/Sentry.AspNetCore.Tests/SentryTracingMiddlewareTests.cs index cdd39556d2..6cce7b0b70 100644 --- a/test/Sentry.AspNetCore.Tests/SentryTracingMiddlewareTests.cs +++ b/test/Sentry.AspNetCore.Tests/SentryTracingMiddlewareTests.cs @@ -122,8 +122,6 @@ public async Task Transaction_is_bound_on_the_scope_automatically() public async Task Transaction_is_started_automatically_from_incoming_trace_header() { // Arrange - ITransactionData transaction = null; - var sentryClient = Substitute.For(); var hub = new Internal.Hub(sentryClient, new SentryOptions @@ -149,11 +147,7 @@ public async Task Transaction_is_started_automatically_from_incoming_trace_heade app.UseEndpoints(routes => { - routes.Map("/person/{id}", _ => - { - transaction = hub.GetSpan() as ITransactionData; - return Task.CompletedTask; - }); + routes.Map("/person/{id}", _ => Task.CompletedTask); }); }) ); @@ -169,11 +163,12 @@ public async Task Transaction_is_started_automatically_from_incoming_trace_heade await client.SendAsync(request); // Assert - transaction.Should().NotBeNull(); - transaction?.Name.Should().Be("GET /person/{id}"); - transaction.TraceId.Should().Be(SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8")); - transaction.ParentSpanId.Should().Be(SpanId.Parse("1000000000000000")); - transaction.IsSampled.Should().BeFalse(); + sentryClient.Received(1).CaptureTransaction(Arg.Is(t => + t.Name == "GET /person/{id}" && + t.TraceId == SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8") && + t.ParentSpanId == SpanId.Parse("1000000000000000") && + t.IsSampled == false + )); } [Fact]