Module Opentelemetry_trace

opentelemetry.trace implements a Trace_core.Collector for ocaml-trace.

After installing this collector with setup, you can consume libraries that use ocaml-trace, and they will automatically emit OpenTelemetry spans and logs.

Ambient_context is used to propagate the current span to child spans.

Trace_core.extension_event is used to expose OTEL-specific features on top of the common tracing interface, e.g. to set the span kind:

  let@ span = Trace_core.with_span ~__FILE__ ~__LINE__ "my-span" in
  Opentelemetry_trace.set_span_kind span Span_kind_client
  (* ... *)
module OTEL := Opentelemetry_core
module Otrace := Trace_core
module Extensions : sig ... end

The extension events for Trace_core.

val setup : unit -> unit

Install the OTEL backend as a Trace collector. The trace collector will use Trace_provider.get, Log_provider.get, and Meter_provider.get to get the current tracer, logger, meter and use that to emit signals.

This will not do much until a proper OTEL.Exporter.t is installed via OTEL.Sdk.set.

val setup_with_otel_exporter : OTEL.Exporter.t -> unit

Same as setup, but also calls OTEL.Sdk.set otel_exporter

val setup_with_otel_backend : OTEL.Exporter.t -> unit
  • deprecated use setup_with_otel_exporter
val collector : Trace_core.collector

Make a Trace collector that uses the main OTEL providers to emit traces, metrics, and logs

val ambient_span_provider : Trace_core.Ambient_span_provider.t

Uses Ambient_context to provide contextual spans in Trace_core. It is automatically installed by the collector.

link_spans sp1 sp2 modifies sp1 by adding a span link to sp2.

  • since 0.11

link_spans sp1 sp_ctx2 modifies sp1 by adding a span link to sp_ctx2. It must be the case that sp1 is a currently active span.

  • since 0.90
val set_span_kind : Otrace.span -> OTEL.Span.kind -> unit

set_span_kind sp k sets the span's kind.

val set_span_status : Otrace.span -> OTEL.Span_status.t -> unit
  • since 0.90
val record_exception : Otrace.span -> exn -> Stdlib.Printexc.raw_backtrace -> unit

Record exception in the current span.

val with_ambient_span : Otrace.span -> (unit -> 'a) -> 'a

with_ambient_span sp f calls f() in an ambient context where sp is the current span.

val with_ambient_span_ctx : OTEL.Span_ctx.t -> (unit -> 'a) -> 'a

with_ambient_span_ctx spc f calls f() in a scope where spc is the ambient span-context

module Well_known : sig ... end