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:

FieldTypeDescription
typestring'logs' (default) or 'analytics'
event_typestringSubtype e.g. 'page_view', 'signup'
user_idstringUser this log is associated with
req_idstringRequest / correlation ID
routestringURL path e.g. '/api/orders'
hoststringHostname / service instance
attrsRecord<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.

Related