Judgment Labs Logo

JudgmentTracerProvider

Global singleton that manages tracer registration and context propagation. Acts as a proxy TracerProvider that delegates to the currently active tracer's underlying OpenTelemetry provider.

Global singleton that manages tracer registration and context propagation.

Acts as a proxy TracerProvider that delegates to the currently active tracer's underlying OpenTelemetry provider.

Static Method

getInstance()

Get the singleton JudgmentTracerProvider instance.

function getInstance(): JudgmentTracerProvider

Returns

JudgmentTracerProvider - The global provider instance.


Static Method

installAsGlobalTracerProvider()

Install the JudgmentTracerProvider as the global tracer provider. This generally does not need to be called - Judgeval automatically uses this for all its observability functionality. Only use this if you specifically want to override the global tracer provider, which will enable all Opentelemetry captured instrumentations to flow through judgeval.

function installAsGlobalTracerProvider(): boolean

Returns

boolean - True if the installation was successful, false otherwise.


register()

Register a tracer with the provider.

function register(tracer: BaseTracer): void

Parameters

tracer

required

:

BaseTracer

The tracer to register.

Returns

void


deregister()

Remove a tracer from the provider.

function deregister(tracer: BaseTracer): void

Parameters

tracer

required

:

BaseTracer

The tracer to deregister.

Returns

void


setActive()

Set a tracer as the active tracer.

Cannot be called while a root span is active.

function setActive(tracer: BaseTracer): boolean

Parameters

tracer

required

:

BaseTracer

The tracer to activate.

Returns

boolean - true if activation succeeded.


getActiveTracer()

Get the currently active tracer.

function getActiveTracer(): BaseTracer | null

Returns

BaseTracer | null - The active tracer, or null if none.


getCurrentContext()

Get the current OpenTelemetry context.

function getCurrentContext(): Context

Returns

Context - The current context.


setSpan()

Set a span on a context, returning a new context.

function setSpan(ctx: Context, span: Span): Context

Parameters

ctx

required

:

Context

span

required

:

Span

Returns

Context


wrapSpanContext()

Wrap a SpanContext into a non-recording Span.

function wrapSpanContext(spanContext: SpanContext): Span

Parameters

spanContext

required

:

SpanContext

Returns

Span


getCurrentSpan()

Get the span from the current context.

function getCurrentSpan(): Span | undefined

Returns

Span | undefined - The current span, or undefined if none.


hasActiveRootSpan()

Check whether there is an active root span.

function hasActiveRootSpan(): boolean

Returns

boolean - true if a root span is currently recording.


addInstrumentation()

Register an OpenTelemetry instrumentation.

function addInstrumentation(instrumentor: Instrumentation<InstrumentationConfig>): void

Parameters

instrumentor

required

:

Instrumentation<InstrumentationConfig>

The instrumentation to add.

Returns

void


withContext()

Run fn with ctx installed as the active context for the duration of the callback. Sync or async.

function withContext(ctx: Context, fn: () => T): T

Parameters

ctx

required

:

Context

fn

required

:

() => T

Returns

T


forceFlush()

Flush all registered tracers.

async function forceFlush(): Promise<void>

Returns

Promise<void>


shutdown()

Shut down all registered tracers and clear state.

async function shutdown(): Promise<void>

Returns

Promise<void>