diff --git a/src/client/util_resources.ml b/src/client/util_resources.ml index 7ca16496..c64802e2 100644 --- a/src/client/util_resources.ml +++ b/src/client/util_resources.ml @@ -7,7 +7,8 @@ let make_resource_logs ?service_name ?attrs (logs : Proto.Logs.log_record list) let attributes = OTEL.Globals.mk_attributes ?service_name ?attrs () in let resource = Proto.Resource.make_resource ~attributes () in let ll = - Proto.Logs.make_scope_logs ~scope:OTEL.Globals.instrumentation_library + Proto.Logs.make_scope_logs + ~scope:(OTEL.Globals.instrumentation_library ()) ~log_records:logs () in Proto.Logs.make_resource_logs ~resource ~scope_logs:[ ll ] () @@ -15,7 +16,8 @@ let make_resource_logs ?service_name ?attrs (logs : Proto.Logs.log_record list) let make_resource_spans ?service_name ?attrs spans : Proto.Trace.resource_spans = let ils = - Proto.Trace.make_scope_spans ~scope:OTEL.Globals.instrumentation_library + Proto.Trace.make_scope_spans + ~scope:(OTEL.Globals.instrumentation_library ()) ~spans () in let attributes = OTEL.Globals.mk_attributes ?service_name ?attrs () in @@ -27,7 +29,9 @@ let make_resource_metrics ?service_name ?attrs (l : OTEL.Metrics.t list) : Proto.Metrics.resource_metrics = let open Proto.Metrics in let lm = - make_scope_metrics ~scope:OTEL.Globals.instrumentation_library ~metrics:l () + make_scope_metrics + ~scope:(OTEL.Globals.instrumentation_library ()) + ~metrics:l () in let attributes = OTEL.Globals.mk_attributes ?service_name ?attrs () in let resource = Proto.Resource.make_resource ~attributes () in diff --git a/src/lib/globals.ml b/src/lib/globals.ml index c4d3c55b..a6be5231 100644 --- a/src/lib/globals.ml +++ b/src/lib/globals.ml @@ -16,8 +16,14 @@ let service_instance_id = ref None @since 0.12 *) let service_version = ref None -let instrumentation_library = - make_instrumentation_scope ~version:"%%VERSION_NUM%%" ~name:"ocaml-otel" () +let instrumentation_name = ref "ocaml-otel" + +let instrumentation_runtime_version = ref "%%VERSION_NUM%%" + +let instrumentation_library () = + make_instrumentation_scope + ~version:!instrumentation_runtime_version + ~name:!instrumentation_name () (** Global attributes, initially set via OTEL_RESOURCE_ATTRIBUTES and modifiable by the user code. They will be attached to each outgoing metrics/traces. *) diff --git a/tests/bin/emit_logs_cohttp.ml b/tests/bin/emit_logs_cohttp.ml index 80a744ef..bc8fda98 100644 --- a/tests/bin/emit_logs_cohttp.ml +++ b/tests/bin/emit_logs_cohttp.ml @@ -69,6 +69,7 @@ let () = Sys.catch_break true; T.Globals.service_name := "t1"; T.Globals.service_namespace := Some "ocaml-otel.test"; + T.Globals.instrumentation_runtime_version := ""; let debug = ref false in let batch_traces = ref 400 in diff --git a/tests/client_e2e/clients_e2e_lib.ml b/tests/client_e2e/clients_e2e_lib.ml index 35e75c82..de605ccc 100644 --- a/tests/client_e2e/clients_e2e_lib.ml +++ b/tests/client_e2e/clients_e2e_lib.ml @@ -213,6 +213,7 @@ let tests params signal_batches = ] let run_tests ~port (cmds : _ list) : unit = + Opentelemetry.Globals.instrumentation_runtime_version := ""; let suites = let open Lwt.Syntax in Lwt_main.run diff --git a/tests/logs/test_logs_e2e.expected b/tests/logs/test_logs_e2e.expected index 451aad62..2eae2a56 100644 --- a/tests/logs/test_logs_e2e.expected +++ b/tests/logs/test_logs_e2e.expected @@ -19,7 +19,7 @@ [{ scope = Some( { name = "ocaml-otel"; - version = "%%VERSION_NUM%%"; + version = ""; attributes = []; dropped_attributes_count = 0 (* absent *); });