Skip to content

Commit

Permalink
add Scope.make
Browse files Browse the repository at this point in the history
  • Loading branch information
tatchi committed Oct 7, 2024
1 parent b3747cf commit 41f1f43
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
8 changes: 1 addition & 7 deletions src/client-ocurl/opentelemetry_client_ocurl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
6 changes: 5 additions & 1 deletion src/core/opentelemetry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down Expand Up @@ -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 =
Expand Down
10 changes: 1 addition & 9 deletions src/integrations/cohttp/opentelemetry_cohttp_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
10 changes: 1 addition & 9 deletions src/trace/opentelemetry_trace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 41f1f43

Please sign in to comment.