Tracing API
This page mirrors the real SDK surface in sdk/boson-js (Boson-branded wrappers around upstream Langfuse packages). The SDK always talks to Boson’s official backend (Boson Cloud or customer-deployed Boson).
Minimal Node.js setup (recommended)
The fastest production-grade setup is to use OpenTelemetry’s Node SDK plus the Boson span processor.
1) Install
pnpm add @getboson/sdk @opentelemetry/sdk-node
2) Configure env vars
LANGFUSE_BASE_URL=https://app.getboson.com
LANGFUSE_PUBLIC_KEY=...
LANGFUSE_SECRET_KEY=...
3) Initialize tracing and instrument work
import { NodeSDK } from "@opentelemetry/sdk-node"
import { LangfuseSpanProcessor, observe, propagateAttributes } from "@getboson/sdk"
const spanProcessor = new LangfuseSpanProcessor()
const sdk = new NodeSDK({ spanProcessor, instrumentations: [] })
await sdk.start()
const run = observe(
async () => {
// Your actual work here (LLM calls, retrieval, tools…)
return { ok: true, at: new Date().toISOString() }
},
{
name: "trace-smoke-handshake",
asType: "span",
captureInput: true,
captureOutput: true,
},
)
await propagateAttributes(
{
traceName: "trace-smoke",
metadata: { env: process.env.NODE_ENV ?? "development" },
},
() => run(),
)
await spanProcessor.forceFlush()
await spanProcessor.shutdown()
await sdk.shutdown()
This is the same pattern used in sdk/boson-js/examples/trace-smoke.
Common instrumentation helpers
Depending on your app you may also use:
startActiveSpan,startActiveGeneration(span/generation helpers)startActiveObservation(more direct control over observation lifecycle)
Keep span naming stable (llm.completion, tool.execute, retrieval.query) and put variability in metadata.
Streaming output (recommended pattern)
When streaming a model response, avoid emitting an event per token. Instead:
- emit an
output.deltaevent occasionally (every N chars or on sentence boundaries), or - emit a final
outputevent with the complete text at the end
Next steps
- Learn how to structure spans: Spans
- Add eval gates: Evaluations