Connect an app with the SDK, read it from the terminal
No agent to run. A small client library in your app sends events and logs over HTTP, and the optic CLI reads them back.
Not published yet. The SDK and CLI packages are not on npm, PyPI or a Go module proxy, so this page shows no install command. Early access includes them.
Adapters
The core client has no runtime dependencies. Each adapter records every request as an event with its method, path, status code and latency.
| Runtime | Entry point | Notes |
|---|---|---|
| Hono | @opsoptic/sdk/hono | Middleware for every route you register it before. |
| Express | @opsoptic/sdk/express | Middleware. |
| Next.js | @opsoptic/sdk/next | Runs in middleware.ts. It cannot see the final response status, so requests are recorded as 200. |
| Bun.serve() | @opsoptic/sdk/bun | Wraps your fetch handler. |
| Python | opsoptic | ASGI middleware, Django and Flask entry points, and a logging handler. |
| Go | Go module | net/http middleware and a slog handler. |
Any other runtime can send events by hand through the core client.
What you can send
const optic = init({ apiKey: process.env.OPSOPTIC_KEY! })
optic.identify('user-1', { plan: 'pro' })
optic.track('checkout.started', { plan: 'pro' })
// amount is in the minor unit: 2900 is 29.00 USD
optic.revenue('subscription.created', { amount: 2900, currency: 'USD' })
optic.captureError(err)The client also has a logger with debug, info, warn and error methods, and stripeRevenue(event), which turns a Stripe webhook event you have already verified into a revenue event.
Delivery behavior
- Batching
- Events are queued and flushed every 5 seconds, up to 100 per batch, by default.
- Retries
- A failed flush makes 3 attempts in total, waiting 1 second and then 4 seconds, then requeues the batch for the next cycle.
- Backpressure
- The queue holds up to 1,000 events by default. When it overflows, the oldest events are dropped first.
- Sampling
sampleRatethins request and custom events only. Errors, revenue and identify events are never sampled away.- Rejections
- A rejected key or oversized batch is reported through
onIngestError, by default as one console warning that is not repeated for 5 minutes. - Limits
- One ingest request carries at most 10,000 events or 8 MiB, whichever comes first.
The CLI
The optic command compiles to a standalone binary. Credentials are kept in ~/.optic with restricted permissions, and --profile <name> switches between named workspaces. Most commands accept --json.
optic status- Live stats for every project.
optic tail [project]- Streams events and logs. Filter with
--filter level=error,status=500,type=ERRORorpath=/api/checkout. optic watch [project]- Live events with stats, refreshed every few seconds.
optic stats [project] [period]- Summary for MINUTE, HOUR, DAY or WEEK.
optic errors [project]- Recent error log.
optic users [project] [free|paid]- Tracked users, optionally by plan.
optic deploy <project>- Records a deployment, with
--commit <sha>. optic key create|rotate|revoke- Manages SDK keys. The raw key is shown only in human output.
optic alerts list,optic backtest- List alert rules, or test a condition against historical data.
optic incidents open|list- Open or list incidents.
optic cohorts- Revenue cohort retention.
Want the client packages for a product of yours? Early access starts with a conversation.
Talk to the founder on WhatsApp