mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-11 13:08:35 -04:00
trace-collector: Expose Internal module
This commit is contained in:
parent
6bf59ee21e
commit
2b3e3d733c
2 changed files with 237 additions and 141 deletions
|
|
@ -2,6 +2,7 @@ module Otel = Opentelemetry
|
||||||
module Otrace = Trace (* ocaml-trace *)
|
module Otrace = Trace (* ocaml-trace *)
|
||||||
module TLS = Ambient_context_tls.Thread_local
|
module TLS = Ambient_context_tls.Thread_local
|
||||||
|
|
||||||
|
module Internal = struct
|
||||||
type span_begin = {
|
type span_begin = {
|
||||||
id: Otel.Span_id.t;
|
id: Otel.Span_id.t;
|
||||||
start_time: int64;
|
start_time: int64;
|
||||||
|
|
@ -55,7 +56,7 @@ let spankind_of_string =
|
||||||
| "CONSUMER" -> Span_kind_consumer
|
| "CONSUMER" -> Span_kind_consumer
|
||||||
| _ -> Span_kind_unspecified
|
| _ -> Span_kind_unspecified
|
||||||
|
|
||||||
let otel_attrs_of_otrace_data (data : Otel.Span.key_value list) =
|
let otel_attrs_of_otrace_data data =
|
||||||
let kind : Otel.Span.kind ref = ref Otel.Span.Span_kind_unspecified in
|
let kind : Otel.Span.kind ref = ref Otel.Span.Span_kind_unspecified in
|
||||||
let data =
|
let data =
|
||||||
List.filter_map
|
List.filter_map
|
||||||
|
|
@ -68,7 +69,8 @@ let otel_attrs_of_otrace_data (data : Otel.Span.key_value list) =
|
||||||
in
|
in
|
||||||
!kind, data
|
!kind, data
|
||||||
|
|
||||||
let enter_span' ?explicit_parent ~__FUNCTION__ ~__FILE__ ~__LINE__ ~data name =
|
let enter_span' ?explicit_parent ~__FUNCTION__ ~__FILE__ ~__LINE__ ~data name
|
||||||
|
=
|
||||||
let open Otel in
|
let open Otel in
|
||||||
let otel_id = Span_id.create () in
|
let otel_id = Span_id.create () in
|
||||||
let otrace_id = otrace_of_otel otel_id in
|
let otrace_id = otrace_of_otel otel_id in
|
||||||
|
|
@ -159,8 +161,7 @@ let exit_span' otrace_id
|
||||||
~end_time ~attrs name
|
~end_time ~attrs name
|
||||||
|> fst
|
|> fst
|
||||||
|
|
||||||
let collector () : Trace.collector =
|
module M = struct
|
||||||
let module M = struct
|
|
||||||
let with_span ~__FUNCTION__ ~__FILE__ ~__LINE__ ~data name cb =
|
let with_span ~__FUNCTION__ ~__FILE__ ~__LINE__ ~data name cb =
|
||||||
let otrace_id, sb =
|
let otrace_id, sb =
|
||||||
enter_span' ~__FUNCTION__ ~__FILE__ ~__LINE__ ~data name
|
enter_span' ~__FUNCTION__ ~__FILE__ ~__LINE__ ~data name
|
||||||
|
|
@ -226,8 +227,10 @@ let collector () : Trace.collector =
|
||||||
let counter_float name cur_val : unit =
|
let counter_float name cur_val : unit =
|
||||||
let m = Otel.Metrics.(gauge ~name [ float cur_val ]) in
|
let m = Otel.Metrics.(gauge ~name [ float cur_val ]) in
|
||||||
Otel.Metrics.emit [ m ]
|
Otel.Metrics.emit [ m ]
|
||||||
end in
|
end
|
||||||
(module M)
|
end
|
||||||
|
|
||||||
|
let collector () : Trace.collector = (module Internal.M)
|
||||||
|
|
||||||
let setup () = Trace.setup_collector @@ collector ()
|
let setup () = Trace.setup_collector @@ collector ()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,101 @@
|
||||||
val collector : unit -> Trace.collector
|
module Otel := Opentelemetry
|
||||||
(** Make a Trace collector that uses the OTEL backend to send spans and logs *)
|
module Otrace := Trace
|
||||||
|
module TLS := Ambient_context_tls.Thread_local
|
||||||
|
|
||||||
val setup : unit -> unit
|
val setup : unit -> unit
|
||||||
(** Install the OTEL backend as a Trace collector *)
|
(** Install the OTEL backend as a Trace collector *)
|
||||||
|
|
||||||
val setup_with_otel_backend : Opentelemetry.Collector.backend -> unit
|
val setup_with_otel_backend : Opentelemetry.Collector.backend -> unit
|
||||||
(** Same as {!setup}, but also install the given backend as OTEL backend *)
|
(** Same as {!setup}, but also install the given backend as OTEL backend *)
|
||||||
|
|
||||||
|
val collector : unit -> Trace.collector
|
||||||
|
(** Make a Trace collector that uses the OTEL backend to send spans and logs *)
|
||||||
|
|
||||||
|
(** Internal implementation details; do not consider these stable. *)
|
||||||
|
module Internal : sig
|
||||||
|
module M : sig
|
||||||
|
val with_span :
|
||||||
|
__FUNCTION__:string option ->
|
||||||
|
__FILE__:string ->
|
||||||
|
__LINE__:int ->
|
||||||
|
data:(string * Otrace.user_data) list ->
|
||||||
|
string (* span name *) ->
|
||||||
|
(Otrace.span -> 'a) ->
|
||||||
|
'a
|
||||||
|
|
||||||
|
val enter_manual_span :
|
||||||
|
parent:Otrace.explicit_span option ->
|
||||||
|
flavor:'a ->
|
||||||
|
__FUNCTION__:string option ->
|
||||||
|
__FILE__:string ->
|
||||||
|
__LINE__:int ->
|
||||||
|
data:(string * Otrace.user_data) list ->
|
||||||
|
string (* span name *) ->
|
||||||
|
Otrace.explicit_span
|
||||||
|
|
||||||
|
val exit_manual_span : Otrace.explicit_span -> unit
|
||||||
|
|
||||||
|
val message :
|
||||||
|
?span:Otrace.span ->
|
||||||
|
data:(string * Otrace.user_data) list ->
|
||||||
|
string ->
|
||||||
|
unit
|
||||||
|
|
||||||
|
val shutdown : unit -> unit
|
||||||
|
|
||||||
|
val name_process : string -> unit
|
||||||
|
|
||||||
|
val name_thread : string -> unit
|
||||||
|
|
||||||
|
val counter_int : string -> int -> unit
|
||||||
|
|
||||||
|
val counter_float : string -> float -> unit
|
||||||
|
end
|
||||||
|
|
||||||
|
type span_begin = {
|
||||||
|
id: Otel.Span_id.t;
|
||||||
|
start_time: int64;
|
||||||
|
name: string;
|
||||||
|
data: (string * Otrace.user_data) list;
|
||||||
|
__FILE__: string;
|
||||||
|
__LINE__: int;
|
||||||
|
__FUNCTION__: string option;
|
||||||
|
trace_id: Otel.Trace_id.t;
|
||||||
|
scope: Otel.Scope.t;
|
||||||
|
parent_id: Otel.Span_id.t option;
|
||||||
|
parent_scope: Otel.Scope.t option;
|
||||||
|
}
|
||||||
|
|
||||||
|
module Active_span_tbl : Hashtbl.S with type key = Otrace.span
|
||||||
|
|
||||||
|
module Active_spans : sig
|
||||||
|
type t = private { tbl: span_begin Active_span_tbl.t } [@@unboxed]
|
||||||
|
|
||||||
|
val create : unit -> t
|
||||||
|
|
||||||
|
val tls : t TLS.t
|
||||||
|
|
||||||
|
val get : unit -> t
|
||||||
|
end
|
||||||
|
|
||||||
|
val otrace_of_otel : Otel.Span_id.t -> Otrace.span
|
||||||
|
|
||||||
|
val otel_of_otrace : Otrace.span -> Otel.Span_id.t
|
||||||
|
|
||||||
|
val spankind_of_string : string -> Otel.Span.kind
|
||||||
|
|
||||||
|
val otel_attrs_of_otrace_data :
|
||||||
|
(string * Otrace.user_data) list ->
|
||||||
|
Otel.Span.kind * Otel.Span.key_value list
|
||||||
|
|
||||||
|
val enter_span' :
|
||||||
|
?explicit_parent:Otrace.span ->
|
||||||
|
__FUNCTION__:string option ->
|
||||||
|
__FILE__:string ->
|
||||||
|
__LINE__:int ->
|
||||||
|
data:(string * Otrace.user_data) list ->
|
||||||
|
string ->
|
||||||
|
Otrace.span * span_begin
|
||||||
|
|
||||||
|
val exit_span' : Otrace.span -> span_begin -> Otel.Span.t
|
||||||
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue