This document provides a comprehensive reference for the Blocklog TypeScript SDK API.
- BlocklogClient
- Configuration
- Event Methods
- Lifecycle Methods
- API Clients
- Decorators
- Tracing
- Integrations
- Error Classes
The main client class for interacting with the Blocklog API.
new BlocklogClient(config: BlocklogConfig, dependencies?: ClientDependencies)Parameters:
config- Configuration objectdependencies- Optional dependency injection overrides
Example:
const client = new BlocklogClient({
apiKey: 'your-api-key',
endpoint: 'base_url',
batchSize: 100,
flushInterval: 5000
});| Property | Type | Description |
|---|---|---|
config |
ResolvedConfig |
Resolved configuration |
transport |
SyncTransport |
HTTP transport layer |
processor |
EventProcessor |
Event processing pipeline |
traceManager |
typeof TraceManager |
Tracing manager |
buffer |
EventBuffer |
Event buffer |
memoryQueue |
MemoryQueue |
In-memory queue |
persistentQueue |
PersistentQueue |
Persistent queue |
deadLetterQueue |
DeadLetterQueue |
Dead letter queue |
decisions |
DecisionsClient |
Decisions API client |
traces |
TracesClient |
Traces API client |
approvals |
ApprovalClient |
Approvals API client |
incidents |
IncidentsClient |
Incidents API client |
compliance |
ComplianceClient |
Compliance API client |
replay |
ReplayClient |
Replay API client |
forensics |
ReplayClient |
Alias for replay client |
hitl |
ApprovalClient |
Alias for approval client |
interface BlocklogConfig {
apiKey: string;
endpoint?: string;
batchSize?: number;
flushInterval?: number;
timeout?: number;
retryCount?: number;
enableSigning?: boolean;
signingKey?: string;
signingAlg?: 'hmac-sha256' | 'ed25519';
enableCompression?: boolean;
debug?: boolean;
}interface ResolvedConfig {
apiKey: string;
endpoint: string;
batchSize: number;
flushInterval: number;
timeout: number;
retryCount: number;
enableSigning: boolean;
signingKey?: string;
signingAlg: 'hmac-sha256' | 'ed25519';
enableCompression: boolean;
debug: boolean;
}Send a single event to the Blocklog API.
event(eventType: string, payload: any, options?: EventOptions): Promise<IngestResponse>Parameters:
eventType- Event type identifierpayload- Event payload dataoptions- Optional event options
Returns: Promise<IngestResponse>
Example:
await client.event('AGENT_RUN', {
agent_id: 'my-agent',
input: 'test input',
output: 'test output'
});Enqueue an event for batch processing.
enqueue(eventType: string, payload: any, options?: EventOptions): Promise<IngestResponse | null>Parameters:
eventType- Event type identifierpayload- Event payload dataoptions- Optional event options
Returns: Promise<IngestResponse | null> - Returns null if event is buffered
Example:
await client.enqueue('TOOL_CALL', {
tool_name: 'calculator',
input: '2 + 2',
output: '4'
});Add a middleware hook to transform events.
addHook(hook: MiddlewareHook): BlocklogClientParameters:
hook- Middleware hook function
Returns: BlocklogClient - Returns client for chaining
Example:
client.addHook((event) => {
event.metadata = { ...event.metadata, enriched: true };
return event;
});Flush all buffered events to the API.
flush(): Promise<IngestResponse>Returns: Promise<IngestResponse>
Example:
await client.flush();Gracefully shutdown the client, flushing all events and cleaning up resources.
shutdown(): Promise<void>Returns: Promise<void>
Example:
await client.shutdown();Check the health status of the client.
health(): Promise<HealthStatus>Returns: Promise<HealthStatus>
Example:
const health = await client.health();
console.log(health);
// { healthy: true, queueDepth: 0, pendingEvents: 0, transportReady: true }Manages decision records.
client.decisions.create(data: Record<string, any>): Promise<any>
client.decisions.get(id: string): Promise<any>
client.decisions.list(params?: Record<string, any>): Promise<any>
client.decisions.search(query: Record<string, any>): Promise<any>
client.decisions.update(id: string, data: Record<string, any>): Promise<any>
client.decisions.verify(id: string): Promise<any>Manages trace records.
client.traces.get(id: string): Promise<any>
client.traces.list(params?: Record<string, any>): Promise<any>
client.traces.getTimeline(id: string): Promise<any>Manages approval workflows.
client.approvals.create(data: Record<string, any>): Promise<any>
client.approvals.approve(id: string, reason?: string): Promise<any>
client.approvals.reject(id: string, reason?: string): Promise<any>
client.approvals.status(id: string): Promise<any>
client.approvals.list(params?: Record<string, any>): Promise<any>Manages incident records.
client.incidents.create(data: Record<string, any>): Promise<any>
client.incidents.get(id: string): Promise<any>
client.incidents.update(id: string, data: Record<string, any>): Promise<any>
client.incidents.list(params?: Record<string, any>): Promise<any>
client.incidents.assign(id: string, assignee: string): Promise<any>
client.incidents.resolve(id: string, reason: string): Promise<any>
client.incidents.close(id: string, reason: string): Promise<any>Manages compliance operations.
client.compliance.audit(data: Record<string, any>): Promise<any>
client.compliance.verify(id: string): Promise<any>
client.compliance.export(data: Record<string, any>): Promise<any>
client.compliance.getReport(id: string): Promise<any>
client.compliance.getDashboard(params?: Record<string, any>): Promise<any>
client.compliance.shareReport(id: string, emails: string[]): Promise<any>
client.compliance.exportEvidence(id: string, format: string): Promise<any>Manages replay operations.
client.replay.reconstruct(traceId: string, options?: Record<string, any>): Promise<any>
client.replay.verify(id: string): Promise<any>
client.replay.replay(id: string, options?: Record<string, any>): Promise<any>
client.replay.get(id: string): Promise<any>
client.replay.list(params?: Record<string, any>): Promise<any>
client.replay.compare(idA: string, idB: string): Promise<any>Decorator for automatic agent tracing.
@traceAgent(options: AgentOptions | string)Parameters:
options- Agent options or agent name string
Example:
class MyAgent {
@traceAgent('my-agent')
async execute(input: string): Promise<string> {
return `processed: ${input}`;
}
}Function for agent tracing without decorators.
executeAgent<T>(agentId: string, fn: () => Promise<T>, options?: AgentOptions): Promise<T>Parameters:
agentId- Agent identifierfn- Function to executeoptions- Optional agent options
Returns: Promise<T> - Result of the function
Example:
const result = await executeAgent('my-agent', async () => {
return 'processed result';
}, { version: '1.0' });Static class for managing trace spans.
TraceManager.startSpan(name: string, options?: SpanOptions): Span
TraceManager.endSpan(span: Span | string, status?: string): void
TraceManager.currentSpan(): Span | undefined
TraceManager.parentSpan(): Span | undefined
TraceManager.runWithSpan<T>(span: Span, fn: () => Promise<T>): Promise<T>Example:
const span = TraceManager.startSpan('my-operation');
const result = await TraceManager.runWithSpan(span, async () => {
return 'result';
});
TraceManager.endSpan(span, 'success');Instrument LangChain for automatic tracing.
instrumentLangChain(): LangChainTracerReturns: LangChainTracer
Example:
const tracer = instrumentLangChain();
tracer.handleChainStart({ name: 'my-chain' }, { input: 'test' }, 'run-id');Instrument LangGraph for automatic tracing.
instrumentLangGraph(): LangGraphHooksReturns: LangGraphHooks
Example:
const hooks = instrumentLangGraph();
hooks.onNodeStart('node-a', { input: 'test' }, 'run-id');Instrument OpenAI Agents for automatic tracing.
instrumentOpenAIAgents(): OpenAIHooksReturns: OpenAIHooks
Example:
const hooks = instrumentOpenAIAgents();
hooks.onAgentRunStart('my-agent', { input: 'test' });Base API error class.
class ApiError extends BlocklogError {
statusCode: number;
errorCode: string;
details?: any;
}Authentication error (401, 403).
class AuthenticationError extends BlocklogAuthErrorRate limit error (429).
class RateLimitError extends BlocklogError {
retryAfter?: number;
}Validation error (400).
class ValidationError extends BlocklogError {
field?: string;
value?: any;
}Transport/network error.
class TransportError extends BlocklogTransportError {
statusCode: number;
details?: string;
}Set the global client for decorator usage.
setGlobalClient(client: BlocklogClient): voidExample:
const client = new BlocklogClient({ apiKey: 'your-api-key' });
setGlobalClient(client);Get the global client.
getGlobalClient(): BlocklogClient | nullReturns: BlocklogClient | null
Example:
const client = getGlobalClient();
if (client) {
await client.event('TEST_EVENT', {});
}interface IngestResponse {
ingested: number;
log_ids: string[];
}interface HealthStatus {
healthy: boolean;
queueDepth: number;
pendingEvents: number;
transportReady: boolean;
}interface EventOptions {
metadata?: Record<string, any>;
trace_id?: string;
span_id?: string;
timestamp?: string;
}interface AgentOptions {
name?: string;
version?: string;
tags?: string[];
metadata?: Record<string, any>;
}interface SpanOptions {
metadata?: Record<string, any>;
tags?: string[];
attributes?: Record<string, any>;
}- Configuration Guide - Configuration options
- Feature Guides - Feature-specific guides
- Integration Guides - Framework integrations