add Scope.make

This commit is contained in:
Corentin Leruth 2024-10-07 15:28:19 +02:00
parent b3747cfc8e
commit 41f1f43470
4 changed files with 8 additions and 26 deletions

View file

@ -33,13 +33,7 @@ module Self_trace = struct
else ( else (
(* do nothing *) (* do nothing *)
let scope = let scope =
{ Scope.make ~trace_id:dummy_trace_id_ ~span_id:dummy_span_id ()
Scope.trace_id = dummy_trace_id_;
span_id = dummy_span_id;
attrs = [];
events = [];
links = [];
}
in in
f scope f scope
) )

View file

@ -809,6 +809,10 @@ module Scope = struct
mutable links: Span_link.t list; 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 *) (** Turn the scope into a span context *)
let[@inline] to_span_ctx (self : t) : Span_ctx.t = let[@inline] to_span_ctx (self : t) : Span_ctx.t =
Span_ctx.make ~trace_id:self.trace_id ~parent_id:self.span_id () Span_ctx.make ~trace_id:self.trace_id ~parent_id:self.span_id ()
@ -1049,7 +1053,7 @@ module Trace = struct
in in
let start_time = Timestamp_ns.now_unix_ns () in let start_time = Timestamp_ns.now_unix_ns () in
let span_id = Span_id.create () 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 *) (* called once we're done, to emit a span *)
let finally res = let finally res =
let status = let status =

View file

@ -111,15 +111,7 @@ end = struct
| Some v -> | Some v ->
(match Traceparent.of_value v with (match Traceparent.of_value v with
| Ok (trace_id, parent_id) -> | Ok (trace_id, parent_id) ->
Some Some (Otel.Scope.make ~trace_id ~span_id:parent_id ())
Otel.Trace.
{
trace_id;
span_id = parent_id;
events = [];
attrs = [];
links = [];
}
| Error _ -> None) | Error _ -> None)
let remove_trace_context req = let remove_trace_context req =

View file

@ -121,15 +121,7 @@ module Internal = struct
| None, None -> None | None, None -> None
in in
let new_scope = let new_scope = Otel.Scope.make ~trace_id ~span_id:otel_id ~attrs:data () in
{
Scope.span_id = otel_id;
trace_id;
events = [];
attrs = data;
links = [];
}
in
let start_time = Timestamp_ns.now_unix_ns () in let start_time = Timestamp_ns.now_unix_ns () in
let sb = let sb =