mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-07 18:37:56 -05:00
refactor
This commit is contained in:
parent
5daef6873b
commit
9f5506c1ee
1 changed files with 20 additions and 16 deletions
|
|
@ -3,10 +3,10 @@
|
||||||
https://github.com/open-telemetry/oteps/blob/main/text/0099-otlp-http.md
|
https://github.com/open-telemetry/oteps/blob/main/text/0099-otlp-http.md
|
||||||
*)
|
*)
|
||||||
|
|
||||||
open Opentelemetry_client
|
module Config = Config
|
||||||
|
module OTELC = Opentelemetry_client
|
||||||
open Common_
|
open Common_
|
||||||
module OTEL = Opentelemetry
|
module OTEL = Opentelemetry
|
||||||
module Config = Config
|
|
||||||
|
|
||||||
let get_headers = Config.Env.get_headers
|
let get_headers = Config.Env.get_headers
|
||||||
|
|
||||||
|
|
@ -14,21 +14,22 @@ let set_headers = Config.Env.set_headers
|
||||||
|
|
||||||
let n_bytes_sent : int Atomic.t = Atomic.make 0
|
let n_bytes_sent : int Atomic.t = Atomic.make 0
|
||||||
|
|
||||||
type error = Export_error.t
|
type error = OTELC.Export_error.t
|
||||||
|
|
||||||
open struct
|
open struct
|
||||||
module Notifier = Notifier_sync
|
module Notifier = OTELC.Notifier_sync
|
||||||
|
|
||||||
module IO : Generic_io.S_WITH_CONCURRENCY with type 'a t = 'a = struct
|
module IO : OTELC.Generic_io.S_WITH_CONCURRENCY with type 'a t = 'a = struct
|
||||||
include Generic_io.Direct_style
|
include OTELC.Generic_io.Direct_style
|
||||||
|
|
||||||
let sleep_s = Thread.delay
|
let sleep_s = Thread.delay
|
||||||
|
|
||||||
let[@inline] spawn f = ignore (Util_thread.start_bg_thread f : Thread.t)
|
let[@inline] spawn f =
|
||||||
|
ignore (OTELC.Util_thread.start_bg_thread f : Thread.t)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module Httpc : Generic_http_consumer.HTTPC with module IO = IO = struct
|
module Httpc : OTELC.Generic_http_consumer.HTTPC with module IO = IO = struct
|
||||||
module IO = IO
|
module IO = IO
|
||||||
|
|
||||||
type t = Curl.t
|
type t = Curl.t
|
||||||
|
|
@ -72,11 +73,13 @@ module Httpc : Generic_http_consumer.HTTPC with module IO = IO = struct
|
||||||
(`Failure
|
(`Failure
|
||||||
(spf "decoding failed with:\n%s\n%s" (Printexc.to_string e) bt))))
|
(spf "decoding failed with:\n%s\n%s" (Printexc.to_string e) bt))))
|
||||||
| Ok { code; body; _ } ->
|
| Ok { code; body; _ } ->
|
||||||
let err = Export_error.decode_invalid_http_response ~url ~code body in
|
let err =
|
||||||
|
OTELC.Export_error.decode_invalid_http_response ~url ~code body
|
||||||
|
in
|
||||||
Error err
|
Error err
|
||||||
end
|
end
|
||||||
|
|
||||||
module Consumer_impl = Generic_http_consumer.Make (IO) (Notifier) (Httpc)
|
module Consumer_impl = OTELC.Generic_http_consumer.Make (IO) (Notifier) (Httpc)
|
||||||
|
|
||||||
let consumer ?(stop = Atomic.make false) ?(config = Config.make ()) () :
|
let consumer ?(stop = Atomic.make false) ?(config = Config.make ()) () :
|
||||||
Opentelemetry_client.Consumer.any_resource_builder =
|
Opentelemetry_client.Consumer.any_resource_builder =
|
||||||
|
|
@ -93,12 +96,12 @@ let consumer ?(stop = Atomic.make false) ?(config = Config.make ()) () :
|
||||||
let create_exporter ?stop ?(config = Config.make ()) () : OTEL.Exporter.t =
|
let create_exporter ?stop ?(config = Config.make ()) () : OTEL.Exporter.t =
|
||||||
let consumer = consumer ?stop ~config () in
|
let consumer = consumer ?stop ~config () in
|
||||||
let bq =
|
let bq =
|
||||||
Bounded_queue_sync.create
|
OTELC.Bounded_queue_sync.create
|
||||||
~high_watermark:Bounded_queue.Defaults.high_watermark ()
|
~high_watermark:OTELC.Bounded_queue.Defaults.high_watermark ()
|
||||||
in
|
in
|
||||||
|
|
||||||
Exporter_queued.create ~q:bq ~consumer ()
|
OTELC.Exporter_queued.create ~q:bq ~consumer ()
|
||||||
|> Exporter_add_batching.add_batching ~config:config.common
|
|> OTELC.Exporter_add_batching.add_batching ~config:config.common
|
||||||
|
|
||||||
let create_backend = create_exporter
|
let create_backend = create_exporter
|
||||||
|
|
||||||
|
|
@ -107,13 +110,14 @@ let setup_ ?(stop = Atomic.make false) ?(config : Config.t = Config.make ()) ()
|
||||||
let exporter = create_exporter ~stop ~config () in
|
let exporter = create_exporter ~stop ~config () in
|
||||||
OTEL.Main_exporter.set exporter;
|
OTEL.Main_exporter.set exporter;
|
||||||
|
|
||||||
Self_trace.set_enabled config.common.self_trace;
|
OTELC.Self_trace.set_enabled config.common.self_trace;
|
||||||
|
|
||||||
if config.ticker_thread then (
|
if config.ticker_thread then (
|
||||||
(* at most a minute *)
|
(* at most a minute *)
|
||||||
let sleep_ms = min 60_000 (max 2 config.ticker_interval_ms) in
|
let sleep_ms = min 60_000 (max 2 config.ticker_interval_ms) in
|
||||||
ignore
|
ignore
|
||||||
(Util_thread.setup_ticker_thread ~stop ~sleep_ms exporter () : Thread.t)
|
(OTELC.Util_thread.setup_ticker_thread ~stop ~sleep_ms exporter ()
|
||||||
|
: Thread.t)
|
||||||
)
|
)
|
||||||
|
|
||||||
let remove_backend () : unit =
|
let remove_backend () : unit =
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue