File tree 1 file changed +13
-3
lines changed
1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 3
3
4
4
import 'dart:async' ;
5
5
6
+ import 'package:logging/logging.dart' ;
6
7
import 'package:meta/meta.dart' ;
7
8
8
9
import '../../../api.dart' ;
9
10
import '../trace/nonrecording_span.dart' show NonRecordingSpan;
10
11
12
+ final Logger _log = Logger ('opentelemetry' );
13
+
11
14
typedef ContextKey = Object ;
12
15
13
16
final ContextKey contextKey = ContextKey ();
@@ -83,13 +86,20 @@ bool detach(ContextToken token) {
83
86
Zone .current[contextStackKey] ?? rootStack;
84
87
85
88
final index = stack.indexWhere ((c) => c.token == token);
86
- final success = index == stack.length - 1 ;
89
+
90
+ // the expected context to detach is the last one in the stack
91
+ final match = index == stack.length - 1 ;
92
+ if (! match) {
93
+ _log.warning ('unexpected (mismatched) token given to detach' );
94
+ }
95
+
96
+ // if the context associated with the given token exists, remove it regardless
97
+ // of mismatch
87
98
if (index != - 1 ) {
88
99
stack.removeAt (index);
89
100
}
90
101
91
- // TODO: log attach/detach mismatch warning
92
- return success;
102
+ return match;
93
103
}
94
104
95
105
class Context {
You can’t perform that action at this time.
0 commit comments