mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 03:47:59 -04:00
wip: fix tests
This commit is contained in:
parent
576ce9637b
commit
0a32049b4c
4 changed files with 37 additions and 29 deletions
|
|
@ -27,9 +27,10 @@ let i = ref 0
|
|||
|
||||
let run_job job_id : unit Lwt.t =
|
||||
while%lwt not @@ Atomic.get stop do
|
||||
let tracer = T.Tracer.get_main () in
|
||||
let@ scope =
|
||||
Atomic.incr num_tr;
|
||||
T.Trace.with_ ~kind:T.Span.Span_kind_producer "loop.outer"
|
||||
T.Tracer.with_ tracer ~kind:T.Span.Span_kind_producer "loop.outer"
|
||||
~attrs:[ "i", `Int job_id ]
|
||||
in
|
||||
|
||||
|
|
@ -39,9 +40,9 @@ let run_job job_id : unit Lwt.t =
|
|||
Lwt.return @@ Atomic.set stop true
|
||||
else
|
||||
(* parent scope is found via thread local storage *)
|
||||
let@ scope =
|
||||
let@ span =
|
||||
Atomic.incr num_tr;
|
||||
T.Trace.with_ ~scope ~kind:T.Span.Span_kind_internal
|
||||
T.Tracer.with_ tracer ~parent:scope ~kind:T.Span.Span_kind_internal
|
||||
~attrs:[ "j", `Int j ]
|
||||
"loop.inner"
|
||||
in
|
||||
|
|
@ -49,19 +50,20 @@ let run_job job_id : unit Lwt.t =
|
|||
let* () = Lwt_unix.sleep !sleep_outer in
|
||||
Atomic.incr num_sleep;
|
||||
|
||||
T.Logs.(
|
||||
emit
|
||||
[
|
||||
make_strf ~trace_id:scope.trace_id ~span_id:scope.span_id
|
||||
~severity:Severity_number_info "inner at %d" j;
|
||||
]);
|
||||
Opentelemetry_emitter.Emitter.emit (T.Logger.get_main ())
|
||||
[
|
||||
T.Log_record.make_strf ~trace_id:(T.Span.trace_id span)
|
||||
~span_id:(T.Span.id span) ~severity:Severity_number_info
|
||||
"inner at %d" j;
|
||||
];
|
||||
|
||||
incr i;
|
||||
|
||||
try%lwt
|
||||
Atomic.incr num_tr;
|
||||
let@ scope =
|
||||
T.Trace.with_ ~kind:T.Span.Span_kind_internal ~scope "alloc"
|
||||
T.Tracer.with_ tracer ~kind:T.Span.Span_kind_internal ~parent:span
|
||||
"alloc"
|
||||
in
|
||||
(* allocate some stuff *)
|
||||
if !stress_alloc_ then (
|
||||
|
|
@ -75,22 +77,23 @@ let run_job job_id : unit Lwt.t =
|
|||
(* simulate a failure *)
|
||||
if j = 4 && !i mod 13 = 0 then failwith "oh no";
|
||||
|
||||
Opentelemetry.Scope.add_event scope (fun () ->
|
||||
T.Event.make "done with alloc");
|
||||
T.Span.add_event scope (T.Event.make "done with alloc");
|
||||
Lwt.return ()
|
||||
with Failure _ -> Lwt.return ()
|
||||
done
|
||||
done
|
||||
|
||||
let run () : unit Lwt.t =
|
||||
T.GC_metrics.basic_setup ();
|
||||
T.Gc_metrics.setup_on_main_exporter ();
|
||||
|
||||
T.Metrics_callbacks.register (fun () ->
|
||||
T.Metrics.
|
||||
[
|
||||
sum ~name:"num-sleep" ~is_monotonic:true
|
||||
[ int (Atomic.get num_sleep) ];
|
||||
]);
|
||||
T.Metrics_callbacks.(
|
||||
with_set_added_to_main_exporter (fun set ->
|
||||
add_metrics_cb set (fun () ->
|
||||
T.Metrics.
|
||||
[
|
||||
sum ~name:"num-sleep" ~is_monotonic:true
|
||||
[ int (Atomic.get num_sleep) ];
|
||||
])));
|
||||
|
||||
let n_jobs = max 1 !n_jobs in
|
||||
Printf.printf "run %d jobs\n%!" n_jobs;
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@ let varied_tag_set =
|
|||
|> add string_list_tag [ "foo"; "bar"; "baz" ])
|
||||
|
||||
let run () =
|
||||
Opentelemetry.Globals.service_name := "emit_logs";
|
||||
let otel_reporter =
|
||||
Opentelemetry_logs.otel_reporter ~service_name:"emit_logs"
|
||||
Opentelemetry_logs.otel_reporter
|
||||
~attributes:[ "my_reporter_attr", `String "foo" ]
|
||||
()
|
||||
in
|
||||
|
|
@ -35,7 +36,9 @@ let run () =
|
|||
Logs.err (fun m -> m "emit_logs: error log");
|
||||
Logs.app (fun m -> m "emit_logs: app log");
|
||||
let%lwt () =
|
||||
T.Trace.with_ ~kind:T.Span.Span_kind_producer "my_scope" (fun _scope ->
|
||||
let tracer = T.Tracer.get_main () in
|
||||
T.Tracer.with_ tracer ~kind:T.Span.Span_kind_producer "my_scope"
|
||||
(fun _scope ->
|
||||
Logs.info (fun m ->
|
||||
m ~tags:varied_tag_set
|
||||
"emit_logs: this log is emitted with varied tags from a span");
|
||||
|
|
@ -50,7 +53,8 @@ let run () =
|
|||
|
||||
let fmt_logger = Logs_fmt.reporter ~dst:Format.err_formatter () in
|
||||
let combined_logger =
|
||||
Opentelemetry_logs.attach_otel_reporter ~service_name:"emit_logs_fmt"
|
||||
Opentelemetry_logs.attach_otel_reporter
|
||||
(* FIXME ~service_name:"emit_logs_fmt" *)
|
||||
~attributes:[ "my_fmt_attr", `String "bar" ]
|
||||
fmt_logger
|
||||
in
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
open Alcotest
|
||||
module Config = Opentelemetry_client.Config
|
||||
module Config = Opentelemetry_client.Client_config
|
||||
|
||||
let test_config_printing () =
|
||||
let module Env = Config.Env () in
|
||||
|
|
@ -7,11 +7,12 @@ let test_config_printing () =
|
|||
Format.asprintf "%a" Config.pp @@ Env.make (fun common () -> common) ()
|
||||
in
|
||||
let expected =
|
||||
{|{ debug=false;
|
||||
self_trace=false; url_traces="http://localhost:4318/v1/traces";
|
||||
url_metrics="http://localhost:4318/v1/metrics";
|
||||
url_logs="http://localhost:4318/v1/logs"; headers=; batch_traces=400;
|
||||
batch_metrics=20; batch_logs=400; batch_timeout_ms=2000 }|}
|
||||
"{ debug=false;\n\
|
||||
\ self_trace=false; url_traces=\"http://localhost:4318/v1/traces\";\n\
|
||||
\ url_metrics=\"http://localhost:4318/v1/metrics\";\n\
|
||||
\ url_logs=\"http://localhost:4318/v1/logs\"; headers=[]; batch_traces=400;\n\
|
||||
\ batch_metrics=20; batch_logs=400; batch_timeout_ms=2000;\n\
|
||||
\ http_concurrency_level=None }"
|
||||
in
|
||||
check' string ~msg:"is rendered correctly" ~actual ~expected
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ module Tested_program = struct
|
|||
end
|
||||
|
||||
let default_port =
|
||||
String.split_on_char ':' Client.Config.default_url |> function
|
||||
String.split_on_char ':' Client.Client_config.default_url |> function
|
||||
(* Extracting the port from 'http://foo:<port>' *)
|
||||
| [ _; _; port ] -> int_of_string port
|
||||
| _ -> failwith "unexpected format in Client.Config.default_url"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue