---
title: JudgmentTracerProvider
seo:
  title: JudgmentTracerProvider — Python SDK
  description: >-
    Global singleton that manages Judgment tracers and context propagation.
    (Python SDK)
description: 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.

```python
from judgeval.trace import JudgmentTracerProvider

provider = JudgmentTracerProvider.get_instance()
span = provider.get_current_span()
```

## \_\_init\_\_()

```python
def __init__():
```

***

## get\_instance()

Return the global singleton, creating it on first access.

```python
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).

```python
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.

```python
def register(tracer) -> None:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `tracer` | `JudgmentTracer` | - | |

### Returns

`None`

***

## deregister()

Remove a tracer from the tracked set.

```python
def deregister(tracer) -> None:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `tracer` | `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.

```python
def set_active(tracer) -> bool:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `tracer` | `JudgmentTracer` | - | |

### Returns

`bool` - True if the tracer was activated, False if blocked by an
active root span.

***

## restore\_active()

Restore the active tracer for the current context.

Counterpart to `set_active` for temporary activations: pass the
tracer captured via `get_active_tracer()` before the switch, or
`None` to deactivate entirely. Unlike `set_active` this does
not register the tracer.

```python
def restore_active(tracer) -> None:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `tracer` | `Optional[JudgmentTracer]` | - | |

### Returns

`None`

***

## get\_active\_tracer()

Return the tracer active in the current async context, or None.

```python
def get_active_tracer() -> Optional[JudgmentTracer]:
```

### Returns

`Optional[JudgmentTracer]`

***

## get\_current\_context()

Return the current OpenTelemetry context.

```python
def get_current_context() -> Context:
```

### Returns

`Context`

***

## get\_current\_span()

Return the span that is active in the current context.

```python
def get_current_span() -> Span:
```

### Returns

`Span`

***

## has\_active\_root\_span()

Check whether a root span (no parent) is currently recording.

```python
def has_active_root_span() -> bool:
```

### Returns

`bool`

***

## get\_tracer()

```python
def get_tracer(instrumenting_module_name, instrumenting_library_version=None, schema_url=None, attributes=None) -> Tracer:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `instrumenting_module_name` | `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()`.

```python
def add_span_processor(span_processor) -> None:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `span_processor` | `SpanProcessor` | - | |

### Returns

`None`

***

## add\_instrumentation()

Register and activate a third-party OTel instrumentor.

```python
def add_instrumentation(instrumentor) -> None:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `instrumentor` | `Any` | - | |

### Returns

`None`

***

## use\_span()

```python
def use_span(span, end_on_exit=False, record_exception=True, set_status_on_exception=True):
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `span` | `Span` | - | |
| `end_on_exit?` | `bool` | `False` | |
| `record_exception?` | `bool` | `True` | |
| `set_status_on_exception?` | `bool` | `True` | |

***

## attach\_context()

```python
def attach_context(ctx) -> Token[Context]:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `ctx` | `Context` | - | |

### Returns

`Token[Context]`

***

## detach\_context()

```python
def detach_context(token) -> None:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `token` | `Token[Context]` | - | |

### Returns

`None`

***

## force\_flush()

Flush pending spans from all registered tracers.

```python
def force_flush(timeout_millis=30000) -> bool:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `timeout_millis?` | `int` | `30000` | |

### Returns

`bool`

***

## shutdown()

Shut down all registered tracers and clear the tracked set.

```python
def shutdown() -> None:
```

### Returns

`None`
