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