mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 03:47:59 -04:00
Compare commits
6 commits
c442f3b818
...
b92159c11e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b92159c11e | ||
|
|
0c29da4302 | ||
|
|
a28f24d14f | ||
|
|
e97088f6f7 | ||
|
|
05ef03b39d | ||
|
|
e2fe0f6683 |
8 changed files with 23 additions and 14 deletions
|
|
@ -11,7 +11,7 @@
|
|||
-open
|
||||
Opentelemetry_atomic)
|
||||
(libraries
|
||||
opentelemetry.proto
|
||||
(re_export opentelemetry.proto)
|
||||
opentelemetry.util
|
||||
(re_export opentelemetry.atomic)
|
||||
(re_export opentelemetry.emitter)
|
||||
|
|
|
|||
|
|
@ -16,15 +16,15 @@ type t = Metrics.metric
|
|||
let pp = Proto.Metrics.pp_metric
|
||||
|
||||
(** Number data point, as a float *)
|
||||
let float ?start_time_unix_nano ?(attrs = []) ~(now : Timestamp_ns.t)
|
||||
let float ?start_time_unix_nano ?(attrs = []) ?(now = Clock.now_main ())
|
||||
(d : float) : number_data_point =
|
||||
let attributes = attrs |> List.map Key_value.conv in
|
||||
make_number_data_point ?start_time_unix_nano ~time_unix_nano:now ~attributes
|
||||
~value:(As_double d) ()
|
||||
|
||||
(** Number data point, as an int *)
|
||||
let int ?start_time_unix_nano ?(attrs = []) ~(now : Timestamp_ns.t) (i : int) :
|
||||
number_data_point =
|
||||
let int ?start_time_unix_nano ?(attrs = []) ?(now = Clock.now_main ()) (i : int)
|
||||
: number_data_point =
|
||||
let attributes = attrs |> List.map Key_value.conv in
|
||||
make_number_data_point ?start_time_unix_nano ~time_unix_nano:now ~attributes
|
||||
~value:(As_int (Int64.of_int i))
|
||||
|
|
@ -61,7 +61,7 @@ type histogram_data_point = Metrics.histogram_data_point
|
|||
length 0)
|
||||
@param explicit_bounds strictly increasing list of bounds for the buckets *)
|
||||
let histogram_data_point ?start_time_unix_nano ?(attrs = []) ?(exemplars = [])
|
||||
~explicit_bounds ?sum ~(now : Timestamp_ns.t) ~bucket_counts ~count () :
|
||||
~explicit_bounds ?sum ?(now = Clock.now_main ()) ~bucket_counts ~count () :
|
||||
histogram_data_point =
|
||||
let attributes = attrs |> List.map Key_value.conv in
|
||||
make_histogram_data_point ?start_time_unix_nano ~time_unix_nano:now
|
||||
|
|
|
|||
|
|
@ -103,17 +103,21 @@ let add_event' self ev : unit =
|
|||
let record_exception (self : t) (exn : exn) (bt : Printexc.raw_backtrace) : unit
|
||||
=
|
||||
if is_not_dummy self then (
|
||||
let exn_msg = Printexc.to_string exn in
|
||||
let ev =
|
||||
Event.make "exception"
|
||||
~attrs:
|
||||
[
|
||||
"exception.message", `String (Printexc.to_string exn);
|
||||
"exception.message", `String exn_msg;
|
||||
"exception.type", `String (Printexc.exn_slot_name exn);
|
||||
( "exception.stacktrace",
|
||||
`String (Printexc.raw_backtrace_to_string bt) );
|
||||
]
|
||||
in
|
||||
add_event self ev
|
||||
add_event self ev;
|
||||
|
||||
let status = make_status ~code:Status_code_error ~message:exn_msg () in
|
||||
span_set_status self status
|
||||
)
|
||||
|
||||
let add_attrs (self : t) (attrs : Key_value.t list) : unit =
|
||||
|
|
|
|||
|
|
@ -94,6 +94,8 @@ val add_event' : t -> (unit -> Event.t) -> unit
|
|||
it if there is an instrumentation backend. *)
|
||||
|
||||
val record_exception : t -> exn -> Printexc.raw_backtrace -> unit
|
||||
(** Record an exception occurring inside the span. This creates a span event
|
||||
{b and} also sets the span status to error. *)
|
||||
|
||||
val add_links : t -> Span_link.t list -> unit
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ let dummy : t = { emit = Emitter.dummy; clock = Clock.ptime_clock }
|
|||
|
||||
let[@inline] enabled (self : t) = Emitter.enabled self.emit
|
||||
|
||||
let[@inline] emit self ms : unit = Emitter.emit self.emit ms
|
||||
|
||||
let[@inline] emit1 (self : t) (m : Metrics.t) : unit =
|
||||
Emitter.emit self.emit [ m ]
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ val enabled : t -> bool
|
|||
val of_exporter : Exporter.t -> t
|
||||
(** Create a meter from an exporter *)
|
||||
|
||||
val emit : t -> Metrics.t list -> unit
|
||||
(** Emit metrics directly, bypassing the instrument registry *)
|
||||
|
||||
val emit1 : t -> Metrics.t -> unit
|
||||
(** Emit a single metric directly, bypassing the instrument registry *)
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,9 @@ let get_meter ?name ?version ?(attrs : (string * [< Value.t ]) list = [])
|
|||
(** Emit with current meter *)
|
||||
let[@inline] emit (m : Metrics.t) : unit = Emitter.emit (get ()).emit [ m ]
|
||||
|
||||
(** Emit a list of metrics with current meter *)
|
||||
let[@inline] emit_l (ms : Metrics.t list) : unit = Emitter.emit (get ()).emit ms
|
||||
|
||||
(** A Meter.t that lazily reads the global at emit time *)
|
||||
let default_meter : Meter.t = get_meter ()
|
||||
|
||||
|
|
|
|||
|
|
@ -87,19 +87,14 @@ let with_thunk_and_finally (self : Tracer.t) ?(force_new_trace_id = false)
|
|||
(* called once we're done, to emit a span *)
|
||||
let finally res =
|
||||
let end_time = Clock.now self.clock in
|
||||
Proto.Trace.span_set_end_time_unix_nano span end_time;
|
||||
span_set_end_time_unix_nano span end_time;
|
||||
|
||||
(match Span.status span with
|
||||
| Some _ -> ()
|
||||
| None ->
|
||||
(match res with
|
||||
| Ok () -> ()
|
||||
| Error (e, bt) ->
|
||||
Span.record_exception span e bt;
|
||||
let status =
|
||||
make_status ~code:Status_code_error ~message:(Printexc.to_string e) ()
|
||||
in
|
||||
Span.set_status span status));
|
||||
| Error (e, bt) -> Span.record_exception span e bt));
|
||||
|
||||
Emitter.emit self.emit [ span ]
|
||||
in
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue