@@ -18,7 +18,10 @@ module D = Debug.Make (struct let name = "dummytaskhelper" end)
1818(* * Every operation has an origin: either the HTTP connection it came from or
1919 an internal subsystem (eg synchroniser thread / event handler
2020 thread) *)
21- type origin = Http of Http.Request .t * Unix .file_descr | Internal
21+ type origin =
22+ | Http of Http.Request .t * Unix .file_descr
23+ | Internal
24+ | Internal_Traced of Tracing.Span .t option
2225
2326let string_of_origin = function
2427 | Http (req , fd ) ->
@@ -32,7 +35,7 @@ let string_of_origin = function
3235 (* unfortunately all connections come from stunnel on localhost *)
3336 Printf. sprintf " HTTP request from %s with User-Agent: %s" peer
3437 (Option. value ~default: " unknown" req.Http.Request. user_agent)
35- | Internal ->
38+ | Internal | Internal_Traced _ ->
3639 " Internal"
3740
3841(* * A Context is used to represent every API invocation. It may be extended
@@ -105,7 +108,7 @@ let default_database () =
105108
106109let preauth ~__context =
107110 match __context.origin with
108- | Internal ->
111+ | Internal | Internal_Traced _ ->
109112 None
110113 | Http (_ , s ) -> (
111114 match Unix. getsockname s with
@@ -203,7 +206,7 @@ let trackid ?(with_brackets = false) ?(prefix = "") __context =
203206 trackid_of_session ~with_brackets ~prefix __context.session_id
204207
205208let _client_of_origin = function
206- | Internal ->
209+ | Internal | Internal_Traced _ ->
207210 None
208211 | Http (req , fd ) ->
209212 Http_svr. client_of_req_and_fd req fd
@@ -233,7 +236,9 @@ let parent_of_origin (origin : origin) span_name =
233236 let * span_context = SpanContext. of_trace_context context in
234237 let span = Tracer. span_of_span_context span_context span_name in
235238 Some span
236- | _ ->
239+ | Internal_Traced span ->
240+ span
241+ | Internal ->
237242 None
238243
239244let attribute_helper_fn f v = Option. fold ~none: [] ~some: f v
@@ -312,7 +317,7 @@ let make_attributes ?task_name ?task_id ?task_uuid ?session_id ?origin () =
312317 ; attribute_helper_fn
313318 (fun origin ->
314319 match origin with
315- | Internal ->
320+ | Internal | Internal_Traced _ ->
316321 [(" xs.xapi.task.origin" , " internal" )]
317322 | Http (req , s ) ->
318323 [attr_of_req req; attr_of_fd s] |> List. concat
@@ -518,7 +523,11 @@ let get_client_ip context =
518523 context.client |> Option. map (fun (_ , ip ) -> Ipaddr. to_string ip)
519524
520525let get_user_agent context =
521- match context.origin with Internal -> None | Http (rq , _ ) -> rq.user_agent
526+ match context.origin with
527+ | Internal | Internal_Traced _ ->
528+ None
529+ | Http (rq , _ ) ->
530+ rq.user_agent
522531
523532let finally_destroy_context ~__context f =
524533 let tracing = __context.tracing in
0 commit comments