Skip to content

Commit

Permalink
helpers for attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Jun 7, 2022
1 parent 99d5ba7 commit 5d3fa1c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/opentelemetry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
()
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5d3fa1c

Please sign in to comment.