File tree Expand file tree Collapse file tree 5 files changed +32
-2
lines changed Expand file tree Collapse file tree 5 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -132,6 +132,8 @@ module Hdr = struct
132
132
133
133
let location = " location"
134
134
135
+ let originator = " originator"
136
+
135
137
let traceparent = " traceparent"
136
138
137
139
let hsts = " strict-transport-security"
@@ -688,6 +690,14 @@ module Request = struct
688
690
let frame_header = if x.frame then make_frame_header headers else " " in
689
691
frame_header ^ headers ^ body
690
692
693
+ let with_originator_of req f =
694
+ Option. iter
695
+ (fun req ->
696
+ let originator = List. assoc_opt Hdr. originator req.additional_headers in
697
+ f originator
698
+ )
699
+ req
700
+
691
701
let traceparent_of req =
692
702
let open Tracing in
693
703
let ( let * ) = Option. bind in
Original file line number Diff line number Diff line change @@ -129,6 +129,8 @@ module Request : sig
129
129
val to_wire_string : t -> string
130
130
(* * [to_wire_string t] returns a string which could be sent to a server *)
131
131
132
+ val with_originator_of : t option -> (string option -> unit ) -> unit
133
+
132
134
val traceparent_of : t -> Tracing.Span .t option
133
135
134
136
val with_tracing :
Original file line number Diff line number Diff line change @@ -38,6 +38,15 @@ let with_dbg ~name ~dbg f =
38
38
(* ********************************************************************************************)
39
39
(* Random utility functions *)
40
40
41
+ let env_vars =
42
+ Some
43
+ (Array. concat
44
+ [
45
+ Forkhelpers. default_path_env_pair
46
+ ; Env_record. to_string_array [Env_record. pair (" ORIGINATOR" , " SM" )]
47
+ ]
48
+ )
49
+
41
50
type call = {
42
51
(* All calls are performed by a specific Host with a special Session and device_config *)
43
52
host_ref : API .ref_host
@@ -355,7 +364,7 @@ let exec_xmlrpc ~dbg ?context:_ ?(needs_session = true) (driver : string)
355
364
let env, exe, args =
356
365
match Xapi_observer_components. is_smapi_enabled () with
357
366
| false ->
358
- (None , exe, args)
367
+ (env_vars , exe, args)
359
368
| true ->
360
369
Xapi_observer_components. env_exe_args_of
361
370
~component: Xapi_observer_components. SMApi ~exe ~args
Original file line number Diff line number Diff line change @@ -103,13 +103,15 @@ let dir_name_of_component component =
103
103
104
104
let env_exe_args_of ~component ~exe ~args =
105
105
let dir_name_value = Filename. quote (dir_name_of_component component) in
106
+ let originator = match component with SMApi -> " SM" | _ -> " none" in
106
107
let env_vars =
107
108
Array. concat
108
109
[
109
110
Forkhelpers. default_path_env_pair
110
111
; Env_record. to_string_array
111
112
[
112
- Env_record. pair (" OBSERVER_CONFIG_DIR" , dir_name_value)
113
+ Env_record. pair (" ORIGINATOR" , originator)
114
+ ; Env_record. pair (" OBSERVER_CONFIG_DIR" , dir_name_value)
113
115
; Env_record. pair (" PYTHONPATH" , Filename. dirname exe)
114
116
]
115
117
]
Original file line number Diff line number Diff line change @@ -119,11 +119,18 @@ def with_tracecontext(self):
119
119
for k , v in headers .items ():
120
120
self .add_extra_header (k , v )
121
121
122
+ def with_originator (self ):
123
+ originator_k = "ORIGINATOR"
124
+ originator_v = os .getenv (originator_k , None )
125
+ if originator_v :
126
+ self .add_extra_header (originator_k .lower (), originator_v )
127
+
122
128
def make_connection (self , host ):
123
129
# clear the extra headers when making a new connection. This makes sure
124
130
# headers such as "traceparent" do not get duplicated.
125
131
self ._extra_headers = []
126
132
self .with_tracecontext ()
133
+ self .with_originator ()
127
134
128
135
# compatibility with parent xmlrpclib.Transport HTTP/1.1 support
129
136
if self ._connection and host == self ._connection [0 ]:
You can’t perform that action at this time.
0 commit comments