diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a6cbf410b..9daaca2244 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,11 @@ ### BREAKING CHANGES - SentryOptions.IsEnvironmentUser now defaults to false on MAUI. The means the User.Name will no longer be set, by default, to the name of the device ([#4606](https://github.com/getsentry/sentry-dotnet/pull/4606)) -- Remove unnecessary files from SentryCocoaFramework before packing ([#4602](https://github.com/getsentry/sentry-dotnet/pull/4602)) +- Remove unnecessary files from SentryCocoaFramework before packing ([#4623](https://github.com/getsentry/sentry-dotnet/pull/4623)) + +### Fixes + +- The SDK avoids redundant scope sync after transaction finish ([#4479](https://github.com/getsentry/sentry-dotnet/pull/4479)) ## 6.0.0-preview.1 diff --git a/src/Sentry/Scope.cs b/src/Sentry/Scope.cs index d1fe138ded..04fab75ff1 100644 --- a/src/Sentry/Scope.cs +++ b/src/Sentry/Scope.cs @@ -818,11 +818,7 @@ internal void ResetTransaction(ITransactionTracer? expectedCurrentTransaction) if (ReferenceEquals(_transaction.Value, expectedCurrentTransaction)) { _transaction.Value = null; - if (Options.EnableScopeSync) - { - // We have to restore the trace on the native layers to be in sync with the current scope - Options.ScopeObserver?.SetTrace(PropagationContext.TraceId, PropagationContext.SpanId); - } + SetPropagationContext(new SentryPropagationContext()); } } finally diff --git a/src/Sentry/TransactionTracer.cs b/src/Sentry/TransactionTracer.cs index 767ccf977c..4dc88923c8 100644 --- a/src/Sentry/TransactionTracer.cs +++ b/src/Sentry/TransactionTracer.cs @@ -385,11 +385,7 @@ public void Finish() // Clear the transaction from the scope and regenerate the Propagation Context // We do this so new events don't have a trace context that is "older" than the transaction that just finished - _hub.ConfigureScope(static (scope, transactionTracer) => - { - scope.ResetTransaction(transactionTracer); - scope.SetPropagationContext(new SentryPropagationContext()); - }, this); + _hub.ConfigureScope(static (scope, transactionTracer) => scope.ResetTransaction(transactionTracer), this); // Client decides whether to discard this transaction based on sampling _hub.CaptureTransaction(new SentryTransaction(this)); diff --git a/test/Sentry.Tests/ScopeTests.cs b/test/Sentry.Tests/ScopeTests.cs index 4b46d62c3f..0bb65dc8ec 100644 --- a/test/Sentry.Tests/ScopeTests.cs +++ b/test/Sentry.Tests/ScopeTests.cs @@ -356,9 +356,6 @@ public void ResetTransaction_MatchingTransaction_ObserverSetsTraceFromPropagatio }); var transaction = new TransactionTracer(DisabledHub.Instance, "test-transaction", "op"); scope.Transaction = transaction; - - var expectedTraceId = scope.PropagationContext.TraceId; - var expectedSpanId = scope.PropagationContext.SpanId; var expectedCount = enableScopeSync ? 1 : 0; observer.ClearReceivedCalls(); @@ -367,7 +364,8 @@ public void ResetTransaction_MatchingTransaction_ObserverSetsTraceFromPropagatio scope.ResetTransaction(transaction); // Assert - observer.Received(expectedCount).SetTrace(Arg.Is(expectedTraceId), Arg.Is(expectedSpanId)); + observer.Received(expectedCount) + .SetTrace(Arg.Is(scope.PropagationContext.TraceId), Arg.Is(scope.PropagationContext.SpanId)); } [Theory]