Module Opentelemetry.Trace_provider

val get : unit -> Tracer.t

Get current tracer.

val set : Tracer.t -> unit

Set current tracer

val clear : unit -> unit

Replace current tracer by the dummy one. All spans will be discarded from now on.

val get_tracer : ?name:string -> ?version:string -> ?attrs:(string * [< Opentelemetry_core.Value.t ]) list -> ?__MODULE__:string -> unit -> Tracer.t

Get a tracer pre-configured with a fixed set of attributes added to every span it emits, forwarding to the current global tracer. Intended to be called once at the top of a library module.

  • parameter name

    instrumentation scope name (recorded as otel.scope.name)

  • parameter version

    instrumentation scope version (recorded as otel.scope.version)

  • parameter __MODULE__

    the OCaml module name, typically the __MODULE__ literal (recorded as code.namespace)

  • parameter attrs

    additional fixed attributes

val default_tracer : Tracer.t

A Tracer.t that lazily reads the global at emit time

val emit : Opentelemetry_core.Span.t -> unit

Emit a span directly via the current global tracer

val with_thunk_and_finally : Tracer.t -> ?force_new_trace_id:bool -> ?trace_state:string -> ?attrs:(string * Opentelemetry_core.Value.t) list -> ?kind:Opentelemetry_core.Span.kind -> ?trace_id:Opentelemetry_core.Trace_id.t -> ?parent:Opentelemetry_core.Span.t -> ?links:Opentelemetry_core.Span_link.t list -> string -> (Opentelemetry_core.Span.t -> 'a) -> (unit -> 'a) * ((unit, exn * Stdlib.Printexc.raw_backtrace) result -> unit)

Helper to implement with_ and similar functions

val with_ : ?tracer:Tracer.t -> ?force_new_trace_id:bool -> ?trace_state:string -> ?attrs:(string * Opentelemetry_core.Value.t) list -> ?kind:Opentelemetry_core.Span.kind -> ?trace_id:Opentelemetry_core.Trace_id.t -> ?parent:Opentelemetry_core.Span.t -> ?links:Opentelemetry_core.Span_link.t list -> string -> (Opentelemetry_core.Span.t -> 'a) -> 'a

Sync span guard.

Notably, this includes implicit scope-tracking: if called without a ~scope argument (or ~parent/~trace_id), it will check in the Ambient_context for a surrounding environment, and use that as the scope. Similarly, it uses Scope.with_ambient_scope to set a new scope in the ambient context, so that any logically-nested calls to with_ will use this span as their parent.

NOTE be careful not to call this inside a Gc alarm, as it can cause deadlocks.

  • parameter tracer

    the tracer to use (default default_tracer)

  • parameter force_new_trace_id

    if true (default false), the span will not use a ambient scope, the ~scope argument, nor ~trace_id, but will instead always create fresh identifiers for this span