Skip to content

Commit cde5714

Browse files
authored
CP-47867: Add observer uuid to span attributes (xapi-project#6711)
Currently, if two observers have the same name (eg. job 3931663), then it is difficult to distinguish which generated a span. This commit adds the observer uuid to the default span attributes, and updates tests accordingly.
2 parents 9903379 + 2219f13 commit cde5714

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

ocaml/tests/test_observer.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ module TracerProvider = struct
9898
; "xs.host.name"
9999
; "xs.host.uuid"
100100
; "xs.observer.name"
101+
; "xs.observer.uuid"
101102
; "service.name"
102103
]
103104

@@ -301,6 +302,7 @@ let verify_json_fields_and_values ~json =
301302
, `Assoc
302303
[
303304
("xs.pool.uuid", `String _)
305+
; ("xs.observer.uuid", `String _)
304306
; ("xs.observer.name", `String "test-observer")
305307
; ("xs.host.uuid", `String _)
306308
; ("xs.host.name", `String _)

ocaml/xapi/xapi_observer.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,19 @@ module Xapi_cluster = struct
245245
end
246246
end
247247

248-
let default_attributes ~__context ~host ~name_label ~component =
248+
let default_attributes ~__context ~host ~observer ~component =
249249
let pool = Helpers.get_pool ~__context in
250250
let host_label = Db.Host.get_name_label ~__context ~self:host in
251251
let host_uuid = Db.Host.get_uuid ~__context ~self:host in
252252
let pool_uuid = Db.Pool.get_uuid ~__context ~self:pool in
253+
let name_label = Db.Observer.get_name_label ~__context ~self:observer in
254+
let observer_uuid = Db.Observer.get_uuid ~__context ~self:observer in
253255
[
254256
("xs.pool.uuid", pool_uuid)
255257
; ("xs.host.name", host_label)
256258
; ("xs.host.uuid", host_uuid)
257259
; ("xs.observer.name", name_label)
260+
; ("xs.observer.uuid", observer_uuid)
258261
; ("service.name", to_string component)
259262
]
260263

@@ -289,13 +292,12 @@ module ObserverConfig = struct
289292
from and updated instead of being regenerated. *)
290293
let endpoints = Db.Observer.get_endpoints ~__context ~self:observer in
291294
let host = Helpers.get_localhost ~__context in
292-
let name_label = Db.Observer.get_name_label ~__context ~self:observer in
293295
{
294296
otel_service_name= to_string component
295297
; otel_resource_attributes=
296298
attributes_to_W3CBaggage
297299
(Db.Observer.get_attributes ~__context ~self:observer
298-
@ default_attributes ~__context ~host ~name_label ~component
300+
@ default_attributes ~__context ~host ~observer ~component
299301
)
300302
; xs_exporter_zipkin_endpoints= zipkin_endpoints endpoints
301303
; xs_exporter_bugtool_endpoint= bugtool_endpoint endpoints
@@ -513,11 +515,11 @@ let assert_valid_attributes attributes =
513515
attributes
514516

515517
let register_component ~__context ~self ~host ~component =
516-
let name_label = Db.Observer.get_name_label ~__context ~self in
517518
let attributes =
518-
default_attributes ~__context ~host ~name_label ~component
519+
default_attributes ~__context ~host ~observer:self ~component
519520
@ Db.Observer.get_attributes ~__context ~self
520521
in
522+
let name_label = Db.Observer.get_name_label ~__context ~self in
521523
let uuid = Db.Observer.get_uuid ~__context ~self in
522524
let endpoints = Db.Observer.get_endpoints ~__context ~self in
523525
let enabled = Db.Observer.get_enabled ~__context ~self in
@@ -691,14 +693,13 @@ let set_attributes ~__context ~self ~value =
691693
assert_valid_attributes value ;
692694
let uuid = Db.Observer.get_uuid ~__context ~self in
693695
let host = Helpers.get_localhost ~__context in
694-
let name_label = Db.Observer.get_name_label ~__context ~self in
695696
let observation_fn () =
696697
List.iter
697698
(fun c ->
698699
let module Forwarder = (val get_forwarder c : ObserverInterface) in
699700
Forwarder.set_attributes ~__context ~uuid
700701
~attributes:
701-
(default_attributes ~__context ~host ~name_label ~component:c
702+
(default_attributes ~__context ~host ~observer:self ~component:c
702703
@ value
703704
)
704705
)

0 commit comments

Comments
 (0)