Node.jsSDK
SDK overview
The Because Node.js SDK public API.
The Because SDK exports a default object with all methods. Import it once and use it anywhere in your app.
import because from '@refactorlabs/because';Methods
| Method | Description |
|---|---|
because.init(options?) | Configure the SDK |
because.startTrace(name, fn) | Wrap work in a trace |
because.addSpan(type, name, ...) | Add a span to the active trace |
because.addMessage(name, text, opts?) | Add a message span |
because.setOutput(output, redact?) | Set the output on the active trace |
because.fetch(name, url, init?) | Traced fetch wrapper |
because.table(title?) | Build a table span |
because.chart(type, title?) | Build a chart span |
because.spanCell(value, span) | Create a spanning cell |
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/because/anthropic';
import { wrapOpenAI } from '@refactorlabs/because/openai';
import { wrapCollection } from '@refactorlabs/because/mongodb';Each integration uses the third-party package already installed in your project - no additional version constraints.
Named exports
import type {
BecauseOptions,
TraceOptions,
SpanOptions,
SpanType,
SpanAlert,
SpanAlertCheck,
TableData,
ChartData
// ...
} from '@refactorlabs/because';
import { BecauseError, REDACTED } from '@refactorlabs/because';See the types reference for full type definitions.