Node.js
SDK overview
Every method in the Recount Node.js SDK: tracing, spans, alerts, groups, metadata, and the table and chart builders.
The Recount SDK exports a default object with all methods. Import it once and use it anywhere in your app.
import recount from '@refactorlabs/recount';Methods
| Method | Description |
|---|---|
recount.init(options?) | Override SDK defaults (optional) |
recount.startTrace(name, fn) | Wrap work in a trace |
recount.named(name, fn) | Name the next auto-instrumented span |
recount.addSpan(type, name, ...) | Add a span to the active trace |
recount.addMessage(name, text?, opts?) | Add a message span |
recount.addAlert(label, level, opts?) | Flag the most recent span |
recount.addMetadata(data) | Attach metadata to the active trace |
recount.fetch(name, input, init?, opts?) | Traced fetch wrapper |
recount.table(title?) | Build a table span |
recount.tableFromRecords({ data, title? }) | Build a table directly from records |
recount.tableFromObject({ data, title? }) | Build a table directly from an object |
recount.spanCell(value, span) | Create a spanning cell |
recount.chart(type, title?) | Build a chart span |
recount.chartFromRecords({ type, data, labelKey, seriesKeys, title? }) | Build a chart directly from records |
Integrations
Wrap third-party clients to record spans automatically, without changing your business logic.
| Import | Description |
|---|---|
wrapAnthropic | Auto-trace Anthropic messages.create() calls |
wrapOpenAI | Auto-trace OpenAI chat.completions.create() calls |
wrapCollection | Auto-trace MongoDB collection operations |
import { wrapAnthropic } from '@refactorlabs/recount/anthropic';
import { wrapOpenAI } from '@refactorlabs/recount/openai';
import { wrapCollection } from '@refactorlabs/recount/mongodb';Each integration uses the third-party package already installed in your project - no additional version constraints.
Named exports
import type {
RecountOptions,
TraceOptions,
SpanOptions,
SpanType,
SpanAlert,
SpanAlertCheck,
SpanAlertLevel,
SpanAlertOptions,
TableData,
ChartData
// ...
} from '@refactorlabs/recount';
import { RecountError, REDACTED } from '@refactorlabs/recount';See the types reference for full type definitions.