Skip to content

Commit 7b1b32e

Browse files
authored
fix: Removed redundant scope sync after transaction finish (#4623)
1 parent fc117ae commit 7b1b32e

4 files changed

Lines changed: 9 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
### BREAKING CHANGES
66

77
- 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))
8-
- Remove unnecessary files from SentryCocoaFramework before packing ([#4602](https://github.com/getsentry/sentry-dotnet/pull/4602))
8+
- Remove unnecessary files from SentryCocoaFramework before packing ([#4623](https://github.com/getsentry/sentry-dotnet/pull/4623))
9+
10+
### Fixes
11+
12+
- The SDK avoids redundant scope sync after transaction finish ([#4479](https://github.com/getsentry/sentry-dotnet/pull/4479))
913

1014
## 6.0.0-preview.1
1115

src/Sentry/Scope.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -818,11 +818,7 @@ internal void ResetTransaction(ITransactionTracer? expectedCurrentTransaction)
818818
if (ReferenceEquals(_transaction.Value, expectedCurrentTransaction))
819819
{
820820
_transaction.Value = null;
821-
if (Options.EnableScopeSync)
822-
{
823-
// We have to restore the trace on the native layers to be in sync with the current scope
824-
Options.ScopeObserver?.SetTrace(PropagationContext.TraceId, PropagationContext.SpanId);
825-
}
821+
SetPropagationContext(new SentryPropagationContext());
826822
}
827823
}
828824
finally

src/Sentry/TransactionTracer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,7 @@ public void Finish()
385385

386386
// Clear the transaction from the scope and regenerate the Propagation Context
387387
// We do this so new events don't have a trace context that is "older" than the transaction that just finished
388-
_hub.ConfigureScope(static (scope, transactionTracer) =>
389-
{
390-
scope.ResetTransaction(transactionTracer);
391-
scope.SetPropagationContext(new SentryPropagationContext());
392-
}, this);
388+
_hub.ConfigureScope(static (scope, transactionTracer) => scope.ResetTransaction(transactionTracer), this);
393389

394390
// Client decides whether to discard this transaction based on sampling
395391
_hub.CaptureTransaction(new SentryTransaction(this));

test/Sentry.Tests/ScopeTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,6 @@ public void ResetTransaction_MatchingTransaction_ObserverSetsTraceFromPropagatio
356356
});
357357
var transaction = new TransactionTracer(DisabledHub.Instance, "test-transaction", "op");
358358
scope.Transaction = transaction;
359-
360-
var expectedTraceId = scope.PropagationContext.TraceId;
361-
var expectedSpanId = scope.PropagationContext.SpanId;
362359
var expectedCount = enableScopeSync ? 1 : 0;
363360

364361
observer.ClearReceivedCalls();
@@ -367,7 +364,8 @@ public void ResetTransaction_MatchingTransaction_ObserverSetsTraceFromPropagatio
367364
scope.ResetTransaction(transaction);
368365

369366
// Assert
370-
observer.Received(expectedCount).SetTrace(Arg.Is(expectedTraceId), Arg.Is(expectedSpanId));
367+
observer.Received(expectedCount)
368+
.SetTrace(Arg.Is(scope.PropagationContext.TraceId), Arg.Is(scope.PropagationContext.SpanId));
371369
}
372370

373371
[Theory]

0 commit comments

Comments
 (0)