mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-10 04:35:46 -04:00
Merge pull request #25 from imandra-ai/span-links
module for Span links
This commit is contained in:
commit
b2df8ab31d
3 changed files with 54 additions and 16 deletions
6
.ocamlformat-ignore
Normal file
6
.ocamlformat-ignore
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
src/*_pb.ml
|
||||||
|
src/*_pb.mli
|
||||||
|
src/*_types.ml
|
||||||
|
src/*_types.mli
|
||||||
|
src/*_pp.ml
|
||||||
|
src/*_pp.mli
|
||||||
|
|
@ -32,7 +32,7 @@ module Server : sig
|
||||||
?service_name:string ->
|
?service_name:string ->
|
||||||
?attrs:Otel.Span.key_value list ->
|
?attrs:Otel.Span.key_value list ->
|
||||||
?kind:Otel.Span.kind ->
|
?kind:Otel.Span.kind ->
|
||||||
?links:(Otel.Trace_id.t * Otel.Span_id.t * string) list ->
|
?links:Otel.Span_link.t list ->
|
||||||
string ->
|
string ->
|
||||||
Request.t ->
|
Request.t ->
|
||||||
(Request.t -> 'a Lwt.t) ->
|
(Request.t -> 'a Lwt.t) ->
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ module Rand_bytes = Rand_bytes
|
||||||
(** Generation of random identifiers *)
|
(** Generation of random identifiers *)
|
||||||
|
|
||||||
open struct
|
open struct
|
||||||
let result_bind x f = match x with
|
let[@inline] result_bind x f =
|
||||||
|
match x with
|
||||||
| Error e -> Error e
|
| Error e -> Error e
|
||||||
| Ok x -> f x
|
| Ok x -> f x
|
||||||
end
|
end
|
||||||
|
|
@ -416,8 +417,8 @@ module Globals = struct
|
||||||
|> String.split_on_char ',' |> List.map parse_pair
|
|> String.split_on_char ',' |> List.map parse_pair
|
||||||
with _ -> []
|
with _ -> []
|
||||||
|
|
||||||
(** Add a global attribute *)
|
(** Add a global attribute *)
|
||||||
let add_global_attribute (key:string) (v:value) : unit =
|
let add_global_attribute (key : string) (v : value) : unit =
|
||||||
global_attributes := _conv_key_value (key, v) :: !global_attributes
|
global_attributes := _conv_key_value (key, v) :: !global_attributes
|
||||||
|
|
||||||
(* add global attributes to this list *)
|
(* add global attributes to this list *)
|
||||||
|
|
@ -443,7 +444,8 @@ module Globals = struct
|
||||||
| None -> l
|
| None -> l
|
||||||
| Some v ->
|
| Some v ->
|
||||||
default_key_value ~key:Conventions.Attributes.Service.instance_id
|
default_key_value ~key:Conventions.Attributes.Service.instance_id
|
||||||
~value:(Some (String_value v)) () :: l
|
~value:(Some (String_value v)) ()
|
||||||
|
:: l
|
||||||
in
|
in
|
||||||
let l =
|
let l =
|
||||||
match !service_namespace with
|
match !service_namespace with
|
||||||
|
|
@ -480,6 +482,43 @@ end = struct
|
||||||
default_span_event ~time_unix_nano ~name ~attributes:attrs ()
|
default_span_event ~time_unix_nano ~name ~attributes:attrs ()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
(** Span Link
|
||||||
|
|
||||||
|
A pointer from the current span to another span in the same trace or in a
|
||||||
|
different trace. For example, this can be used in batching operations,
|
||||||
|
where a single batch handler processes multiple requests from different
|
||||||
|
traces or when the handler receives a request from a different project.
|
||||||
|
*)
|
||||||
|
module Span_link : sig
|
||||||
|
open Proto.Trace
|
||||||
|
|
||||||
|
type t = span_link
|
||||||
|
|
||||||
|
val make :
|
||||||
|
trace_id:Trace_id.t ->
|
||||||
|
span_id:Span_id.t ->
|
||||||
|
?trace_state:string ->
|
||||||
|
?attrs:key_value list ->
|
||||||
|
?dropped_attributes_count:int ->
|
||||||
|
unit ->
|
||||||
|
t
|
||||||
|
end = struct
|
||||||
|
open Proto.Trace
|
||||||
|
|
||||||
|
type t = span_link
|
||||||
|
|
||||||
|
let make ~trace_id ~span_id ?trace_state ?(attrs = [])
|
||||||
|
?dropped_attributes_count () : t =
|
||||||
|
let attributes = List.map _conv_key_value attrs in
|
||||||
|
let dropped_attributes_count =
|
||||||
|
Option.map Int32.of_int dropped_attributes_count
|
||||||
|
in
|
||||||
|
default_span_link
|
||||||
|
~trace_id:(Trace_id.to_bytes trace_id)
|
||||||
|
~span_id:(Span_id.to_bytes span_id) ?trace_state ~attributes
|
||||||
|
?dropped_attributes_count ()
|
||||||
|
end
|
||||||
|
|
||||||
(** Spans.
|
(** Spans.
|
||||||
|
|
||||||
A Span is the workhorse of traces, it indicates an operation that
|
A Span is the workhorse of traces, it indicates an operation that
|
||||||
|
|
@ -525,7 +564,7 @@ module Span : sig
|
||||||
?status:status ->
|
?status:status ->
|
||||||
trace_id:Trace_id.t ->
|
trace_id:Trace_id.t ->
|
||||||
?parent:id ->
|
?parent:id ->
|
||||||
?links:(Trace_id.t * Span_id.t * string) list ->
|
?links:Span_link.t list ->
|
||||||
start_time:Timestamp_ns.t ->
|
start_time:Timestamp_ns.t ->
|
||||||
end_time:Timestamp_ns.t ->
|
end_time:Timestamp_ns.t ->
|
||||||
string ->
|
string ->
|
||||||
|
|
@ -571,14 +610,6 @@ end = struct
|
||||||
let trace_id = Trace_id.to_bytes trace_id in
|
let trace_id = Trace_id.to_bytes trace_id in
|
||||||
let parent_span_id = Option.map Span_id.to_bytes parent in
|
let parent_span_id = Option.map Span_id.to_bytes parent in
|
||||||
let attributes = List.map _conv_key_value attrs in
|
let attributes = List.map _conv_key_value attrs in
|
||||||
let links =
|
|
||||||
List.map
|
|
||||||
(fun (trace_id, span_id, trace_state) ->
|
|
||||||
let trace_id = Trace_id.to_bytes trace_id in
|
|
||||||
let span_id = Span_id.to_bytes span_id in
|
|
||||||
default_span_link ~trace_id ~span_id ~trace_state ())
|
|
||||||
links
|
|
||||||
in
|
|
||||||
let span =
|
let span =
|
||||||
default_span ~trace_id ?parent_span_id ~span_id:(Span_id.to_bytes id)
|
default_span ~trace_id ?parent_span_id ~span_id:(Span_id.to_bytes id)
|
||||||
~attributes ~events ?trace_state ~status ~kind ~name ~links
|
~attributes ~events ?trace_state ~status ~kind ~name ~links
|
||||||
|
|
@ -672,7 +703,8 @@ module Trace = struct
|
||||||
| Error e -> default_status ~code:Status_code_error ~message:e ()
|
| Error e -> default_status ~code:Status_code_error ~message:e ()
|
||||||
in
|
in
|
||||||
let span, _ =
|
let span, _ =
|
||||||
(* TODO: should the attrs passed to with_ go on the Span (in Span.create) or on the ResourceSpan (in emit)?
|
(* TODO: should the attrs passed to with_ go on the Span
|
||||||
|
(in Span.create) or on the ResourceSpan (in emit)?
|
||||||
(question also applies to Opentelemetry_lwt.Trace.with) *)
|
(question also applies to Opentelemetry_lwt.Trace.with) *)
|
||||||
Span.create ?kind ~trace_id ?parent ?links ~id:span_id ?trace_state
|
Span.create ?kind ~trace_id ?parent ?links ~id:span_id ?trace_state
|
||||||
~attrs:scope.attrs ~events:scope.events ~start_time
|
~attrs:scope.attrs ~events:scope.events ~start_time
|
||||||
|
|
@ -889,8 +921,8 @@ module Logs = struct
|
||||||
~instrumentation_library_logs:[ ll ] ()
|
~instrumentation_library_logs:[ ll ] ()
|
||||||
in
|
in
|
||||||
Collector.send_logs [ rl ] ~ret:ignore
|
Collector.send_logs [ rl ] ~ret:ignore
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
(** A set of callbacks that produce metrics when called.
|
(** A set of callbacks that produce metrics when called.
|
||||||
The metrics are automatically called regularly.
|
The metrics are automatically called regularly.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue