mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-09 12:23:32 -04:00
Specify and document the Signal_gatherer API
This commit is contained in:
parent
8288bcb59b
commit
f1b7a2237c
2 changed files with 26 additions and 15 deletions
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
module Client = Opentelemetry_client
|
||||
module Signal = Client.Signal
|
||||
module Proto = Opentelemetry.Proto
|
||||
open Lwt.Syntax
|
||||
|
||||
(* Server to collect telemetry data *)
|
||||
|
|
@ -18,11 +17,6 @@ module Server = struct
|
|||
(* in *)
|
||||
Lwt.return ()
|
||||
|
||||
let metrics req data =
|
||||
let metrics = Signal.Decode.metrics data in
|
||||
let+ () = dbg_request "metrics" req Signal.Pp.metrics metrics in
|
||||
Signal.Metrics metrics
|
||||
|
||||
let handler push_signal _socket (request : Http.Request.t)
|
||||
(body : Cohttp_lwt.Body.t) =
|
||||
let* data = Cohttp_lwt.Body.to_string body in
|
||||
|
|
@ -89,14 +83,6 @@ module Tested_program = struct
|
|||
validate_exit result
|
||||
end
|
||||
|
||||
let collect_traces ~port program_to_test push_signals () =
|
||||
let* () =
|
||||
Lwt.pick
|
||||
[ Server.run port push_signals; Tested_program.run program_to_test ]
|
||||
in
|
||||
(* Let the tester know all the signals have be sent *)
|
||||
Lwt.return (push_signals None)
|
||||
|
||||
let default_port =
|
||||
String.split_on_char ':' Client.Config.default_url |> function
|
||||
(* Extracting the port from 'http://foo:<port>' *)
|
||||
|
|
@ -107,7 +93,11 @@ let gather_signals ?(port = default_port) program_to_test =
|
|||
Lwt_main.run
|
||||
@@
|
||||
let stream, push = Lwt_stream.create () in
|
||||
let* () = collect_traces ~port program_to_test push () in
|
||||
let* () =
|
||||
Lwt.pick [ Server.run port push; Tested_program.run program_to_test ]
|
||||
in
|
||||
(* Close out the stream *)
|
||||
push None;
|
||||
Lwt_stream.to_list stream
|
||||
|
||||
(* Just run the server, and print the signals gathered. *)
|
||||
|
|
|
|||
21
tests/client_e2e/signal_gatherer.mli
Normal file
21
tests/client_e2e/signal_gatherer.mli
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
(** A test utility for running a signal emitting executable alongside a minimal
|
||||
server that can receive the signals make them available for inspection. *)
|
||||
|
||||
val gather_signals :
|
||||
?port:int -> string list -> Opentelemetry_client.Signal.t list
|
||||
(** [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
|
||||
localhost on [port].
|
||||
|
||||
@param port
|
||||
the port where signals will be received. Default is port set in
|
||||
{!Opentelemetry_client.Config.default_url}. *)
|
||||
|
||||
val run : ?port:int -> unit -> unit
|
||||
(** [run ()] runs a signal gathering server and prints all batches of signals
|
||||
received to stdout.
|
||||
|
||||
@param port
|
||||
the port where signals will be received. Default is port set in
|
||||
{!Opentelemetry_client.Config.default_url}. *)
|
||||
Loading…
Add table
Reference in a new issue