JudgmentTracerProvider
Global singleton that manages Judgment tracers and context propagation.
Global singleton that manages Judgment tracers and context propagation.
Acts as the OpenTelemetry TracerProvider for the Judgment SDK.
It maintains a WeakSet of registered tracers and routes all span
creation through a ProxyTracer that delegates to the currently
active tracer.
You don't create this directly -- Tracer.init() registers with
the singleton automatically. Access it via get_instance() when
building custom integrations.
from judgeval.trace import JudgmentTracerProvider
provider = JudgmentTracerProvider.get_instance()
span = provider.get_current_span()__init__()
def __init__():get_instance()
Return the global singleton, creating it on first access.
def get_instance() -> JudgmentTracerProvider:Returns
JudgmentTracerProvider
install_as_global_tracer_provider()
Install this provider as the OpenTelemetry global tracer provider.
Returns True if the provider was successfully installed, False if another provider was already set (OpenTelemetry enforces first-writer-wins semantics).
def install_as_global_tracer_provider() -> bool:Returns
bool
register()
Add a tracer to the tracked set (weak reference).
Any span processors previously added via add_span_processor
are automatically forwarded to the tracer's underlying provider.
def register(tracer) -> None:Parameters
tracer
required:JudgmentTracer
Returns
None
deregister()
Remove a tracer from the tracked set.
def deregister(tracer) -> None:Parameters
tracer
required:JudgmentTracer
Returns
None
set_active()
Set a tracer as the active tracer for the current context.
Fails if a root span is currently recording to prevent mid-trace provider switches.
def set_active(tracer) -> bool:Parameters
tracer
required:JudgmentTracer
Returns
bool - True if the tracer was activated, False if blocked by an
active root span.
get_active_tracer()
Return the tracer active in the current async context, or None.
def get_active_tracer() -> Optional[JudgmentTracer]:Returns
Optional[JudgmentTracer]
get_current_context()
Return the current OpenTelemetry context.
def get_current_context() -> Context:Returns
Context
get_current_span()
Return the span that is active in the current context.
def get_current_span() -> Span:Returns
Span
has_active_root_span()
Check whether a root span (no parent) is currently recording.
def has_active_root_span() -> bool:Returns
bool
_get_delegate_tracer()
def _get_delegate_tracer() -> Tracer:Returns
Tracer
get_tracer()
def get_tracer(instrumenting_module_name, instrumenting_library_version=None, schema_url=None, attributes=None) -> Tracer:Parameters
instrumenting_module_name
required:str
instrumenting_library_version
:Optional[str]
None
schema_url
:Optional[str]
None
attributes
:Attributes
None
Returns
Tracer
add_span_processor()
Register a span processor with all managed tracers.
Processors are forwarded to the underlying TracerProvider of
every currently registered JudgmentTracer, and will be
automatically added to any tracer registered in the future via
register().
def add_span_processor(span_processor) -> None:Parameters
span_processor
required:SpanProcessor
Returns
None
add_instrumentation()
Register and activate a third-party OTel instrumentor.
def add_instrumentation(instrumentor) -> None:Parameters
instrumentor
requiredReturns
None
use_span()
def use_span(span, end_on_exit=False, record_exception=True, set_status_on_exception=True):Parameters
span
required:Span
end_on_exit
:bool
False
record_exception
:bool
True
set_status_on_exception
:bool
True
attach_context()
def attach_context(ctx) -> object:Parameters
ctx
required:Context
Returns
object
detach_context()
def detach_context(token) -> None:Parameters
token
requiredReturns
None
force_flush()
Flush pending spans from all registered tracers.
def force_flush(timeout_millis=30000) -> bool:Parameters
timeout_millis
:int
30000
Returns
bool
shutdown()
Shut down all registered tracers and clear the tracked set.
def shutdown() -> None:Returns
None