Skip to content

Commit d74fe5a

Browse files
committed
Update
1 parent 33d8892 commit d74fe5a

File tree

7 files changed

+25
-3
lines changed

7 files changed

+25
-3
lines changed

packages/dart/lib/src/protocol/noop_span.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ class NoOpSpan implements Span {
3535

3636
@override
3737
DateTime? get endTimestamp => null;
38+
39+
@override
40+
bool get isFinished => false;
3841
}

packages/dart/lib/src/protocol/simple_span.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'package:meta/meta.dart';
2-
31
import '../../sentry.dart';
42

53
class SimpleSpan implements Span {
@@ -12,6 +10,7 @@ class SimpleSpan implements Span {
1210
String _name;
1311
SpanV2Status _status = SpanV2Status.ok;
1412
DateTime? _endTimestamp;
13+
bool _isFinished = false;
1514

1615
SimpleSpan({
1716
required String name,
@@ -46,6 +45,7 @@ class SimpleSpan implements Span {
4645
void end({DateTime? endTimestamp}) {
4746
_endTimestamp = endTimestamp ?? DateTime.now().toUtc();
4847
hub.captureSpan(this);
48+
_isFinished = true;
4949
}
5050

5151
@override
@@ -58,6 +58,9 @@ class SimpleSpan implements Span {
5858
_attributes.addAll(attributes);
5959
}
6060

61+
@override
62+
bool get isFinished => _isFinished;
63+
6164
@override
6265
Map<String, dynamic> toJson() {
6366
// TODO: implement toJson

packages/dart/lib/src/protocol/span.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ abstract class Span {
4949
/// Overrides if the attributes already exist.
5050
void setAttributes(Map<String, SentryAttribute> attributes);
5151

52+
@internal
53+
bool get isFinished;
54+
5255
@internal
5356
Map<String, dynamic> toJson();
5457
}

packages/dart/lib/src/protocol/unset_span.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ class UnsetSpan extends Span {
5454

5555
@override
5656
DateTime? get endTimestamp => throw UnimplementedError();
57+
58+
@override
59+
bool get isFinished => throw UnimplementedError();
5760
}

packages/dart/lib/src/scope.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class Scope {
4343
/// Returns active transaction or null if there is no active transaction.
4444
ISentrySpan? span;
4545

46+
/// List of active spans.
47+
/// The last span in the list is the current active span.
4648
final List<Span> _activeSpans = [];
4749

4850
@visibleForTesting
@@ -307,6 +309,7 @@ class Scope {
307309
_replayId = null;
308310
propagationContext = PropagationContext();
309311
_attributes.clear();
312+
_activeSpans.clear();
310313

311314
_clearBreadcrumbsSync();
312315
_setUserSync(null);
@@ -514,6 +517,10 @@ class Scope {
514517
clone.setAttributes(Map.from(_attributes));
515518
}
516519

520+
if (_activeSpans.isNotEmpty) {
521+
clone._activeSpans.addAll(_activeSpans);
522+
}
523+
517524
return clone;
518525
}
519526

packages/dart/test/scope_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ void main() {
431431
expect(sut.eventProcessors.length, 0);
432432
expect(sut.replayId, isNull);
433433
expect(sut.attributes, isEmpty);
434+
expect(sut.activeSpans, isEmpty);
434435
});
435436

436437
test('clones', () async {

packages/dart/test/span_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ void main() {
1919
final span = SimpleSpan(name: 'test-span', parentSpan: null, hub: hub);
2020

2121
span.end();
22-
// TODO: verify span is finished once SimpleSpan implements it
22+
23+
expect(span.endTimestamp, isNotNull);
24+
expect(span.isFinished, isTrue);
2325
});
2426

2527
test('end sets current time by default', () {

0 commit comments

Comments
 (0)