use Extensions module in opentelemetry.trace

This commit is contained in:
Simon Cruanes 2026-02-23 13:35:03 -05:00
parent 3608c218bf
commit e33a792f46
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 42 additions and 17 deletions

View file

@ -6,19 +6,30 @@ module Well_known = struct end
let on_internal_error =
ref (fun msg -> Printf.eprintf "error in Opentelemetry_trace: %s\n%!" msg)
type span_info = {
start_time: int64;
name: string;
scope: Otel.Scope.t;
parent: Otel.Span_ctx.t option;
}
module Extensions = struct
type span_info = {
start_time: int64;
name: string;
scope: Otel.Scope.t;
parent: Otel.Span_ctx.t option;
}
type Trace.span += Span_otel of span_info
let scope_of_span_info s = s.scope
type Trace.extension_event +=
| Ev_link_span of Trace.span * Trace.span
| Ev_set_span_kind of Trace.span * Otel.Span_kind.t
| Ev_record_exn of Trace.span * exn * Printexc.raw_backtrace
type Trace.span += Span_otel of span_info
type Trace.extension_event +=
| Ev_link_span of Trace.span * Trace.span
| Ev_record_exn of Trace.span * exn * Printexc.raw_backtrace
| Ev_set_span_kind of Trace.span * Otel.Span_kind.t
type Trace.metric +=
| Metric_hist of Opentelemetry_proto.Metrics.histogram_data_point
| Metric_sum_int of int
| Metric_sum_float of float
end
open Extensions
module Internal = struct
let enter_span' ?(parent_span : Trace.span option) ~__FUNCTION__ ~__FILE__

View file

@ -19,12 +19,26 @@
module Otel := Opentelemetry
module Otrace := Trace_core
type Otrace.extension_event +=
| Ev_link_span of Otrace.span * Otrace.span
(** Link the two spans together. Both must be currently active spans. *)
| Ev_set_span_kind of Otrace.span * Otel.Span_kind.t
| Ev_record_exn of Otrace.span * exn * Printexc.raw_backtrace
(** Record exception and potentially turn span to an error *)
module Extensions : sig
type span_info
val scope_of_span_info : span_info -> Otel.Scope.t
type Otrace.span += Span_otel of span_info
type Otrace.extension_event +=
| Ev_link_span of Otrace.span * Otrace.span
(** Link the two spans together. Both must be currently active spans.
*)
| Ev_record_exn of Otrace.span * exn * Printexc.raw_backtrace
| Ev_set_span_kind of Otrace.span * Otel.Span_kind.t
(** Record exception and potentially turn span to an error *)
type Otrace.metric +=
| Metric_hist of Opentelemetry_proto.Metrics.histogram_data_point
| Metric_sum_int of int
| Metric_sum_float of float
end
val on_internal_error : (string -> unit) ref
(** Callback to print errors in the library itself (ie bugs) *)