> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fiddler.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# FiddlerClient

> Primary entry point for Fiddler AI observability in JavaScript/TypeScript.

Primary entry point for Fiddler AI observability in JavaScript/TypeScript.

Creates an isolated OpenTelemetry BasicTracerProvider that exports
traces to the Fiddler backend via OTLP HTTP.  The provider is **not**
registered globally, so it will not interfere with other OTel
instrumentation in the same process.

**Node.js only** — registers a `process.beforeExit` handler for
automatic shutdown.  The `process` guard is safe in non-Node
environments but OTel SDK dependencies require Node.js >= 20.

## Methods

### `constructor(config: FiddlerClientConfig)`

Create a new Fiddler client and initialize the OTel provider.

<ParamField path="config" type="FiddlerClientConfig" required={true}>
  Client configuration including Fiddler URL, API key,
  and application ID.
</ParamField>

### `async flush(): Promise<void>`

Force-flush all buffered spans to the Fiddler backend.

Call this before process exit in short-lived scripts to ensure all
spans are exported.

### `async shutdown(): Promise<void>`

Flush remaining spans and shut down the underlying OTel provider.

After shutdown the client cannot create new spans.  This method is
idempotent — calling it multiple times is safe.

### `startAgent(name: string, options?: Omit<StartSpanOptions, "type">): FiddlerAgentSpan`

Start a new agent/chain span (sets `fiddler.span.type` to `"chain"`).

<ParamField path="name" type="string" required={true}>
  Human-readable name for the agent span.
</ParamField>

<ParamField path="options" type="Omit<StartSpanOptions, &#x22;type&#x22;>" required={false}>
  Optional parent span for nesting.
</ParamField>

<ResponseField name="return">
  A new FiddlerAgentSpan with agent-specific helpers.
</ResponseField>

### `startGeneration(name: string, options?: Omit<StartSpanOptions, "type">): FiddlerGenerationSpan`

Start a new LLM generation span (sets `fiddler.span.type` to `"llm"`).

<ParamField path="name" type="string" required={true}>
  Human-readable name for the generation span.
</ParamField>

<ParamField path="options" type="Omit<StartSpanOptions, &#x22;type&#x22;>" required={false}>
  Optional parent span for nesting.
</ParamField>

<ResponseField name="return">
  A new FiddlerGenerationSpan with LLM-specific helpers.
</ResponseField>

### `startSpan(name: string, options?: StartSpanOptions): FiddlerSpan`

Start a new span with an optional explicit type.

<ParamField path="name" type="string" required={true}>
  Human-readable name for the span.
</ParamField>

<ParamField path="options" type="StartSpanOptions" required={false}>
  Optional span type and parent span.
</ParamField>

<ResponseField name="return">
  A new FiddlerSpan instance.
</ResponseField>

### `startTool(name: string, options?: Omit<StartSpanOptions, "type">): FiddlerToolSpan`

Start a new tool span (sets `fiddler.span.type` to `"tool"`).

<ParamField path="name" type="string" required={true}>
  Human-readable name for the tool span.
</ParamField>

<ParamField path="options" type="Omit<StartSpanOptions, &#x22;type&#x22;>" required={false}>
  Optional parent span for nesting.
</ParamField>

<ResponseField name="return">
  A new FiddlerToolSpan with tool-specific helpers.
</ResponseField>
