mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 03:47:59 -04:00
merge any_signal/signal into resource_signal, dedup
we had duplication there! my bad.
This commit is contained in:
parent
3dfbd14508
commit
95e8c78ff8
10 changed files with 96 additions and 63 deletions
|
|
@ -1,40 +0,0 @@
|
|||
open Common_
|
||||
open Opentelemetry.Proto
|
||||
|
||||
(** A resource *)
|
||||
type t =
|
||||
| R_metrics of Metrics.resource_metrics list
|
||||
| R_spans of Trace.resource_spans list
|
||||
| R_logs of Logs.resource_logs list
|
||||
|
||||
open struct
|
||||
let of_x_or_empty ?service_name ?attrs ~f l =
|
||||
if l = [] then
|
||||
[]
|
||||
else
|
||||
[ f ?service_name ?attrs l ]
|
||||
end
|
||||
|
||||
let of_logs ?service_name ?attrs logs : t =
|
||||
R_logs [ Util_resources.make_resource_logs ?service_name ?attrs logs ]
|
||||
|
||||
let of_logs_or_empty ?service_name ?attrs logs =
|
||||
of_x_or_empty ?service_name ?attrs ~f:of_logs logs
|
||||
|
||||
let of_spans ?service_name ?attrs spans : t =
|
||||
R_spans [ Util_resources.make_resource_spans ?service_name ?attrs spans ]
|
||||
|
||||
let of_spans_or_empty ?service_name ?attrs spans =
|
||||
of_x_or_empty ?service_name ?attrs ~f:of_spans spans
|
||||
|
||||
let of_metrics ?service_name ?attrs m : t =
|
||||
R_metrics [ Util_resources.make_resource_metrics ?service_name ?attrs m ]
|
||||
|
||||
let of_metrics_or_empty ?service_name ?attrs ms =
|
||||
of_x_or_empty ?service_name ?attrs ~f:of_metrics ms
|
||||
|
||||
let of_signal_l ?service_name ?attrs (s : OTEL.Any_signal_l.t) : t =
|
||||
match s with
|
||||
| Logs logs -> of_logs ?service_name ?attrs logs
|
||||
| Spans sp -> of_spans ?service_name ?attrs sp
|
||||
| Metrics ms -> of_metrics ?service_name ?attrs ms
|
||||
|
|
@ -45,5 +45,5 @@ end
|
|||
|
||||
type any_signal_l_builder = OTEL.Any_signal_l.t Builder.t
|
||||
|
||||
type any_resource_builder = Any_resource.t Builder.t
|
||||
type resource_signal_builder = Resource_signal.t Builder.t
|
||||
(** The type that's useful for HTTP backends *)
|
||||
|
|
|
|||
|
|
@ -61,14 +61,14 @@ end = struct
|
|||
|
||||
let send (self : t) (sigs : OTEL.Any_signal_l.t) : (unit, error) result IO.t
|
||||
=
|
||||
let res = Any_resource.of_signal_l sigs in
|
||||
let res = Resource_signal.of_signal_l sigs in
|
||||
let url =
|
||||
match res with
|
||||
| R_logs _ -> self.config.url_logs
|
||||
| R_spans _ -> self.config.url_traces
|
||||
| R_metrics _ -> self.config.url_metrics
|
||||
| Logs _ -> self.config.url_logs
|
||||
| Traces _ -> self.config.url_traces
|
||||
| Metrics _ -> self.config.url_metrics
|
||||
in
|
||||
let data = Signal.Encode.any ~encoder:self.encoder res in
|
||||
let data = Resource_signal.Encode.any ~encoder:self.encoder res in
|
||||
Httpc.send self.http ~url ~decode:(`Ret ()) data
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,40 @@
|
|||
open Common_
|
||||
module Trace_service = Opentelemetry.Proto.Trace_service
|
||||
module Metrics_service = Opentelemetry.Proto.Metrics_service
|
||||
module Logs_service = Opentelemetry.Proto.Logs_service
|
||||
module Span = Opentelemetry.Span
|
||||
|
||||
let ( let@ ) = ( @@ )
|
||||
|
||||
module Proto = Opentelemetry.Proto
|
||||
open struct
|
||||
let of_x_or_empty ?service_name ?attrs ~f l =
|
||||
if l = [] then
|
||||
[]
|
||||
else
|
||||
[ f ?service_name ?attrs l ]
|
||||
end
|
||||
|
||||
type t =
|
||||
| Traces of Proto.Trace.resource_spans list
|
||||
| Metrics of Proto.Metrics.resource_metrics list
|
||||
| Logs of Proto.Logs.resource_logs list
|
||||
|
||||
let of_logs ?service_name ?attrs logs : t =
|
||||
Logs [ Util_resources.make_resource_logs ?service_name ?attrs logs ]
|
||||
|
||||
let of_logs_or_empty ?service_name ?attrs logs =
|
||||
of_x_or_empty ?service_name ?attrs ~f:of_logs logs
|
||||
|
||||
let of_spans ?service_name ?attrs spans : t =
|
||||
Traces [ Util_resources.make_resource_spans ?service_name ?attrs spans ]
|
||||
|
||||
let of_spans_or_empty ?service_name ?attrs spans =
|
||||
of_x_or_empty ?service_name ?attrs ~f:of_spans spans
|
||||
|
||||
let of_metrics ?service_name ?attrs m : t =
|
||||
Metrics [ Util_resources.make_resource_metrics ?service_name ?attrs m ]
|
||||
|
||||
let of_metrics_or_empty ?service_name ?attrs ms =
|
||||
of_x_or_empty ?service_name ?attrs ~f:of_metrics ms
|
||||
|
||||
let to_traces = function
|
||||
| Traces xs -> Some xs
|
||||
| _ -> None
|
||||
|
|
@ -36,6 +59,12 @@ let is_logs = function
|
|||
| Logs _ -> true
|
||||
| _ -> false
|
||||
|
||||
let of_signal_l ?service_name ?attrs (s : OTEL.Any_signal_l.t) : t =
|
||||
match s with
|
||||
| Logs logs -> of_logs ?service_name ?attrs logs
|
||||
| Spans sp -> of_spans ?service_name ?attrs sp
|
||||
| Metrics ms -> of_metrics ?service_name ?attrs ms
|
||||
|
||||
module Encode = struct
|
||||
let resource_to_string ~encoder ~ctor ~enc resource : string =
|
||||
let encoder =
|
||||
|
|
@ -78,11 +107,11 @@ module Encode = struct
|
|||
Trace_service.make_export_trace_service_request ~resource_spans:r ())
|
||||
~enc:Trace_service.encode_pb_export_trace_service_request
|
||||
|
||||
let any ?encoder (r : Any_resource.t) : string =
|
||||
let any ?encoder (r : t) : string =
|
||||
match r with
|
||||
| R_logs l -> logs ?encoder l
|
||||
| R_spans sp -> traces ?encoder sp
|
||||
| R_metrics ms -> metrics ?encoder ms
|
||||
| Logs l -> logs ?encoder l
|
||||
| Traces sp -> traces ?encoder sp
|
||||
| Metrics ms -> metrics ?encoder ms
|
||||
end
|
||||
|
||||
module Decode = struct
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
(** Constructing and managing OTel
|
||||
{{:https://opentelemetry.io/docs/concepts/signals/} signals} *)
|
||||
{{:https://opentelemetry.io/docs/concepts/signals/} signals} at the resource
|
||||
(batch) level *)
|
||||
|
||||
open Common_
|
||||
|
||||
(** The type of signals
|
||||
|
||||
|
|
@ -11,6 +14,45 @@ type t =
|
|||
| Metrics of Opentelemetry_proto.Metrics.resource_metrics list
|
||||
| Logs of Opentelemetry_proto.Logs.resource_logs list
|
||||
|
||||
val of_logs :
|
||||
?service_name:string ->
|
||||
?attrs:OTEL.Key_value.t list ->
|
||||
Proto.Logs.log_record list ->
|
||||
t
|
||||
|
||||
val of_logs_or_empty :
|
||||
?service_name:string ->
|
||||
?attrs:OTEL.Key_value.t list ->
|
||||
Proto.Logs.log_record list ->
|
||||
t list
|
||||
|
||||
val of_spans :
|
||||
?service_name:string -> ?attrs:OTEL.Key_value.t list -> OTEL.Span.t list -> t
|
||||
|
||||
val of_spans_or_empty :
|
||||
?service_name:string ->
|
||||
?attrs:OTEL.Key_value.t list ->
|
||||
OTEL.Span.t list ->
|
||||
t list
|
||||
|
||||
val of_metrics :
|
||||
?service_name:string ->
|
||||
?attrs:OTEL.Key_value.t list ->
|
||||
Proto.Metrics.metric list ->
|
||||
t
|
||||
|
||||
val of_metrics_or_empty :
|
||||
?service_name:string ->
|
||||
?attrs:OTEL.Key_value.t list ->
|
||||
Proto.Metrics.metric list ->
|
||||
t list
|
||||
|
||||
val of_signal_l :
|
||||
?service_name:string ->
|
||||
?attrs:OTEL.Key_value.t list ->
|
||||
OTEL.Any_signal_l.t ->
|
||||
t
|
||||
|
||||
val to_traces : t -> Opentelemetry_proto.Trace.resource_spans list option
|
||||
|
||||
val to_metrics : t -> Opentelemetry_proto.Metrics.resource_metrics list option
|
||||
|
|
@ -49,7 +91,7 @@ module Encode : sig
|
|||
|
||||
@param encoder provide an encoder state to reuse *)
|
||||
|
||||
val any : ?encoder:Pbrt.Encoder.t -> Any_resource.t -> string
|
||||
val any : ?encoder:Pbrt.Encoder.t -> t -> string
|
||||
end
|
||||
|
||||
(** Decode signals from protobuf encoded strings, received over the wire *)
|
||||
|
|
@ -45,6 +45,8 @@ let k_span_ctx = Span_ctx.k_span_ctx
|
|||
(** {2 Attributes and conventions} *)
|
||||
|
||||
module Conventions = Conventions
|
||||
module Value = Value
|
||||
module Key_value = Key_value
|
||||
|
||||
type value = Value.t
|
||||
(** A value in a key/value attribute *)
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ module Client = Opentelemetry_client
|
|||
module Proto = Opentelemetry.Proto
|
||||
open Containers
|
||||
|
||||
let batch_size : Client.Signal.t -> int = function
|
||||
let batch_size : Client.Resource_signal.t -> int = function
|
||||
| Traces ts -> List.length ts
|
||||
| Logs ls -> List.length ls
|
||||
| Metrics ms -> List.length ms
|
||||
|
||||
let avg_batch_size (p : Client.Signal.t -> bool)
|
||||
(batches : Client.Signal.t list) : int =
|
||||
let avg_batch_size (p : Client.Resource_signal.t -> bool)
|
||||
(batches : Client.Resource_signal.t list) : int =
|
||||
let sum =
|
||||
List.fold_left
|
||||
(fun acc b ->
|
||||
|
|
@ -24,7 +24,7 @@ let avg_batch_size (p : Client.Signal.t -> bool)
|
|||
in
|
||||
sum / List.length batches
|
||||
|
||||
let signals_from_batch (signal_batch : Client.Signal.t) =
|
||||
let signals_from_batch (signal_batch : Client.Resource_signal.t) =
|
||||
match signal_batch with
|
||||
| Traces ts -> List.map (fun t -> `Trace t) ts
|
||||
| Logs ls -> List.map (fun l -> `Log l) ls
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
(* A runs tests against a OTel-instrumented program *)
|
||||
|
||||
module Client = Opentelemetry_client
|
||||
module Signal = Client.Signal
|
||||
module Signal = Client.Resource_signal
|
||||
open Lwt.Syntax
|
||||
|
||||
let debug =
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
server that can receive the signals make them available for inspection. *)
|
||||
|
||||
val gather_signals :
|
||||
?port:int -> string list -> Opentelemetry_client.Signal.t list Lwt.t
|
||||
?port:int -> string list -> Opentelemetry_client.Resource_signal.t list Lwt.t
|
||||
(** [gather_signals program_to_test] is a list of all the signals emitted by the
|
||||
[program_to_test], which the server was able to record. This function
|
||||
assumes that the program to test will be sending its signals to the
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ let url = Printf.sprintf "http://localhost:%d" port
|
|||
|
||||
let cmd = [ "emit_logs_cohttp"; "--url"; url ]
|
||||
|
||||
let tests (signal_batches : Client.Signal.t list) =
|
||||
let tests (signal_batches : Client.Resource_signal.t list) =
|
||||
ignore signal_batches;
|
||||
let cur_time = ref 0 in
|
||||
List.iter
|
||||
(fun (signal_batch : Client.Signal.t) ->
|
||||
(fun (signal_batch : Client.Resource_signal.t) ->
|
||||
match signal_batch with
|
||||
| Logs ls ->
|
||||
ls (* Mask out the times so tests don't change in between runs *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue