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

<Badge>
  Static Method
</Badge>

## getInstance()

Get the singleton JudgmentTracerProvider instance.

```typescript
function getInstance(): JudgmentTracerProvider
```

### Returns

`JudgmentTracerProvider` - The global provider instance.

***

<Badge>
  Static Method
</Badge>

## 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.

```typescript
function installAsGlobalTracerProvider(): boolean
```

### Returns

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

***

## register()

Register a tracer with the provider.

```typescript
function register(tracer: BaseTracer): void
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `tracer` | `BaseTracer` | - | The tracer to register. |

### Returns

`void`

***

## deregister()

Remove a tracer from the provider.

```typescript
function deregister(tracer: BaseTracer): void
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `tracer` | `BaseTracer` | - | The tracer to deregister. |

### Returns

`void`

***

## setActive()

Set a tracer as the active tracer.

Cannot be called while a root span is active.

```typescript
function setActive(tracer: BaseTracer): boolean
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `tracer` | `BaseTracer` | - | The tracer to activate. |

### Returns

`boolean` - `true` if activation succeeded.

***

## getActiveTracer()

Get the currently active tracer.

```typescript
function getActiveTracer(): BaseTracer | null
```

### Returns

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

***

## getCurrentContext()

Get the current OpenTelemetry context.

```typescript
function getCurrentContext(): Context
```

### Returns

`Context` - The current context.

***

## setSpan()

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

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

### Parameters

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

### Returns

`Context`

***

## wrapSpanContext()

Wrap a SpanContext into a non-recording Span.

```typescript
function wrapSpanContext(spanContext: SpanContext): Span
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `spanContext` | `SpanContext` | - | |

### Returns

`Span`

***

## getCurrentSpan()

Get the span from the current context.

```typescript
function getCurrentSpan(): Span | undefined
```

### Returns

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

***

## hasActiveRootSpan()

Check whether there is an active root span.

```typescript
function hasActiveRootSpan(): boolean
```

### Returns

`boolean` - `true` if a root span is currently recording.

***

## addInstrumentation()

Register an OpenTelemetry instrumentation.

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

### Parameters

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

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

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `ctx` | `Context` | - | |
| `fn` | `() => T` | - | |

### Returns

`T`

***

## forceFlush()

Flush all registered tracers.

```typescript
async function forceFlush(): Promise<void>
```

### Returns

`Promise<void>`

***

## shutdown()

Shut down all registered tracers and clear state.

```typescript
async function shutdown(): Promise<void>
```

### Returns

`Promise<void>`
