revert: use collector again for self-tracing spans

it's less dangerous to emit spans for self-tracing, even
if nothing else is going on, than risk having them accumulate
in case the program emits no spans but emits a lot of
metrics and logs (which create self-tracing spans)
This commit is contained in:
Simon Cruanes 2023-12-20 16:05:25 -05:00
parent 9c2b885f95
commit 133b6ad991
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -17,11 +17,7 @@ let timeout_gc_metrics = Mtime.Span.(20 * s)
(** side channel for GC, appended to metrics batch data *) (** side channel for GC, appended to metrics batch data *)
let gc_metrics = AList.make () let gc_metrics = AList.make ()
(** Side channel for self-tracing *) (** Mini tracing module (disabled if [config.self_trace=false]) *)
let self_spans = AList.make ()
(** Mini tracing module that doesn't go through the
collector (and thus doesn't create new batches, etc.) *)
module Self_trace = struct module Self_trace = struct
let enabled = Atomic.make true let enabled = Atomic.make true
@ -31,34 +27,10 @@ module Self_trace = struct
let dummy_span_id = Span_id.create () let dummy_span_id = Span_id.create ()
let with_ ?kind ?(attrs = []) name f = let with_ ?kind ?attrs name f =
if Atomic.get enabled then ( if Atomic.get enabled then
let scope = Scope.get_ambient_scope () in Opentelemetry.Trace.with_ ?kind ?attrs name f
let parent, trace_id = else (
match scope with
| None -> None, Trace_id.create ()
| Some sc -> Some sc.span_id, sc.trace_id
in
let span_id = Span_id.create () in
let start_time = Timestamp_ns.now_unix_ns () in
let scope = { Scope.trace_id; span_id; events = []; attrs } in
let finally () =
let span, _ =
(* TODO: should the attrs passed to with_ go on the Span
(in Span.create) or on the ResourceSpan (in emit)?
(question also applies to Opentelemetry_lwt.Trace.with) *)
Span.create ~trace_id ?parent ?kind ~attrs:scope.attrs ~id:span_id
~start_time
~end_time:(Timestamp_ns.now_unix_ns ())
name
in
AList.add self_spans span
in
let@ () = Scope.with_ambient_scope scope in
Fun.protect ~finally (fun () -> f scope)
) else (
(* do nothing *) (* do nothing *)
let scope = let scope =
{ {
@ -344,16 +316,8 @@ end = struct
in in
let send_traces () = let send_traces () =
let traces = Batch.pop_all batches.traces in B_queue.push self.send_q
let self_spans = AList.pop_all self_spans in (To_send.Send_trace (Batch.pop_all batches.traces))
let traces =
if self_spans != [] then (
let resource = Opentelemetry.Trace.make_resource_spans self_spans in
[ resource ] :: traces
) else
traces
in
B_queue.push self.send_q (To_send.Send_trace traces)
in in
try try