helpers for attributes

This commit is contained in:
Simon Cruanes 2022-06-07 14:48:20 -04:00
parent 99d5ba78fc
commit 5d3fa1c8eb
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -317,6 +317,10 @@ module Conventions = struct
let name = "service.name"
let namespace = "service.namespace"
let instance_id = "service.instance.id"
let version = "service.version"
end
end
@ -383,6 +387,9 @@ module Globals = struct
(** Namespace for the service *)
let service_namespace = ref None
(** Unique identifier for the service *)
let service_instance_id = ref None
let instrumentation_library =
default_instrumentation_library ~version:"0.1" ~name:"ocaml-opentelemetry"
()
@ -403,6 +410,10 @@ module Globals = struct
|> String.split_on_char ',' |> List.map parse_pair
with _ -> []
(** Add a global attribute *)
let add_global_attribute (key:string) (v:value) : unit =
global_attributes := _conv_key_value (key, v) :: !global_attributes
(* add global attributes to this list *)
let merge_global_attributes_ into : _ list =
let not_redundant kv = List.for_all (fun kv' -> kv.key <> kv'.key) into in
@ -415,6 +426,13 @@ module Globals = struct
~value:(Some (String_value service_name)) ()
:: l
in
let l =
match !service_instance_id with
| None -> l
| Some v ->
default_key_value ~key:Conventions.Attributes.Service.instance_id
~value:(Some (String_value v)) () :: l
in
let l =
match !service_namespace with
| None -> l