From 1b538930aeca6eef2c81acec9e05512cb8f4a925 Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Fri, 2 Aug 2024 08:52:43 +0200 Subject: [PATCH 1/7] add support for per-signal urls --- src/client-ocurl/common_.ml | 30 ++++-- src/client-ocurl/config.ml | 59 ++++++++-- src/client-ocurl/config.mli | 28 ++++- .../opentelemetry_client_ocurl.ml | 20 +--- .../opentelemetry_client_ocurl.mli | 6 -- tests/ocurl/test_get_url.expected | 67 +++++++++++- tests/ocurl/test_get_url.ml | 102 ++++++++++++++++-- 7 files changed, 264 insertions(+), 48 deletions(-) diff --git a/src/client-ocurl/common_.ml b/src/client-ocurl/common_.ml index f688ff2b..9388497b 100644 --- a/src/client-ocurl/common_.ml +++ b/src/client-ocurl/common_.ml @@ -15,12 +15,30 @@ let debug_ = let default_url = "http://localhost:4318" -let url = - ref (try Sys.getenv "OTEL_EXPORTER_OTLP_ENDPOINT" with _ -> default_url) - -let get_url () = !url - -let set_url s = url := s +let make_get_from_env env_name = + let value = ref None in + fun () -> + match !value with + | None -> + value := Sys.getenv_opt env_name; + !value + | Some value -> Some value + +let get_url_from_env = make_get_from_env "OTEL_EXPORTER_OTLP_ENDPOINT" + +let get_url_traces_from_env = + make_get_from_env "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" + +let get_url_metrics_from_env = + make_get_from_env "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT" + +let get_url_logs_from_env = make_get_from_env "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT" + +let remove_trailing_slash url = + if url <> "" && String.get url (String.length url - 1) = '/' then + String.sub url 0 (String.length url - 1) + else + url let parse_headers s = let parse_header s = diff --git a/src/client-ocurl/config.ml b/src/client-ocurl/config.ml index 2ea68fb7..1ca45a54 100644 --- a/src/client-ocurl/config.ml +++ b/src/client-ocurl/config.ml @@ -2,7 +2,9 @@ open Common_ type t = { debug: bool; - url: string; + url_traces: string; + url_metrics: string; + url_logs: string; headers: (string * string) list; batch_timeout_ms: int; bg_threads: int; @@ -16,7 +18,9 @@ let pp out self = let ppheaders = Format.pp_print_list pp_header in let { debug; - url; + url_traces; + url_metrics; + url_logs; headers; batch_timeout_ms; bg_threads; @@ -27,18 +31,53 @@ let pp out self = self in Format.fprintf out - "{@[ debug=%B;@ url=%S;@ headers=%a;@ batch_timeout_ms=%d; bg_threads=%d;@ \ - ticker_thread=%B;@ ticker_interval_ms=%d;@ self_trace=%B @]}" - debug url ppheaders headers batch_timeout_ms bg_threads ticker_thread - ticker_interval_ms self_trace + "{@[ debug=%B;@ url_traces=%S;@ url_metrics=%S;@ url_logs=%S;@ \ + headers=%a;@ batch_timeout_ms=%d; bg_threads=%d;@ ticker_thread=%B;@ \ + ticker_interval_ms=%d;@ self_trace=%B @]}" + debug url_traces url_metrics url_logs ppheaders headers batch_timeout_ms + bg_threads ticker_thread ticker_interval_ms self_trace -let make ?(debug = !debug_) ?(url = get_url ()) ?(headers = get_headers ()) - ?(batch_timeout_ms = 2_000) ?(bg_threads = 4) ?(ticker_thread = true) - ?(ticker_interval_ms = 500) ?(self_trace = false) () : t = +let make ?(debug = !debug_) ?url ?url_traces ?url_metrics ?url_logs + ?(headers = get_headers ()) ?(batch_timeout_ms = 2_000) ?(bg_threads = 4) + ?(ticker_thread = true) ?(ticker_interval_ms = 500) ?(self_trace = false) () + : t = let bg_threads = max 1 (min bg_threads 32) in + + let url_traces, url_metrics, url_logs = + let base_url = + match url with + | None -> Option.value (get_url_from_env ()) ~default:default_url + | Some url -> remove_trailing_slash url + in + let url_traces = + match url_traces with + | None -> + Option.value + (get_url_traces_from_env ()) + ~default:(base_url ^ "/v1/traces") + | Some url -> url + in + let url_metrics = + match url_metrics with + | None -> + Option.value + (get_url_metrics_from_env ()) + ~default:(base_url ^ "/v1/metrics") + | Some url -> url + in + let url_logs = + match url_logs with + | None -> + Option.value (get_url_logs_from_env ()) ~default:(base_url ^ "/v1/logs") + | Some url -> url + in + url_traces, url_metrics, url_logs + in { debug; - url; + url_traces; + url_metrics; + url_logs; headers; batch_timeout_ms; bg_threads; diff --git a/src/client-ocurl/config.mli b/src/client-ocurl/config.mli index 07b34c43..b24e350d 100644 --- a/src/client-ocurl/config.mli +++ b/src/client-ocurl/config.mli @@ -2,9 +2,9 @@ type t = private { debug: bool; - url: string; - (** Url of the endpoint. Default is "http://localhost:4318", - or "OTEL_EXPORTER_OTLP_ENDPOINT" if set. *) + url_traces: string; (** Url to send traces *) + url_metrics: string; (** Url to send metrics*) + url_logs: string; (** Url to send logs *) headers: (string * string) list; (** API headers sent to the endpoint. Default is none or "OTEL_EXPORTER_OTLP_HEADERS" if set. *) @@ -39,6 +39,9 @@ type t = private { val make : ?debug:bool -> ?url:string -> + ?url_traces:string -> + ?url_metrics:string -> + ?url_logs:string -> ?headers:(string * string) list -> ?batch_timeout_ms:int -> ?bg_threads:int -> @@ -48,6 +51,25 @@ val make : unit -> t (** Make a configuration. + + @param url base url used to construct per-signal urls. Per-signal url options take precedence over this base url. + Default is "http://localhost:4318", or "OTEL_EXPORTER_OTLP_ENDPOINT" if set. + + Example of constrcuted per-singal urls with the base url http://localhost:4318 + - Traces: http://localhost:4318/v1/traces + - Metrics: http://localhost:4318/v1/metrics + - Logs: http://localhost:4318/v1/logs + + Use per-signal url options if different urls are needed for each signal type. + + @param url_traces url to send traces, or "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" if set. + The url is used as-is without any modification. + + @param url_metrics url to send metrics, or "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT" if set. + The url is used as-is without any modification. + + @param url_logs url to send logs, or "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT" if set. + The url is used as-is without any modification. *) val pp : Format.formatter -> t -> unit diff --git a/src/client-ocurl/opentelemetry_client_ocurl.ml b/src/client-ocurl/opentelemetry_client_ocurl.ml index 9d858544..0cf23dea 100644 --- a/src/client-ocurl/opentelemetry_client_ocurl.ml +++ b/src/client-ocurl/opentelemetry_client_ocurl.ml @@ -145,8 +145,7 @@ end = struct mutable send_threads: Thread.t array; (** Threads that send data via http *) } - let send_http_ ~stop ~config (client : Curl.t) encoder ~path ~encode x : unit - = + let send_http_ ~stop ~config (client : Curl.t) encoder ~url ~encode x : unit = let@ _sc = Self_trace.with_ ~kind:Span.Span_kind_producer "otel-ocurl.send-http" in @@ -160,15 +159,7 @@ end = struct Pbrt.Encoder.to_string encoder in - let url = - let url = config.Config.url in - if url <> "" && String.get url (String.length url - 1) = '/' then - String.sub url 0 (String.length url - 1) - else - url - in - let url = url ^ path in - if !debug_ || config.debug then + if !debug_ || config.Config.debug then Printf.eprintf "opentelemetry: send http POST to %s (%dB)\n%!" url (String.length data); let headers = @@ -227,7 +218,7 @@ end = struct let x = Logs_service.default_export_logs_service_request ~resource_logs:l () in - send_http_ ~stop ~config client encoder ~path:"/v1/logs" + send_http_ ~stop ~config client encoder ~url:config.Config.url_logs ~encode:Logs_service.encode_pb_export_logs_service_request x let send_metrics_http ~stop ~config curl encoder @@ -242,7 +233,7 @@ end = struct Metrics_service.default_export_metrics_service_request ~resource_metrics:l () in - send_http_ ~stop ~config curl encoder ~path:"/v1/metrics" + send_http_ ~stop ~config curl encoder ~url:config.Config.url_metrics ~encode:Metrics_service.encode_pb_export_metrics_service_request x let send_traces_http ~stop ~config curl encoder @@ -256,7 +247,7 @@ end = struct let x = Trace_service.default_export_trace_service_request ~resource_spans:l () in - send_http_ ~stop ~config curl encoder ~path:"/v1/traces" + send_http_ ~stop ~config curl encoder ~url:config.Config.url_traces ~encode:Trace_service.encode_pb_export_trace_service_request x let[@inline] send_event (self : t) ev : unit = B_queue.push self.q ev @@ -514,7 +505,6 @@ let setup_ ?(stop = Atomic.make false) ?(config : Config.t = Config.make ()) () let ((module B) as backend) = create_backend ~stop ~config () in Opentelemetry.Collector.set_backend backend; - if config.url <> get_url () then set_url config.url; Atomic.set Self_trace.enabled config.self_trace; if config.ticker_thread then ( diff --git a/src/client-ocurl/opentelemetry_client_ocurl.mli b/src/client-ocurl/opentelemetry_client_ocurl.mli index a2c01177..8a963692 100644 --- a/src/client-ocurl/opentelemetry_client_ocurl.mli +++ b/src/client-ocurl/opentelemetry_client_ocurl.mli @@ -3,12 +3,6 @@ https://opentelemetry.io/docs/reference/specification/protocol/exporter/ *) -val get_url : unit -> string - -val set_url : string -> unit -(** Url of the endpoint. Default is "http://localhost:4318", - or "OTEL_EXPORTER_OTLP_ENDPOINT" if set. *) - val get_headers : unit -> (string * string) list val set_headers : (string * string) list -> unit diff --git a/tests/ocurl/test_get_url.expected b/tests/ocurl/test_get_url.expected index 0b9a4214..56d92a58 100644 --- a/tests/ocurl/test_get_url.expected +++ b/tests/ocurl/test_get_url.expected @@ -1 +1,66 @@ -ocurl url = http://localhost:3000 +--- default_url --- +url_traces = http://localhost:4318/v1/traces +url_metrics = http://localhost:4318/v1/metrics +url_logs = http://localhost:4318/v1/logs +------ + +--- base_url_from_config --- +url_traces = http://localhost:3000/v1/traces +url_metrics = http://localhost:3000/v1/metrics +url_logs = http://localhost:3000/v1/logs +------ + +--- base_url_from_env --- +url_traces = http://localhost:5000/v1/traces +url_metrics = http://localhost:5000/v1/metrics +url_logs = http://localhost:5000/v1/logs +------ + +--- base_url_from_both_config_and_env --- +url_traces = http://localhost:3000/v1/traces +url_metrics = http://localhost:3000/v1/metrics +url_logs = http://localhost:3000/v1/logs +------ + +--- override_trace_url_from_config --- +url_traces = http://localhost:3001/send/traces +url_metrics = http://localhost:3000/v1/metrics +url_logs = http://localhost:3000/v1/logs +------ + +--- override_trace_url_from_config --- +url_traces = http://localhost:3001/send/traces +url_metrics = http://localhost:5000/v1/metrics +url_logs = http://localhost:5000/v1/logs +------ + +--- override_trace_url_from_both_config_and_env --- +url_traces = http://localhost:3001/send/traces/config +url_metrics = http://localhost:5000/v1/metrics +url_logs = http://localhost:5000/v1/logs +------ + +--- set_all_in_config --- +url_traces = http://localhost:3001/send/traces +url_metrics = http://localhost:3002/send/metrics +url_logs = http://localhost:3003/send/logs +------ + +--- set_all_in_config --- +url_traces = http://localhost:3001/send/traces +url_metrics = http://localhost:3002/send/metrics +url_logs = http://localhost:3003/send/logs +------ + +--- remove_trailing_slash_config --- +url_traces = http://localhost:3001/send/traces +url_metrics = http://localhost:3002/send/metrics +url_logs = http://localhost:3003/send/logs +------ + +--- remove_trailing_slash_config --- +url_traces = http://localhost:3001/send/traces +url_metrics = http://localhost:3002/send/metrics +url_logs = http://localhost:3003/send/logs +------ + diff --git a/tests/ocurl/test_get_url.ml b/tests/ocurl/test_get_url.ml index 1e142015..2fe651c4 100644 --- a/tests/ocurl/test_get_url.ml +++ b/tests/ocurl/test_get_url.ml @@ -1,9 +1,97 @@ -let url = "http://localhost:3000" +open Opentelemetry_client_ocurl -let ocurl () = - let config = Opentelemetry_client_ocurl.Config.make ~url () in - Opentelemetry_client_ocurl.with_setup ~config () @@ fun () -> - let url = Opentelemetry_client_ocurl.get_url () in - print_endline @@ Printf.sprintf "ocurl url = %s" url +let test_urls ~name config = + Printf.printf "--- %s ---\n" name; + Printf.printf "url_traces = %s\n" config.Config.url_traces; + Printf.printf "url_metrics = %s\n" config.Config.url_metrics; + Printf.printf "url_logs = %s\n" config.Config.url_logs; + print_endline "------\n" -let () = ocurl () +let default_url () = + let config = Config.make () in + test_urls ~name:"default_url" config + +let base_url_from_config () = + let config = Config.make ~url:"http://localhost:3000" () in + test_urls ~name:"base_url_from_config" config + +let base_url_from_env () = + Unix.putenv "OTEL_EXPORTER_OTLP_ENDPOINT" "http://localhost:5000"; + let config = Config.make () in + test_urls ~name:"base_url_from_env" config + +let base_url_from_both_config_and_env () = + (* url from config should take precedence *) + Unix.putenv "OTEL_EXPORTER_OTLP_ENDPOINT" "http://localhost:5000"; + let config = Config.make ~url:"http://localhost:3000" () in + test_urls ~name:"base_url_from_both_config_and_env" config + +let override_trace_url_from_config () = + let config = + Config.make ~url:"http://localhost:3000" + ~url_traces:"http://localhost:3001/send/traces" () + in + test_urls ~name:"override_trace_url_from_config" config + +let override_trace_url_from_env () = + Unix.putenv "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" + "http://localhost:3001/send/traces"; + let config = Config.make () in + test_urls ~name:"override_trace_url_from_config" config + +let override_trace_url_from_both_config_and_env () = + Unix.putenv "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" + "http://localhost:3001/send/traces/env"; + let config = + Config.make ~url_traces:"http://localhost:3001/send/traces/config" () + in + test_urls ~name:"override_trace_url_from_both_config_and_env" config + +let set_all_in_config () = + let config = + Config.make ~url_traces:"http://localhost:3001/send/traces" + ~url_metrics:"http://localhost:3002/send/metrics" + ~url_logs:"http://localhost:3003/send/logs" () + in + test_urls ~name:"set_all_in_config" config + +let set_all_in_env () = + Unix.putenv "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" + "http://localhost:3001/send/traces"; + Unix.putenv "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT" + "http://localhost:3002/send/metrics"; + Unix.putenv "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT" + "http://localhost:3003/send/logs"; + let config = Config.make () in + test_urls ~name:"set_all_in_config" config + +let remove_trailing_slash_config () = + let config = Config.make ~url:"http://localhost:3000/" () in + test_urls ~name:"remove_trailing_slash_config" config + +let remove_trailing_slash_env () = + Unix.putenv "OTEL_EXPORTER_OTLP_ENDPOINT" "http://localhost:3000/"; + let config = Config.make () in + test_urls ~name:"remove_trailing_slash_config" config + +let () = default_url () + +let () = base_url_from_config () + +let () = base_url_from_env () + +let () = base_url_from_both_config_and_env () + +let () = override_trace_url_from_config () + +let () = override_trace_url_from_env () + +let () = override_trace_url_from_both_config_and_env () + +let () = set_all_in_config () + +let () = set_all_in_env () + +let () = remove_trailing_slash_config () + +let () = remove_trailing_slash_env () From fd0f1617b6e066199085dca32137b3b1c58b51ec Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Mon, 5 Aug 2024 09:41:04 +0200 Subject: [PATCH 2/7] Update src/client-ocurl/config.mli Co-authored-by: Simon Cruanes --- src/client-ocurl/config.mli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client-ocurl/config.mli b/src/client-ocurl/config.mli index b24e350d..7d2a5514 100644 --- a/src/client-ocurl/config.mli +++ b/src/client-ocurl/config.mli @@ -55,7 +55,7 @@ val make : @param url base url used to construct per-signal urls. Per-signal url options take precedence over this base url. Default is "http://localhost:4318", or "OTEL_EXPORTER_OTLP_ENDPOINT" if set. - Example of constrcuted per-singal urls with the base url http://localhost:4318 + Example of constructed per-signal urls with the base url http://localhost:4318 - Traces: http://localhost:4318/v1/traces - Metrics: http://localhost:4318/v1/metrics - Logs: http://localhost:4318/v1/logs From 1b7b8edbe00415ccd033f4777855d468af821052 Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Mon, 5 Aug 2024 09:45:15 +0200 Subject: [PATCH 3/7] remove get_url in tests --- tests/bin/emit1.ml | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/bin/emit1.ml b/tests/bin/emit1.ml index cf40e2ef..99b112a3 100644 --- a/tests/bin/emit1.ml +++ b/tests/bin/emit1.ml @@ -78,7 +78,6 @@ let run_job () = done let run () = - Printf.printf "collector is on %S\n%!" (Opentelemetry_client_ocurl.get_url ()); T.GC_metrics.basic_setup (); T.Metrics_callbacks.register (fun () -> From 3daa0d87620385bca763cf8330e6466a791956c7 Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Mon, 5 Aug 2024 10:00:52 +0200 Subject: [PATCH 4/7] port changes to cohttp client --- src/client-cohttp-lwt/common_.ml | 30 ++++++-- src/client-cohttp-lwt/config.ml | 59 +++++++++++++--- src/client-cohttp-lwt/config.mli | 28 +++++++- .../opentelemetry_client_cohttp_lwt.ml | 68 +++++++++---------- .../opentelemetry_client_cohttp_lwt.mli | 6 -- tests/bin/cohttp_client.ml | 2 - tests/bin/emit1_cohttp.ml | 2 - tests/cohttp/test_get_url.ml | 1 - 8 files changed, 129 insertions(+), 67 deletions(-) diff --git a/src/client-cohttp-lwt/common_.ml b/src/client-cohttp-lwt/common_.ml index 091896aa..0219c525 100644 --- a/src/client-cohttp-lwt/common_.ml +++ b/src/client-cohttp-lwt/common_.ml @@ -14,12 +14,30 @@ let debug_ = let default_url = "http://localhost:4318" -let url = - ref (try Sys.getenv "OTEL_EXPORTER_OTLP_ENDPOINT" with _ -> default_url) - -let get_url () = !url - -let set_url s = url := s +let make_get_from_env env_name = + let value = ref None in + fun () -> + match !value with + | None -> + value := Sys.getenv_opt env_name; + !value + | Some value -> Some value + +let get_url_from_env = make_get_from_env "OTEL_EXPORTER_OTLP_ENDPOINT" + +let get_url_traces_from_env = + make_get_from_env "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" + +let get_url_metrics_from_env = + make_get_from_env "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT" + +let get_url_logs_from_env = make_get_from_env "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT" + +let remove_trailing_slash url = + if url <> "" && String.get url (String.length url - 1) = '/' then + String.sub url 0 (String.length url - 1) + else + url let parse_headers s = let parse_header s = diff --git a/src/client-cohttp-lwt/config.ml b/src/client-cohttp-lwt/config.ml index 4e90283f..e29a0b96 100644 --- a/src/client-cohttp-lwt/config.ml +++ b/src/client-cohttp-lwt/config.ml @@ -2,7 +2,9 @@ open Common_ type t = { debug: bool; - url: string; + url_traces: string; + url_metrics: string; + url_logs: string; headers: (string * string) list; batch_traces: int option; batch_metrics: int option; @@ -16,7 +18,9 @@ let pp out self : unit = let ppheaders = Format.pp_print_list pp_header in let { debug; - url; + url_traces; + url_metrics; + url_logs; headers; batch_traces; batch_metrics; @@ -26,17 +30,52 @@ let pp out self : unit = self in Format.fprintf out - "{@[ debug=%B;@ url=%S;@ headers=%a;@ batch_traces=%a;@ batch_metrics=%a;@ \ - batch_logs=%a;@ batch_timeout_ms=%d; @]}" - debug url ppheaders headers ppiopt batch_traces ppiopt batch_metrics ppiopt - batch_logs batch_timeout_ms + "{@[ debug=%B;@ url_traces=%S;@ url_metrics=%S;@ url_logs=%S;@ \ + headers=%a;@ batch_traces=%a;@ batch_metrics=%a;@ batch_logs=%a;@ \ + batch_timeout_ms=%d; @]}" + debug url_traces url_metrics url_logs ppheaders headers ppiopt batch_traces + ppiopt batch_metrics ppiopt batch_logs batch_timeout_ms + +let make ?(debug = !debug_) ?url ?url_traces ?url_metrics ?url_logs + ?(headers = get_headers ()) ?(batch_traces = Some 400) + ?(batch_metrics = Some 20) ?(batch_logs = Some 400) + ?(batch_timeout_ms = 500) () : t = + let url_traces, url_metrics, url_logs = + let base_url = + match url with + | None -> Option.value (get_url_from_env ()) ~default:default_url + | Some url -> remove_trailing_slash url + in + let url_traces = + match url_traces with + | None -> + Option.value + (get_url_traces_from_env ()) + ~default:(base_url ^ "/v1/traces") + | Some url -> url + in + let url_metrics = + match url_metrics with + | None -> + Option.value + (get_url_metrics_from_env ()) + ~default:(base_url ^ "/v1/metrics") + | Some url -> url + in + let url_logs = + match url_logs with + | None -> + Option.value (get_url_logs_from_env ()) ~default:(base_url ^ "/v1/logs") + | Some url -> url + in + url_traces, url_metrics, url_logs + in -let make ?(debug = !debug_) ?(url = get_url ()) ?(headers = get_headers ()) - ?(batch_traces = Some 400) ?(batch_metrics = Some 20) - ?(batch_logs = Some 400) ?(batch_timeout_ms = 500) () : t = { debug; - url; + url_traces; + url_metrics; + url_logs; headers; batch_traces; batch_metrics; diff --git a/src/client-cohttp-lwt/config.mli b/src/client-cohttp-lwt/config.mli index 2aded994..ecdc73f0 100644 --- a/src/client-cohttp-lwt/config.mli +++ b/src/client-cohttp-lwt/config.mli @@ -1,8 +1,8 @@ type t = private { debug: bool; - url: string; - (** Url of the endpoint. Default is "http://localhost:4318", - or "OTEL_EXPORTER_OTLP_ENDPOINT" if set. *) + url_traces: string; (** Url to send traces *) + url_metrics: string; (** Url to send metrics*) + url_logs: string; (** Url to send logs *) headers: (string * string) list; (** API headers sent to the endpoint. Default is none or "OTEL_EXPORTER_OTLP_HEADERS" if set. *) @@ -37,6 +37,9 @@ type t = private { val make : ?debug:bool -> ?url:string -> + ?url_traces:string -> + ?url_metrics:string -> + ?url_logs:string -> ?headers:(string * string) list -> ?batch_traces:int option -> ?batch_metrics:int option -> @@ -49,6 +52,25 @@ val make : @param thread if true and [bg_threads] is not provided, we will pick a number of bg threads. Otherwise the number of [bg_threads] superseeds this option. + @param url base url used to construct per-signal urls. Per-signal url options take precedence over this base url. + Default is "http://localhost:4318", or "OTEL_EXPORTER_OTLP_ENDPOINT" if set. + + Example of constructed per-signal urls with the base url http://localhost:4318 + - Traces: http://localhost:4318/v1/traces + - Metrics: http://localhost:4318/v1/metrics + - Logs: http://localhost:4318/v1/logs + + Use per-signal url options if different urls are needed for each signal type. + + @param url_traces url to send traces, or "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" if set. + The url is used as-is without any modification. + + @param url_metrics url to send metrics, or "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT" if set. + The url is used as-is without any modification. + + @param url_logs url to send logs, or "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT" if set. + The url is used as-is without any modification. + *) val pp : Format.formatter -> t -> unit diff --git a/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml b/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml index b078c5b2..5050f35e 100644 --- a/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml +++ b/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml @@ -73,7 +73,7 @@ module Httpc : sig val send : t -> config:Config.t -> - path:string -> + url:string -> decode:[ `Dec of Pbrt.Decoder.t -> 'a | `Ret of 'a ] -> string -> ('a, error) result Lwt.t @@ -91,17 +91,9 @@ end = struct let cleanup _self = () (* send the content to the remote endpoint/path *) - let send (_self : t) ~(config : Config.t) ~path ~decode (bod : string) : + let send (_self : t) ~(config : Config.t) ~url ~decode (bod : string) : ('a, error) result Lwt.t = - let url = - let url = config.url in - if url <> "" && String.get url (String.length url - 1) = '/' then - String.sub url 0 (String.length url - 1) - else - url - in - let full_url = url ^ path in - let uri = Uri.of_string full_url in + let uri = Uri.of_string url in let open Cohttp in let headers = Header.(add_list (init ()) !headers) in @@ -121,7 +113,7 @@ end = struct | Error e -> let err = `Failure - (spf "sending signals via http POST to %S\nfailed with:\n%s" full_url + (spf "sending signals via http POST to %S\nfailed with:\n%s" url (Printexc.to_string e)) in Lwt.return @@ Error err @@ -158,7 +150,7 @@ end = struct %s\n\ status: %S\n\ %s" - full_url code (Printexc.to_string e) body bt)) + url code (Printexc.to_string e) body bt)) in Lwt.return r ) @@ -292,11 +284,11 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) = let set_on_tick_callbacks = Atomic.set on_tick_cbs_ - let send_http_ (httpc : Httpc.t) encoder ~path ~encode x : unit Lwt.t = + let send_http_ (httpc : Httpc.t) encoder ~url ~encode x : unit Lwt.t = Pbrt.Encoder.reset encoder; encode x encoder; let data = Pbrt.Encoder.to_string encoder in - let* r = Httpc.send httpc ~config ~path ~decode:(`Ret ()) data in + let* r = Httpc.send httpc ~config ~url ~decode:(`Ret ()) data in match r with | Ok () -> Lwt.return () | Error `Sysbreak -> @@ -317,7 +309,8 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) = Metrics_service.default_export_metrics_service_request ~resource_metrics:l () in - send_http_ curl encoder ~path:"/v1/metrics" + let url = config.Config.url_metrics in + send_http_ curl encoder ~url ~encode:Metrics_service.encode_pb_export_metrics_service_request x let send_traces_http curl encoder (l : Trace.resource_spans list list) = @@ -325,7 +318,8 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) = let x = Trace_service.default_export_trace_service_request ~resource_spans:l () in - send_http_ curl encoder ~path:"/v1/traces" + let url = config.Config.url_traces in + send_http_ curl encoder ~url ~encode:Trace_service.encode_pb_export_trace_service_request x let send_logs_http curl encoder (l : Logs.resource_logs list list) = @@ -333,7 +327,8 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) = let x = Logs_service.default_export_logs_service_request ~resource_logs:l () in - send_http_ curl encoder ~path:"/v1/logs" + let url = config.Config.url_logs in + send_http_ curl encoder ~url ~encode:Logs_service.encode_pb_export_logs_service_request x (* emit metrics, if the batch is full or timeout lapsed *) @@ -459,12 +454,13 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) = end in (module M) -module Backend (Arg : sig - val stop : bool Atomic.t +module Backend + (Arg : sig + val stop : bool Atomic.t - val config : Config.t -end) -() : Opentelemetry.Collector.BACKEND = struct + val config : Config.t + end) + () : Opentelemetry.Collector.BACKEND = struct include (val mk_emitter ~stop:Arg.stop ~config:Arg.config ()) open Opentelemetry.Proto @@ -475,10 +471,10 @@ end) send = (fun l ~ret -> (if !debug_ then - let@ () = Lock.with_lock in - Format.eprintf "send spans %a@." - (Format.pp_print_list Trace.pp_resource_spans) - l); + let@ () = Lock.with_lock in + Format.eprintf "send spans %a@." + (Format.pp_print_list Trace.pp_resource_spans) + l); push_trace l; ret ()); } @@ -532,10 +528,10 @@ end) send = (fun m ~ret -> (if !debug_ then - let@ () = Lock.with_lock in - Format.eprintf "send metrics %a@." - (Format.pp_print_list Metrics.pp_resource_metrics) - m); + let@ () = Lock.with_lock in + Format.eprintf "send metrics %a@." + (Format.pp_print_list Metrics.pp_resource_metrics) + m); let m = List.rev_append (additional_metrics ()) m in push_metrics m; @@ -547,10 +543,10 @@ end) send = (fun m ~ret -> (if !debug_ then - let@ () = Lock.with_lock in - Format.eprintf "send logs %a@." - (Format.pp_print_list Logs.pp_resource_logs) - m); + let@ () = Lock.with_lock in + Format.eprintf "send logs %a@." + (Format.pp_print_list Logs.pp_resource_logs) + m); push_logs m; ret ()); @@ -560,8 +556,6 @@ end let create_backend ?(stop = Atomic.make false) ?(config = Config.make ()) () = debug_ := config.debug; - if config.url <> get_url () then set_url config.url; - let module B = Backend (struct diff --git a/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.mli b/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.mli index fa25dcfe..09f64e7a 100644 --- a/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.mli +++ b/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.mli @@ -5,12 +5,6 @@ open Common_ -val get_url : unit -> string - -val set_url : string -> unit -(** Url of the endpoint. Default is "http://localhost:4318", - or "OTEL_EXPORTER_OTLP_ENDPOINT" if set. *) - val get_headers : unit -> (string * string) list val set_headers : (string * string) list -> unit diff --git a/tests/bin/cohttp_client.ml b/tests/bin/cohttp_client.ml index 6f695287..dcd395ef 100644 --- a/tests/bin/cohttp_client.ml +++ b/tests/bin/cohttp_client.ml @@ -13,8 +13,6 @@ let mk_client ~scope = Opentelemetry_cohttp_lwt.client ~scope (module Cohttp_lwt_unix.Client) let run () = - Printf.printf "collector is on %S\n%!" - (Opentelemetry_client_cohttp_lwt.get_url ()); let open Lwt.Syntax in let rec go () = let@ scope = diff --git a/tests/bin/emit1_cohttp.ml b/tests/bin/emit1_cohttp.ml index d1c5b900..deb5359d 100644 --- a/tests/bin/emit1_cohttp.ml +++ b/tests/bin/emit1_cohttp.ml @@ -74,8 +74,6 @@ let run_job () : unit Lwt.t = done let run () : unit Lwt.t = - Printf.printf "collector is on %S\n%!" - (Opentelemetry_client_cohttp_lwt.get_url ()); T.GC_metrics.basic_setup (); T.Metrics_callbacks.register (fun () -> diff --git a/tests/cohttp/test_get_url.ml b/tests/cohttp/test_get_url.ml index 3a271956..40d9b11d 100644 --- a/tests/cohttp/test_get_url.ml +++ b/tests/cohttp/test_get_url.ml @@ -3,7 +3,6 @@ let url = "http://localhost:3000" let cohttp () = let config = Opentelemetry_client_cohttp_lwt.Config.make ~url () in Opentelemetry_client_cohttp_lwt.with_setup ~config () @@ fun () -> - let url = Opentelemetry_client_cohttp_lwt.get_url () in print_endline @@ Printf.sprintf "cohttp url = %s" url let () = cohttp () From 8aafa45896fad92aebd6d477cd18751b66beec7a Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Mon, 5 Aug 2024 10:04:12 +0200 Subject: [PATCH 5/7] port urls test + rename --- tests/cohttp/dune | 2 +- tests/cohttp/test_get_url.expected | 1 - tests/cohttp/test_get_url.ml | 8 -- .../test_urls.expected} | 0 tests/cohttp/test_urls.ml | 97 +++++++++++++++++++ tests/ocurl/dune | 3 +- tests/ocurl/test_urls.expected | 66 +++++++++++++ tests/ocurl/{test_get_url.ml => test_urls.ml} | 0 8 files changed, 165 insertions(+), 12 deletions(-) delete mode 100644 tests/cohttp/test_get_url.expected delete mode 100644 tests/cohttp/test_get_url.ml rename tests/{ocurl/test_get_url.expected => cohttp/test_urls.expected} (100%) create mode 100644 tests/cohttp/test_urls.ml create mode 100644 tests/ocurl/test_urls.expected rename tests/ocurl/{test_get_url.ml => test_urls.ml} (100%) diff --git a/tests/cohttp/dune b/tests/cohttp/dune index b467b27c..162b785a 100644 --- a/tests/cohttp/dune +++ b/tests/cohttp/dune @@ -1,4 +1,4 @@ (tests - (names test_get_url) + (names test_urls) (package opentelemetry-client-cohttp-lwt) (libraries opentelemetry opentelemetry-client-cohttp-lwt)) diff --git a/tests/cohttp/test_get_url.expected b/tests/cohttp/test_get_url.expected deleted file mode 100644 index 400f46eb..00000000 --- a/tests/cohttp/test_get_url.expected +++ /dev/null @@ -1 +0,0 @@ -cohttp url = http://localhost:3000 diff --git a/tests/cohttp/test_get_url.ml b/tests/cohttp/test_get_url.ml deleted file mode 100644 index 40d9b11d..00000000 --- a/tests/cohttp/test_get_url.ml +++ /dev/null @@ -1,8 +0,0 @@ -let url = "http://localhost:3000" - -let cohttp () = - let config = Opentelemetry_client_cohttp_lwt.Config.make ~url () in - Opentelemetry_client_cohttp_lwt.with_setup ~config () @@ fun () -> - print_endline @@ Printf.sprintf "cohttp url = %s" url - -let () = cohttp () diff --git a/tests/ocurl/test_get_url.expected b/tests/cohttp/test_urls.expected similarity index 100% rename from tests/ocurl/test_get_url.expected rename to tests/cohttp/test_urls.expected diff --git a/tests/cohttp/test_urls.ml b/tests/cohttp/test_urls.ml new file mode 100644 index 00000000..73d4e924 --- /dev/null +++ b/tests/cohttp/test_urls.ml @@ -0,0 +1,97 @@ +open Opentelemetry_client_cohttp_lwt + +let test_urls ~name config = + Printf.printf "--- %s ---\n" name; + Printf.printf "url_traces = %s\n" config.Config.url_traces; + Printf.printf "url_metrics = %s\n" config.Config.url_metrics; + Printf.printf "url_logs = %s\n" config.Config.url_logs; + print_endline "------\n" + +let default_url () = + let config = Config.make () in + test_urls ~name:"default_url" config + +let base_url_from_config () = + let config = Config.make ~url:"http://localhost:3000" () in + test_urls ~name:"base_url_from_config" config + +let base_url_from_env () = + Unix.putenv "OTEL_EXPORTER_OTLP_ENDPOINT" "http://localhost:5000"; + let config = Config.make () in + test_urls ~name:"base_url_from_env" config + +let base_url_from_both_config_and_env () = + (* url from config should take precedence *) + Unix.putenv "OTEL_EXPORTER_OTLP_ENDPOINT" "http://localhost:5000"; + let config = Config.make ~url:"http://localhost:3000" () in + test_urls ~name:"base_url_from_both_config_and_env" config + +let override_trace_url_from_config () = + let config = + Config.make ~url:"http://localhost:3000" + ~url_traces:"http://localhost:3001/send/traces" () + in + test_urls ~name:"override_trace_url_from_config" config + +let override_trace_url_from_env () = + Unix.putenv "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" + "http://localhost:3001/send/traces"; + let config = Config.make () in + test_urls ~name:"override_trace_url_from_config" config + +let override_trace_url_from_both_config_and_env () = + Unix.putenv "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" + "http://localhost:3001/send/traces/env"; + let config = + Config.make ~url_traces:"http://localhost:3001/send/traces/config" () + in + test_urls ~name:"override_trace_url_from_both_config_and_env" config + +let set_all_in_config () = + let config = + Config.make ~url_traces:"http://localhost:3001/send/traces" + ~url_metrics:"http://localhost:3002/send/metrics" + ~url_logs:"http://localhost:3003/send/logs" () + in + test_urls ~name:"set_all_in_config" config + +let set_all_in_env () = + Unix.putenv "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" + "http://localhost:3001/send/traces"; + Unix.putenv "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT" + "http://localhost:3002/send/metrics"; + Unix.putenv "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT" + "http://localhost:3003/send/logs"; + let config = Config.make () in + test_urls ~name:"set_all_in_config" config + +let remove_trailing_slash_config () = + let config = Config.make ~url:"http://localhost:3000/" () in + test_urls ~name:"remove_trailing_slash_config" config + +let remove_trailing_slash_env () = + Unix.putenv "OTEL_EXPORTER_OTLP_ENDPOINT" "http://localhost:3000/"; + let config = Config.make () in + test_urls ~name:"remove_trailing_slash_config" config + +let () = default_url () + +let () = base_url_from_config () + +let () = base_url_from_env () + +let () = base_url_from_both_config_and_env () + +let () = override_trace_url_from_config () + +let () = override_trace_url_from_env () + +let () = override_trace_url_from_both_config_and_env () + +let () = set_all_in_config () + +let () = set_all_in_env () + +let () = remove_trailing_slash_config () + +let () = remove_trailing_slash_env () diff --git a/tests/ocurl/dune b/tests/ocurl/dune index 18a15fca..499e9ea3 100644 --- a/tests/ocurl/dune +++ b/tests/ocurl/dune @@ -1,5 +1,4 @@ - (tests - (names test_get_url) + (names test_urls) (package opentelemetry-client-ocurl) (libraries opentelemetry opentelemetry-client-ocurl)) diff --git a/tests/ocurl/test_urls.expected b/tests/ocurl/test_urls.expected new file mode 100644 index 00000000..56d92a58 --- /dev/null +++ b/tests/ocurl/test_urls.expected @@ -0,0 +1,66 @@ +--- default_url --- +url_traces = http://localhost:4318/v1/traces +url_metrics = http://localhost:4318/v1/metrics +url_logs = http://localhost:4318/v1/logs +------ + +--- base_url_from_config --- +url_traces = http://localhost:3000/v1/traces +url_metrics = http://localhost:3000/v1/metrics +url_logs = http://localhost:3000/v1/logs +------ + +--- base_url_from_env --- +url_traces = http://localhost:5000/v1/traces +url_metrics = http://localhost:5000/v1/metrics +url_logs = http://localhost:5000/v1/logs +------ + +--- base_url_from_both_config_and_env --- +url_traces = http://localhost:3000/v1/traces +url_metrics = http://localhost:3000/v1/metrics +url_logs = http://localhost:3000/v1/logs +------ + +--- override_trace_url_from_config --- +url_traces = http://localhost:3001/send/traces +url_metrics = http://localhost:3000/v1/metrics +url_logs = http://localhost:3000/v1/logs +------ + +--- override_trace_url_from_config --- +url_traces = http://localhost:3001/send/traces +url_metrics = http://localhost:5000/v1/metrics +url_logs = http://localhost:5000/v1/logs +------ + +--- override_trace_url_from_both_config_and_env --- +url_traces = http://localhost:3001/send/traces/config +url_metrics = http://localhost:5000/v1/metrics +url_logs = http://localhost:5000/v1/logs +------ + +--- set_all_in_config --- +url_traces = http://localhost:3001/send/traces +url_metrics = http://localhost:3002/send/metrics +url_logs = http://localhost:3003/send/logs +------ + +--- set_all_in_config --- +url_traces = http://localhost:3001/send/traces +url_metrics = http://localhost:3002/send/metrics +url_logs = http://localhost:3003/send/logs +------ + +--- remove_trailing_slash_config --- +url_traces = http://localhost:3001/send/traces +url_metrics = http://localhost:3002/send/metrics +url_logs = http://localhost:3003/send/logs +------ + +--- remove_trailing_slash_config --- +url_traces = http://localhost:3001/send/traces +url_metrics = http://localhost:3002/send/metrics +url_logs = http://localhost:3003/send/logs +------ + diff --git a/tests/ocurl/test_get_url.ml b/tests/ocurl/test_urls.ml similarity index 100% rename from tests/ocurl/test_get_url.ml rename to tests/ocurl/test_urls.ml From f0dd5a7a35aa5cddbd2984b7695b508ca3d1440e Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Fri, 9 Aug 2024 08:04:08 +0200 Subject: [PATCH 6/7] remove unused config parameter --- src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml b/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml index 5050f35e..05b1bab9 100644 --- a/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml +++ b/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml @@ -72,7 +72,6 @@ module Httpc : sig val send : t -> - config:Config.t -> url:string -> decode:[ `Dec of Pbrt.Decoder.t -> 'a | `Ret of 'a ] -> string -> @@ -91,8 +90,7 @@ end = struct let cleanup _self = () (* send the content to the remote endpoint/path *) - let send (_self : t) ~(config : Config.t) ~url ~decode (bod : string) : - ('a, error) result Lwt.t = + let send (_self : t) ~url ~decode (bod : string) : ('a, error) result Lwt.t = let uri = Uri.of_string url in let open Cohttp in @@ -288,7 +286,7 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) = Pbrt.Encoder.reset encoder; encode x encoder; let data = Pbrt.Encoder.to_string encoder in - let* r = Httpc.send httpc ~config ~url ~decode:(`Ret ()) data in + let* r = Httpc.send httpc ~url ~decode:(`Ret ()) data in match r with | Ok () -> Lwt.return () | Error `Sysbreak -> From e73ea7e6ad9d3610a00f97809085349d2d10b8d6 Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Fri, 9 Aug 2024 08:17:08 +0200 Subject: [PATCH 7/7] make urls from env take precedence --- src/client-cohttp-lwt/config.ml | 29 ++++++++++++----------------- src/client-ocurl/config.ml | 28 ++++++++++++---------------- tests/cohttp/test_urls.expected | 18 +++++++++--------- tests/cohttp/test_urls.ml | 8 ++++---- tests/ocurl/test_urls.expected | 18 +++++++++--------- tests/ocurl/test_urls.ml | 8 ++++---- 6 files changed, 50 insertions(+), 59 deletions(-) diff --git a/src/client-cohttp-lwt/config.ml b/src/client-cohttp-lwt/config.ml index e29a0b96..1d8605db 100644 --- a/src/client-cohttp-lwt/config.ml +++ b/src/client-cohttp-lwt/config.ml @@ -42,35 +42,30 @@ let make ?(debug = !debug_) ?url ?url_traces ?url_metrics ?url_logs ?(batch_timeout_ms = 500) () : t = let url_traces, url_metrics, url_logs = let base_url = - match url with - | None -> Option.value (get_url_from_env ()) ~default:default_url - | Some url -> remove_trailing_slash url + let base_url = + match get_url_from_env () with + | None -> Option.value url ~default:default_url + | Some url -> remove_trailing_slash url + in + remove_trailing_slash base_url in let url_traces = - match url_traces with - | None -> - Option.value - (get_url_traces_from_env ()) - ~default:(base_url ^ "/v1/traces") + match get_url_traces_from_env () with + | None -> Option.value url_traces ~default:(base_url ^ "/v1/traces") | Some url -> url in let url_metrics = - match url_metrics with - | None -> - Option.value - (get_url_metrics_from_env ()) - ~default:(base_url ^ "/v1/metrics") + match get_url_metrics_from_env () with + | None -> Option.value url_metrics ~default:(base_url ^ "/v1/metrics") | Some url -> url in let url_logs = - match url_logs with - | None -> - Option.value (get_url_logs_from_env ()) ~default:(base_url ^ "/v1/logs") + match get_url_logs_from_env () with + | None -> Option.value url_logs ~default:(base_url ^ "/v1/logs") | Some url -> url in url_traces, url_metrics, url_logs in - { debug; url_traces; diff --git a/src/client-ocurl/config.ml b/src/client-ocurl/config.ml index 1ca45a54..33767cf2 100644 --- a/src/client-ocurl/config.ml +++ b/src/client-ocurl/config.ml @@ -45,30 +45,26 @@ let make ?(debug = !debug_) ?url ?url_traces ?url_metrics ?url_logs let url_traces, url_metrics, url_logs = let base_url = - match url with - | None -> Option.value (get_url_from_env ()) ~default:default_url - | Some url -> remove_trailing_slash url + let base_url = + match get_url_from_env () with + | None -> Option.value url ~default:default_url + | Some url -> remove_trailing_slash url + in + remove_trailing_slash base_url in let url_traces = - match url_traces with - | None -> - Option.value - (get_url_traces_from_env ()) - ~default:(base_url ^ "/v1/traces") + match get_url_traces_from_env () with + | None -> Option.value url_traces ~default:(base_url ^ "/v1/traces") | Some url -> url in let url_metrics = - match url_metrics with - | None -> - Option.value - (get_url_metrics_from_env ()) - ~default:(base_url ^ "/v1/metrics") + match get_url_metrics_from_env () with + | None -> Option.value url_metrics ~default:(base_url ^ "/v1/metrics") | Some url -> url in let url_logs = - match url_logs with - | None -> - Option.value (get_url_logs_from_env ()) ~default:(base_url ^ "/v1/logs") + match get_url_logs_from_env () with + | None -> Option.value url_logs ~default:(base_url ^ "/v1/logs") | Some url -> url in url_traces, url_metrics, url_logs diff --git a/tests/cohttp/test_urls.expected b/tests/cohttp/test_urls.expected index 56d92a58..a5a359b4 100644 --- a/tests/cohttp/test_urls.expected +++ b/tests/cohttp/test_urls.expected @@ -17,25 +17,25 @@ url_logs = http://localhost:5000/v1/logs ------ --- base_url_from_both_config_and_env --- -url_traces = http://localhost:3000/v1/traces -url_metrics = http://localhost:3000/v1/metrics -url_logs = http://localhost:3000/v1/logs +url_traces = http://localhost:5000/v1/traces +url_metrics = http://localhost:5000/v1/metrics +url_logs = http://localhost:5000/v1/logs ------ --- override_trace_url_from_config --- url_traces = http://localhost:3001/send/traces -url_metrics = http://localhost:3000/v1/metrics -url_logs = http://localhost:3000/v1/logs +url_metrics = http://localhost:5000/v1/metrics +url_logs = http://localhost:5000/v1/logs ------ ---- override_trace_url_from_config --- +--- override_trace_url_from_env --- url_traces = http://localhost:3001/send/traces url_metrics = http://localhost:5000/v1/metrics url_logs = http://localhost:5000/v1/logs ------ --- override_trace_url_from_both_config_and_env --- -url_traces = http://localhost:3001/send/traces/config +url_traces = http://localhost:3001/send/traces url_metrics = http://localhost:5000/v1/metrics url_logs = http://localhost:5000/v1/logs ------ @@ -46,7 +46,7 @@ url_metrics = http://localhost:3002/send/metrics url_logs = http://localhost:3003/send/logs ------ ---- set_all_in_config --- +--- set_all_in_env --- url_traces = http://localhost:3001/send/traces url_metrics = http://localhost:3002/send/metrics url_logs = http://localhost:3003/send/logs @@ -58,7 +58,7 @@ url_metrics = http://localhost:3002/send/metrics url_logs = http://localhost:3003/send/logs ------ ---- remove_trailing_slash_config --- +--- remove_trailing_slash_env --- url_traces = http://localhost:3001/send/traces url_metrics = http://localhost:3002/send/metrics url_logs = http://localhost:3003/send/logs diff --git a/tests/cohttp/test_urls.ml b/tests/cohttp/test_urls.ml index 73d4e924..c825539e 100644 --- a/tests/cohttp/test_urls.ml +++ b/tests/cohttp/test_urls.ml @@ -21,7 +21,7 @@ let base_url_from_env () = test_urls ~name:"base_url_from_env" config let base_url_from_both_config_and_env () = - (* url from config should take precedence *) + (* url from env should take precedence *) Unix.putenv "OTEL_EXPORTER_OTLP_ENDPOINT" "http://localhost:5000"; let config = Config.make ~url:"http://localhost:3000" () in test_urls ~name:"base_url_from_both_config_and_env" config @@ -37,7 +37,7 @@ let override_trace_url_from_env () = Unix.putenv "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" "http://localhost:3001/send/traces"; let config = Config.make () in - test_urls ~name:"override_trace_url_from_config" config + test_urls ~name:"override_trace_url_from_env" config let override_trace_url_from_both_config_and_env () = Unix.putenv "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" @@ -63,7 +63,7 @@ let set_all_in_env () = Unix.putenv "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT" "http://localhost:3003/send/logs"; let config = Config.make () in - test_urls ~name:"set_all_in_config" config + test_urls ~name:"set_all_in_env" config let remove_trailing_slash_config () = let config = Config.make ~url:"http://localhost:3000/" () in @@ -72,7 +72,7 @@ let remove_trailing_slash_config () = let remove_trailing_slash_env () = Unix.putenv "OTEL_EXPORTER_OTLP_ENDPOINT" "http://localhost:3000/"; let config = Config.make () in - test_urls ~name:"remove_trailing_slash_config" config + test_urls ~name:"remove_trailing_slash_env" config let () = default_url () diff --git a/tests/ocurl/test_urls.expected b/tests/ocurl/test_urls.expected index 56d92a58..a5a359b4 100644 --- a/tests/ocurl/test_urls.expected +++ b/tests/ocurl/test_urls.expected @@ -17,25 +17,25 @@ url_logs = http://localhost:5000/v1/logs ------ --- base_url_from_both_config_and_env --- -url_traces = http://localhost:3000/v1/traces -url_metrics = http://localhost:3000/v1/metrics -url_logs = http://localhost:3000/v1/logs +url_traces = http://localhost:5000/v1/traces +url_metrics = http://localhost:5000/v1/metrics +url_logs = http://localhost:5000/v1/logs ------ --- override_trace_url_from_config --- url_traces = http://localhost:3001/send/traces -url_metrics = http://localhost:3000/v1/metrics -url_logs = http://localhost:3000/v1/logs +url_metrics = http://localhost:5000/v1/metrics +url_logs = http://localhost:5000/v1/logs ------ ---- override_trace_url_from_config --- +--- override_trace_url_from_env --- url_traces = http://localhost:3001/send/traces url_metrics = http://localhost:5000/v1/metrics url_logs = http://localhost:5000/v1/logs ------ --- override_trace_url_from_both_config_and_env --- -url_traces = http://localhost:3001/send/traces/config +url_traces = http://localhost:3001/send/traces url_metrics = http://localhost:5000/v1/metrics url_logs = http://localhost:5000/v1/logs ------ @@ -46,7 +46,7 @@ url_metrics = http://localhost:3002/send/metrics url_logs = http://localhost:3003/send/logs ------ ---- set_all_in_config --- +--- set_all_in_env --- url_traces = http://localhost:3001/send/traces url_metrics = http://localhost:3002/send/metrics url_logs = http://localhost:3003/send/logs @@ -58,7 +58,7 @@ url_metrics = http://localhost:3002/send/metrics url_logs = http://localhost:3003/send/logs ------ ---- remove_trailing_slash_config --- +--- remove_trailing_slash_env --- url_traces = http://localhost:3001/send/traces url_metrics = http://localhost:3002/send/metrics url_logs = http://localhost:3003/send/logs diff --git a/tests/ocurl/test_urls.ml b/tests/ocurl/test_urls.ml index 2fe651c4..915a397c 100644 --- a/tests/ocurl/test_urls.ml +++ b/tests/ocurl/test_urls.ml @@ -21,7 +21,7 @@ let base_url_from_env () = test_urls ~name:"base_url_from_env" config let base_url_from_both_config_and_env () = - (* url from config should take precedence *) + (* url from env should take precedence *) Unix.putenv "OTEL_EXPORTER_OTLP_ENDPOINT" "http://localhost:5000"; let config = Config.make ~url:"http://localhost:3000" () in test_urls ~name:"base_url_from_both_config_and_env" config @@ -37,7 +37,7 @@ let override_trace_url_from_env () = Unix.putenv "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" "http://localhost:3001/send/traces"; let config = Config.make () in - test_urls ~name:"override_trace_url_from_config" config + test_urls ~name:"override_trace_url_from_env" config let override_trace_url_from_both_config_and_env () = Unix.putenv "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" @@ -63,7 +63,7 @@ let set_all_in_env () = Unix.putenv "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT" "http://localhost:3003/send/logs"; let config = Config.make () in - test_urls ~name:"set_all_in_config" config + test_urls ~name:"set_all_in_env" config let remove_trailing_slash_config () = let config = Config.make ~url:"http://localhost:3000/" () in @@ -72,7 +72,7 @@ let remove_trailing_slash_config () = let remove_trailing_slash_env () = Unix.putenv "OTEL_EXPORTER_OTLP_ENDPOINT" "http://localhost:3000/"; let config = Config.make () in - test_urls ~name:"remove_trailing_slash_config" config + test_urls ~name:"remove_trailing_slash_env" config let () = default_url ()