diff --git a/src/client-ocurl/opentelemetry_client_ocurl.ml b/src/client-ocurl/opentelemetry_client_ocurl.ml index a0a9c39..d724f1c 100644 --- a/src/client-ocurl/opentelemetry_client_ocurl.ml +++ b/src/client-ocurl/opentelemetry_client_ocurl.ml @@ -33,13 +33,7 @@ module Self_trace = struct else ( (* do nothing *) let scope = - { - Scope.trace_id = dummy_trace_id_; - span_id = dummy_span_id; - attrs = []; - events = []; - links = []; - } + Scope.make ~trace_id:dummy_trace_id_ ~span_id:dummy_span_id () in f scope ) diff --git a/src/core/opentelemetry.ml b/src/core/opentelemetry.ml index 4b03078..4cd7124 100644 --- a/src/core/opentelemetry.ml +++ b/src/core/opentelemetry.ml @@ -809,6 +809,10 @@ module Scope = struct mutable links: Span_link.t list; } + let make ~trace_id ~span_id ?(events = []) ?(attrs = []) ?(links = []) () : t + = + { trace_id; span_id; events; attrs; links } + (** Turn the scope into a span context *) let[@inline] to_span_ctx (self : t) : Span_ctx.t = Span_ctx.make ~trace_id:self.trace_id ~parent_id:self.span_id () @@ -1049,7 +1053,7 @@ module Trace = struct in let start_time = Timestamp_ns.now_unix_ns () in let span_id = Span_id.create () in - let scope = { trace_id; span_id; events = []; attrs; links } in + let scope = Scope.make ~trace_id ~span_id ~attrs ~links () in (* called once we're done, to emit a span *) let finally res = let status = diff --git a/src/integrations/cohttp/opentelemetry_cohttp_lwt.ml b/src/integrations/cohttp/opentelemetry_cohttp_lwt.ml index a3ffc71..a0dee06 100644 --- a/src/integrations/cohttp/opentelemetry_cohttp_lwt.ml +++ b/src/integrations/cohttp/opentelemetry_cohttp_lwt.ml @@ -111,15 +111,7 @@ end = struct | Some v -> (match Traceparent.of_value v with | Ok (trace_id, parent_id) -> - Some - Otel.Trace. - { - trace_id; - span_id = parent_id; - events = []; - attrs = []; - links = []; - } + Some (Otel.Scope.make ~trace_id ~span_id:parent_id ()) | Error _ -> None) let remove_trace_context req = diff --git a/src/trace/opentelemetry_trace.ml b/src/trace/opentelemetry_trace.ml index a27788e..9c53c33 100644 --- a/src/trace/opentelemetry_trace.ml +++ b/src/trace/opentelemetry_trace.ml @@ -121,15 +121,7 @@ module Internal = struct | None, None -> None in - let new_scope = - { - Scope.span_id = otel_id; - trace_id; - events = []; - attrs = data; - links = []; - } - in + let new_scope = Otel.Scope.make ~trace_id ~span_id:otel_id ~attrs:data () in let start_time = Timestamp_ns.now_unix_ns () in let sb =