From caade960b6e454e5184fae6cd2508309b54f032a Mon Sep 17 00:00:00 2001 From: Elliott Cable Date: Tue, 19 Sep 2023 23:57:53 +0000 Subject: [PATCH] fix: Repair ambient scope --- src/opentelemetry.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/opentelemetry.ml b/src/opentelemetry.ml index d22247d0..c65133b8 100644 --- a/src/opentelemetry.ml +++ b/src/opentelemetry.ml @@ -810,8 +810,6 @@ module Trace = struct let start_time = Timestamp_ns.now_unix_ns () in let span_id = Span_id.create () in let scope = { trace_id; span_id; events = []; attrs } in - (* set global scope in this thread *) - Scope.with_ambient_scope scope @@ fun () -> (* called once we're done, to emit a span *) let finally res = let status = @@ -830,7 +828,10 @@ module Trace = struct in emit ?service_name [ span ] in - let thunk () = cb scope in + let thunk () = + (* set global scope in this thread *) + Scope.with_ambient_scope scope @@ fun () -> cb scope + in thunk, finally (** Sync span guard.