Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Span ids not re-generating for headers created from scope ([#3051](https://github.com/getsentry/sentry-dart/pull/3051))
- `ScreenshotIntegration` not being added for web ([#3055](https://github.com/getsentry/sentry-dart/pull/3055))
- `PropagationContext` not being set when `Scope` is cloned resulting in different trace ids when using `withScope` ([#3069](https://github.com/getsentry/sentry-dart/pull/3069))

### Enhancements

Expand Down
1 change: 1 addition & 0 deletions dart/lib/src/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ class Scope {
.._transaction = _transaction
..span = span
.._enableScopeSync = false
..propagationContext = propagationContext
.._replayId = _replayId;

clone._setUserSync(user);
Expand Down
20 changes: 20 additions & 0 deletions dart/test/hub_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,26 @@ void main() {
expect(calls[2].scope?.user, isNull);
expect(calls[2].formatted, 'foo bar 2');
});

test(
'withScope should use the same propagation context as the current scope',
() async {
final hub = fixture.getSut();
late Scope clonedScope;
final currentScope = hub.scope;
await hub.captureEvent(SentryEvent(), withScope: (scope) async {
clonedScope = scope;
});

// Verify the propagation context is shared (same instance)
expect(
identical(
clonedScope.propagationContext, currentScope.propagationContext),
true,
reason: 'Propagation context should be the same instance');
expect(clonedScope.propagationContext.traceId,
currentScope.propagationContext.traceId);
});
});

group('ClientReportRecorder', () {
Expand Down
12 changes: 12 additions & 0 deletions dart/test/scope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,18 @@ void main() {
expect(0, fixture.mockScopeObserver.numberOfSetContextsCalls);
});

test('clone shares propagation context to maintain trace continuity', () {
final sut = fixture.getSut();

// Clone the scope
final clone = sut.clone();

// Verify the propagation context is shared (same instance)
expect(identical(sut.propagationContext, clone.propagationContext), true,
reason: 'Propagation context should be the same instance');
expect(clone.propagationContext.traceId, sut.propagationContext.traceId);
});

group('Scope apply', () {
final scopeUser = SentryUser(
id: '800',
Expand Down
Loading