Skip to content

Commit 87ed449

Browse files
fix wrong context propagated to callback of traceContext and traceContextSync
1 parent 9d7a386 commit 87ed449

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/api.dart

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export 'src/api/context/context.dart'
1010
attach,
1111
Context,
1212
ContextKey,
13+
contextFromZone,
1314
contextWithSpan,
1415
contextWithSpanContext,
1516
detach,

lib/src/api/open_telemetry.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Future<T> traceContext<T>(String name, Future<T> Function(api.Context) fn,
4848
bool newRoot = false,
4949
api.SpanKind spanKind = api.SpanKind.internal,
5050
List<api.SpanLink> spanLinks = const []}) async {
51-
return trace(name, () => fn(context ?? api.active),
51+
return trace(name, () => fn(api.contextFromZone()),
5252
context: context,
5353
tracer: tracer,
5454
newRoot: newRoot,
@@ -65,7 +65,7 @@ T traceContextSync<T>(String name, T Function(api.Context) fn,
6565
bool newRoot = false,
6666
api.SpanKind spanKind = api.SpanKind.internal,
6767
List<api.SpanLink> spanLinks = const []}) {
68-
return traceSync(name, () => fn(context ?? api.active),
68+
return traceSync(name, () => fn(api.contextFromZone()),
6969
context: context,
7070
tracer: tracer,
7171
newRoot: newRoot,

0 commit comments

Comments
 (0)