Overview
Client is the main entry point for the Mirador SDK. It handles authentication, plugin registration, sampling, and creates trace builders.
Import
Web SDK:Constructor
Web SDK:Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | string | Yes (Web) / No (Node.js) | API key for authentication |
options | ClientOptions | No | Configuration options |
Options
Web SDK:Examples
Basic initialization:Sampling
Control what percentage of traces are recorded. Unsampled traces return aNoopTrace that silently discards all operations, so your code doesn’t need any conditional checks.
Fixed sample rate:
Lifecycle Callbacks
Register callbacks to observe trace lifecycle events across all traces. See the Lifecycle Callbacks guide for detailed usage patterns and examples.Methods
trace()
Creates a new trace builder. Web SDK:Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
options | TraceOptions | No | Trace configuration |
TraceOptions
Web SDK:| Option | Type | Default | Description |
|---|---|---|---|
name | string | undefined | Name identifying the trace |
traceId | string | undefined | Resume an existing trace by ID |
includeUserMeta | boolean | true | Include browser metadata |
maxRetries | number | 2 | Maximum retry attempts |
retryBackoff | number | 500 | Base backoff delay (ms) |
autoClose | boolean | false | Automatically close trace on page unload |
autoKeepAlive | boolean | true / false | Auto-start keep-alive timer (true for new traces, false when traceId is set) |
maxQueueSize | number | 4096 | Max items in flush queue before dropping |
callbacks | TraceCallbacks | undefined | Per-trace lifecycle callbacks |
| Option | Type | Default | Description |
|---|---|---|---|
name | string | undefined | Name identifying the trace |
traceId | string | undefined | Resume an existing trace by ID (e.g., from frontend SDK) |
captureStackTrace | boolean | true | Capture stack trace at trace creation |
maxRetries | number | 2 | Maximum retry attempts |
retryBackoff | number | 500 | Base backoff delay (ms) |
autoKeepAlive | boolean | true / false | Auto-start keep-alive timer (true for new traces, false when traceId is set) |
maxQueueSize | number | 4096 | Max items in flush queue before dropping |
callbacks | TraceCallbacks | undefined | Per-trace lifecycle callbacks |
Returns
Trace - A trace builder instance (or NoopTrace if the trace is not sampled)
Examples
Web SDK - Basic trace:Usage Patterns
Single Client Instance
Create one client instance and reuse it: Web SDK:Multiple Traces
A single client can create multiple concurrent traces: Web SDK:Environment-Based Configuration
Authentication
The API key is sent with every request in thex-ingest-api-key header. Keep your API key secure:
- Don’t commit it to version control
- Use environment variables
- Consider using different keys for dev/prod
Next Steps
Trace
Trace builder methods
Types
TypeScript type definitions