Getting Started
Get up and running with the Lightning Logs TypeScript SDK in minutes.
1. Install
npm install @lightning-logs/sdk2. Initialize the client
With an API key (server-side / Node.js)
import { LightningLogsClient } from '@lightning-logs/sdk'
const client = new LightningLogsClient({
baseURL: process.env.SUPABASE_URL!, // Your project Supabase URL
getAuthToken: async () => process.env.LIGHTNING_LOGS_API_KEY!, // Ingest API key
serviceName: 'my-api',
environment: process.env.NODE_ENV ?? 'production',
})For browser / Supabase Auth setups, see the Authentication guide.
3. Send your first log
// Fire-and-forget — buffered and flushed automatically
client.log.info('Server started', { attrs: { port: 3000 } })
client.log.warn('Rate limit approaching', { user_id: 'user-123' })
client.log.error('Payment failed', { route: '/api/checkout', req_id: requestId })4. Trace a multi-step operation
Group related work into a trace with spans — everything flushes in one request on trace.end()
const trace = client.startTrace({ name: 'api.create-order' })
const dbSpan = trace.startSpan('db.insert-order')
const order = await db.insert(orders).values({ userId }).returning()
dbSpan.end({ status: 'ok', metadata: { order_id: order.id } })
const paymentSpan = trace.startSpan('stripe.charge')
await stripe.paymentIntents.create({ amount, currency: 'usd' })
paymentSpan.end({ status: 'ok' })
// This log is automatically correlated to the trace
trace.log.info('Order created', { user_id: userId, attrs: { order_id: order.id } })
await trace.end({ status: 'ok' })