File tree Expand file tree Collapse file tree 7 files changed +25
-3
lines changed
Expand file tree Collapse file tree 7 files changed +25
-3
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 1- import 'package:meta/meta.dart' ;
2-
31import '../../sentry.dart' ;
42
53class 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
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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' , () {
You can’t perform that action at this time.
0 commit comments