Logs API
Ingest log events from your application with fire-and-forget helpers or the low-level ingest API.
client.log.* — Quick Log Helpers
The fastest way to send logs. Events are buffered and flushed automatically.
client.log.debug('Cache miss', { attrs: { key: cacheKey } })
client.log.info('User signed in', { user_id: userId, route: '/login' })
client.log.warn('Quota at 80%', { attrs: { used: 8000, limit: 10000 } })
client.log.error('DB connection failed', { req_id: requestId, attrs: { host: dbHost } })Each helper accepts a LogContext with standard fields:
| Field | Type | Description |
|---|---|---|
| type | string | 'logs' (default) or 'analytics' |
| event_type | string | Subtype e.g. 'page_view', 'signup' |
| user_id | string | User this log is associated with |
| req_id | string | Request / correlation ID |
| route | string | URL path e.g. '/api/orders' |
| host | string | Hostname / service instance |
| attrs | Record<string, any> | Arbitrary key-value metadata |
For logs correlated to a trace, use trace.log.* instead — the trace_id and span_id are set automatically.
client.logs.ingest(payload): Promise<IngestResponse>
Low-level ingest — send logs, traces, and spans directly. Prefer
client.log.* for simple logging and client.startTrace() for tracing.import { generateId } from '@lightning-logs/sdk'
await client.logs.ingest({
logs: [
{
id: generateId(),
ts: new Date().toISOString(),
level: 'info',
msg: 'Batch job complete',
service: 'worker',
env: 'production',
attrs: { jobs_processed: 42 },
},
],
})The id and ts fields are required. The payload can also include traces and spans arrays — this is how the tracer flushes data internally.