init() / createClient()
The JavaScript SDK provides two initialization functions: init() for synchronous setup and createClient() for async setup with connection validation.
init()
Section titled “init()”function init(options?: SideSeatOptions): SideSeat;Synchronous initialization. Returns a SideSeat instance.
Parameters
Section titled “Parameters”options (optional)
Section titled “options (optional)”interface SideSeatOptions { disabled?: boolean; endpoint?: string; apiKey?: string; projectId?: string; serviceName?: string; serviceVersion?: string; framework?: Framework | string; enableTraces?: boolean; logLevel?: LogLevel; debug?: boolean;}See Configuration for details on each option.
Returns
Section titled “Returns”SideSeat — the initialized client instance.
Behavior
Section titled “Behavior”When called, init():
- Creates a
NodeTracerProviderwith resource attributes - Configures a
BatchSpanProcessorwith OTLP HTTP exporter - Registers the provider globally via
provider.register()
The function is idempotent. Multiple calls return the existing instance:
const a = init(); // Initializes OpenTelemetryconst b = init(); // Returns same instance, logs warningconsole.log(a === b); // trueExamples
Section titled “Examples”import { init } from '@sideseat/sdk';
// Minimalinit();
// With optionsconst client = init({ endpoint: 'http://sideseat.example.com:5388', projectId: 'my-project', serviceName: 'my-ai-agent', debug: true});
// Environment-basedinit({ debug: process.env.NODE_ENV !== 'production' });createClient()
Section titled “createClient()”function createClient(options?: SideSeatOptions): Promise<SideSeat>;Async initialization with connection validation. Preferred for production use.
Returns
Section titled “Returns”Promise<SideSeat> — resolves to the initialized client instance.
Behavior
Section titled “Behavior”Same as init() but additionally validates the endpoint is reachable before returning. Safe against concurrent calls — returns the same promise if called while initialization is in progress.
Examples
Section titled “Examples”import { createClient } from '@sideseat/sdk';
const client = await createClient({ endpoint: 'http://sideseat.internal:5388', projectId: 'production'});getClient()
Section titled “getClient()”function getClient(): SideSeat;Get the global SideSeat instance. Throws SideSeatError if not initialized.
import { init, getClient } from '@sideseat/sdk';
init();
// Later, in another moduleconst client = getClient();shutdown()
Section titled “shutdown()”function shutdown(): Promise<void>;Shutdown the global instance, flushing pending spans and releasing resources.
import { shutdown } from '@sideseat/sdk';
await shutdown();isInitialized()
Section titled “isInitialized()”function isInitialized(): boolean;Check whether SideSeat has been initialized.
Global Registration
Section titled “Global Registration”After initialization, any code using @opentelemetry/api will use the configured provider:
import { init } from '@sideseat/sdk';import { trace } from '@opentelemetry/api';
init();
// This tracer uses the SideSeat-configured providerconst tracer = trace.getTracer('my-module');Usage with Frameworks
Section titled “Usage with Frameworks”Vercel AI SDK
Section titled “Vercel AI SDK”import { init } from '@sideseat/sdk';import { generateText } from 'ai';import { openai } from '@ai-sdk/openai';
init();
const { text } = await generateText({ model: openai('gpt-5-mini'), prompt: 'Hello!', experimental_telemetry: { isEnabled: true },});Anthropic SDK
Section titled “Anthropic SDK”import { init } from '@sideseat/sdk';import Anthropic from '@anthropic-ai/sdk';
init();
const client = new Anthropic();
const message = await client.messages.create({ model: 'claude-sonnet-4-5-20250929', max_tokens: 1024, messages: [{ role: 'user', content: 'Hello!' }]});Express
Section titled “Express”import { init } from '@sideseat/sdk';import express from 'express';
// Initialize before creating the appinit();
const app = express();
app.get('/chat', async (req, res) => { const response = await callAIModel(req.query.message); res.json({ response });});
app.listen(3000);Automatic Shutdown
Section titled “Automatic Shutdown”The SDK automatically handles shutdown via Node.js process events. For explicit control:
import { trace } from '@opentelemetry/api';
const provider = trace.getTracerProvider();if ('forceFlush' in provider) { await provider.forceFlush();}Next Steps
Section titled “Next Steps”- Configuration — all configuration options
- Integrations — framework-specific guides