Skip to content

Commit c64c5b0

Browse files
committed
CP-52744: Update trace_context when starting a context span
Refresh the trace_context with the correct traceparent when creating a span with `start_tracing_helper` in `context.ml`. This ensures the tracing of the context has the correct parent. Signed-off-by: Gabriel Buica <[email protected]>
1 parent 4d8f0e5 commit c64c5b0

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

ocaml/libs/tracing/tracing.ml

+6
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ module Span = struct
425425
|> get_context
426426
|> SpanContext.context_of_span_context
427427
|> TraceContext.with_traceparent (Some traceparent)
428+
429+
let with_trace_context span trace_context =
430+
let span_context =
431+
span |> get_context |> SpanContext.with_trace_context trace_context
432+
in
433+
{span with context= span_context}
428434
end
429435

430436
module TraceMap = Map.Make (Trace_id)

ocaml/libs/tracing/tracing.mli

+2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ module Span : sig
148148
val get_attributes : t -> (string * string) list
149149

150150
val to_propagation_context : t -> TraceContext.t
151+
152+
val with_trace_context : t -> TraceContext.t -> t
151153
end
152154

153155
module TraceMap : module type of Map.Make (Trace_id)

ocaml/xapi/context.ml

+5-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,11 @@ let start_tracing_helper ?(span_attributes = []) parent_fn task_name =
337337
~parent ()
338338
with
339339
| Ok x ->
340-
x
340+
Option.map
341+
(fun span ->
342+
span |> Span.to_propagation_context |> Span.with_trace_context span
343+
)
344+
x
341345
| Error e ->
342346
R.warn "Failed to start tracing: %s" (Printexc.to_string e) ;
343347
None

0 commit comments

Comments
 (0)