mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-09 04:17:56 -04:00
opentelemetry.trace: expose sum and hist metrics
This commit is contained in:
parent
4183254546
commit
c29ac75a82
3 changed files with 33 additions and 12 deletions
|
|
@ -49,17 +49,20 @@ let sum ~name ?description ?unit_
|
||||||
in
|
in
|
||||||
make_metric ~name ?description ?unit_ ~data ()
|
make_metric ~name ?description ?unit_ ~data ()
|
||||||
|
|
||||||
|
type histogram_data_point = Metrics.histogram_data_point
|
||||||
|
|
||||||
(** Histogram data
|
(** Histogram data
|
||||||
@param count number of values in population (non negative)
|
@param count number of values in population (non negative)
|
||||||
@param sum sum of values in population (0 if count is 0)
|
@param sum sum of values in population (0 if count is 0)
|
||||||
@param now the timestamp for this data point
|
@param now the timestamp for this data point
|
||||||
@param bucket_counts
|
@param bucket_counts
|
||||||
count value of histogram for each bucket. Sum of the counts must be equal
|
count value of histogram for each bucket. Sum of the counts must be equal
|
||||||
to [count]. length must be [1+length explicit_bounds]
|
to [count]. length must be [1+length explicit_bounds] (unless both have
|
||||||
|
length 0)
|
||||||
@param explicit_bounds strictly increasing list of bounds for the buckets *)
|
@param explicit_bounds strictly increasing list of bounds for the buckets *)
|
||||||
let histogram_data_point ?start_time_unix_nano ?(attrs = []) ?(exemplars = [])
|
let histogram_data_point ?start_time_unix_nano ?(attrs = []) ?(exemplars = [])
|
||||||
?(explicit_bounds = []) ?sum ~(now : Timestamp_ns.t) ~bucket_counts ~count
|
~explicit_bounds ?sum ~(now : Timestamp_ns.t) ~bucket_counts ~count () :
|
||||||
() : histogram_data_point =
|
histogram_data_point =
|
||||||
let attributes = attrs |> List.map Key_value.conv in
|
let attributes = attrs |> List.map Key_value.conv in
|
||||||
make_histogram_data_point ?start_time_unix_nano ~time_unix_nano:now
|
make_histogram_data_point ?start_time_unix_nano ~time_unix_nano:now
|
||||||
~attributes ~exemplars ~bucket_counts ~explicit_bounds ~count ?sum ()
|
~attributes ~exemplars ~bucket_counts ~explicit_bounds ~count ?sum ()
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,11 @@ module Extensions = struct
|
||||||
}
|
}
|
||||||
| Ev_set_span_kind of Otrace.span * OTEL.Span_kind.t
|
| Ev_set_span_kind of Otrace.span * OTEL.Span_kind.t
|
||||||
| Ev_set_span_status of Otrace.span * OTEL.Span_status.t
|
| Ev_set_span_status of Otrace.span * OTEL.Span_status.t
|
||||||
|
|
||||||
|
type Otrace.metric +=
|
||||||
|
| Metric_hist of OTEL.Metrics.histogram_data_point
|
||||||
|
| Metric_sum_int of int
|
||||||
|
| Metric_sum_float of float
|
||||||
end
|
end
|
||||||
|
|
||||||
open Extensions
|
open Extensions
|
||||||
|
|
@ -127,17 +132,25 @@ open struct
|
||||||
|
|
||||||
let metric (self : state) ~level:_ ~params:_ ~data:attrs name v : unit =
|
let metric (self : state) ~level:_ ~params:_ ~data:attrs name v : unit =
|
||||||
let now = OTEL.Clock.now self.clock in
|
let now = OTEL.Clock.now self.clock in
|
||||||
let vals =
|
let kind =
|
||||||
|
let open Trace_core.Core_ext in
|
||||||
match v with
|
match v with
|
||||||
| Trace_core.Core_ext.Metric_int i -> [ OTEL.Metrics.int ~attrs ~now i ]
|
| Metric_int i -> `gauge (OTEL.Metrics.int ~attrs ~now i)
|
||||||
| Trace_core.Core_ext.Metric_float v ->
|
| Metric_float v -> `gauge (OTEL.Metrics.float ~attrs ~now v)
|
||||||
[ OTEL.Metrics.float ~attrs ~now v ]
|
| Metric_sum_int i -> `sum (OTEL.Metrics.int ~attrs ~now i)
|
||||||
| _ -> []
|
| Metric_sum_float v -> `sum (OTEL.Metrics.float ~attrs ~now v)
|
||||||
|
| Metric_hist h -> `hist h
|
||||||
|
| _ -> `none
|
||||||
in
|
in
|
||||||
if vals <> [] then (
|
|
||||||
let m = OTEL.Metrics.(gauge ~name vals) in
|
let m =
|
||||||
OTEL.Exporter.send_metrics self.exporter [ m ]
|
match kind with
|
||||||
)
|
| `none -> []
|
||||||
|
| `gauge v -> [ OTEL.Metrics.gauge ~name [ v ] ]
|
||||||
|
| `sum v -> [ OTEL.Metrics.sum ~name [ v ] ]
|
||||||
|
| `hist h -> [ OTEL.Metrics.histogram ~name [ h ] ]
|
||||||
|
in
|
||||||
|
if m <> [] then OTEL.Exporter.send_metrics self.exporter m
|
||||||
|
|
||||||
let extension (_self : state) ~level:_ ev =
|
let extension (_self : state) ~level:_ ev =
|
||||||
match ev with
|
match ev with
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,11 @@ module Extensions : sig
|
||||||
(** Record exception and potentially turn span to an error *)
|
(** Record exception and potentially turn span to an error *)
|
||||||
| Ev_set_span_kind of Otrace.span * OTEL.Span_kind.t
|
| Ev_set_span_kind of Otrace.span * OTEL.Span_kind.t
|
||||||
| Ev_set_span_status of Otrace.span * OTEL.Span_status.t
|
| Ev_set_span_status of Otrace.span * OTEL.Span_status.t
|
||||||
|
|
||||||
|
type Otrace.metric +=
|
||||||
|
| Metric_hist of OTEL.Metrics.histogram_data_point
|
||||||
|
| Metric_sum_int of int
|
||||||
|
| Metric_sum_float of float
|
||||||
end
|
end
|
||||||
|
|
||||||
val setup : unit -> unit
|
val setup : unit -> unit
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue