mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 20:07:55 -04:00
Merge pull request #6 from AestheticIntegration/dave-and-matt/add-attrs
add add_attrs helper to add attrs to existing scope
This commit is contained in:
commit
1a2b3aa398
2 changed files with 16 additions and 6 deletions
|
|
@ -22,12 +22,12 @@ module Trace = struct
|
||||||
|
|
||||||
(** Sync span guard *)
|
(** Sync span guard *)
|
||||||
let with_
|
let with_
|
||||||
?trace_state ?service_name ?attrs
|
?trace_state ?service_name ?(attrs=[])
|
||||||
?kind ?(trace_id=Trace_id.create()) ?parent ?links
|
?kind ?(trace_id=Trace_id.create()) ?parent ?links
|
||||||
name (f:Trace.scope -> 'a Lwt.t) : 'a Lwt.t =
|
name (f:Trace.scope -> 'a Lwt.t) : 'a Lwt.t =
|
||||||
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=[]} in
|
let scope = {trace_id;span_id;events=[];attrs} in
|
||||||
let finally ok =
|
let finally ok =
|
||||||
let status = match ok with
|
let status = match ok with
|
||||||
| Ok () -> default_status ~code:Status_code_ok ()
|
| Ok () -> default_status ~code:Status_code_ok ()
|
||||||
|
|
@ -35,7 +35,7 @@ module Trace = struct
|
||||||
let span, _ =
|
let span, _ =
|
||||||
Span.create
|
Span.create
|
||||||
?kind ~trace_id ?parent ?links ~id:span_id
|
?kind ~trace_id ?parent ?links ~id:span_id
|
||||||
?trace_state ?attrs ~events:scope.events
|
?trace_state ~attrs:scope.attrs ~events:scope.events
|
||||||
~start_time ~end_time:(Timestamp_ns.now_unix_ns())
|
~start_time ~end_time:(Timestamp_ns.now_unix_ns())
|
||||||
~status
|
~status
|
||||||
name in
|
name in
|
||||||
|
|
|
||||||
|
|
@ -426,6 +426,7 @@ module Trace = struct
|
||||||
trace_id: Trace_id.t;
|
trace_id: Trace_id.t;
|
||||||
span_id: Span_id.t;
|
span_id: Span_id.t;
|
||||||
mutable events: Event.t list;
|
mutable events: Event.t list;
|
||||||
|
mutable attrs: Span.key_value list
|
||||||
}
|
}
|
||||||
|
|
||||||
(** Add an event to the scope. It will be aggregated into the span.
|
(** Add an event to the scope. It will be aggregated into the span.
|
||||||
|
|
@ -437,15 +438,24 @@ module Trace = struct
|
||||||
scope.events <- ev() :: scope.events
|
scope.events <- ev() :: scope.events
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(** Add an attr to the scope. It will be aggregated into the span.
|
||||||
|
|
||||||
|
Note that this takes a function that produces attributes, and will only
|
||||||
|
call it if there is an instrumentation backend. *)
|
||||||
|
let[@inline] add_attrs (scope:scope) (attrs:unit -> Span.key_value list) : unit =
|
||||||
|
if Collector.has_backend() then (
|
||||||
|
scope.attrs <- List.rev_append (attrs ()) scope.attrs
|
||||||
|
)
|
||||||
|
|
||||||
(** Sync span guard *)
|
(** Sync span guard *)
|
||||||
let with_
|
let with_
|
||||||
?trace_state ?service_name ?attrs
|
?trace_state ?service_name ?(attrs = [])
|
||||||
?kind ?(trace_id=Trace_id.create()) ?parent ?links
|
?kind ?(trace_id=Trace_id.create()) ?parent ?links
|
||||||
name (f: scope -> 'a) : 'a =
|
name (f: scope -> 'a) : 'a =
|
||||||
|
|
||||||
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=[]} in
|
let scope = {trace_id;span_id;events=[]; attrs} in
|
||||||
|
|
||||||
let finally ok =
|
let finally ok =
|
||||||
let status = match ok with
|
let status = match ok with
|
||||||
|
|
@ -456,7 +466,7 @@ module Trace = struct
|
||||||
(question also applies to Opentelemetry_lwt.Trace.with) *)
|
(question also applies to Opentelemetry_lwt.Trace.with) *)
|
||||||
Span.create
|
Span.create
|
||||||
?kind ~trace_id ?parent ?links ~id:span_id
|
?kind ~trace_id ?parent ?links ~id:span_id
|
||||||
?trace_state ?attrs ~events:scope.events
|
?trace_state ~attrs:scope.attrs ~events:scope.events
|
||||||
~start_time ~end_time:(Timestamp_ns.now_unix_ns())
|
~start_time ~end_time:(Timestamp_ns.now_unix_ns())
|
||||||
~status
|
~status
|
||||||
name in
|
name in
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue