trace-collector: Support for floats, etc from trace

This commit is contained in:
Elliott Cable 2023-09-20 02:30:53 +00:00
parent 057a27abe9
commit 1809075095
3 changed files with 29 additions and 6 deletions

View file

@ -435,6 +435,7 @@ type value =
[ `Int of int
| `String of string
| `Bool of bool
| `Float of float
| `None
]
@ -448,6 +449,7 @@ let _conv_value =
| `Int i -> Some (Int_value (Int64.of_int i))
| `String s -> Some (String_value s)
| `Bool b -> Some (Bool_value b)
| `Float f -> Some (Double_value f)
| `None -> None
(**/**)
@ -679,7 +681,7 @@ module Span : sig
val id : t -> Span_id.t
type key_value =
string * [ `Int of int | `String of string | `Bool of bool | `None ]
string * [ `Int of int | `String of string | `Bool of bool | `Float of float | `None ]
val create :
?kind:kind ->
@ -716,7 +718,7 @@ end = struct
| Span_kind_consumer
type key_value =
string * [ `Int of int | `String of string | `Bool of bool | `None ]
string * [ `Int of int | `String of string | `Bool of bool | `Float of float | `None ]
type nonrec status_code = status_status_code =
| Status_code_unset

View file

@ -215,6 +215,19 @@ module Internal = struct
let otel_span = exit_span' otrace_id sb in
Otel.Trace.emit [ otel_span ]
let add_data_to_span otrace_id data =
let active_spans = Active_spans.get () in
match Active_span_tbl.find_opt active_spans.tbl otrace_id with
| None ->
(* FIXME: some kind of error/debug logging *)
()
| Some sb ->
Active_span_tbl.replace active_spans.tbl otrace_id
{ sb with data = sb.data @ data }
let add_data_to_manual_span Otrace.{ span = otrace_id; _ } data =
add_data_to_span otrace_id data
let message ?span ~data:_ msg : unit =
(* gather information from context *)
let old_scope = Otel.Scope.get_ambient_scope () in
@ -235,11 +248,11 @@ module Internal = struct
let name_thread _name = ()
let counter_int name cur_val : unit =
let counter_int ~data:_ name cur_val : unit =
let m = Otel.Metrics.(gauge ~name [ int cur_val ]) in
Otel.Metrics.emit [ m ]
let counter_float name cur_val : unit =
let counter_float ~data:_ name cur_val : unit =
let m = Otel.Metrics.(gauge ~name [ float cur_val ]) in
Otel.Metrics.emit [ m ]
end

View file

@ -126,6 +126,12 @@ module Internal : sig
(See the notes at {!enter_manual_span} about {!Ambient_context}.) *)
val add_data_to_span :
Otrace.span -> (string * Otrace.user_data) list -> unit
val add_data_to_manual_span :
Otrace.explicit_span -> (string * Otrace.user_data) list -> unit
val message :
?span:Otrace.span ->
data:(string * Otrace.user_data) list ->
@ -138,9 +144,11 @@ module Internal : sig
val name_thread : string -> unit
val counter_int : string -> int -> unit
val counter_int :
data:(string * Otrace.user_data) list -> string -> int -> unit
val counter_float : string -> float -> unit
val counter_float :
data:(string * Otrace.user_data) list -> string -> float -> unit
end
type span_begin = {