mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 20:07:55 -04:00
make urls from env take precedence
This commit is contained in:
parent
f0dd5a7a35
commit
e73ea7e6ad
6 changed files with 50 additions and 59 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 ()
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 ()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue