@flarelog/sdk
v2.11.0
Published
Zero-dependency observability SDK with AI inference observability. Ships logs, errors, W3C traces, and AI/LLM cost & token tracking from Cloudflare Workers, Vercel, Node.js, or the browser to FlareLog or any OTLP backend.
Downloads
917
Maintainers
Readme
@flarelog/sdk
Zero-dependency observability for any JavaScript runtime.
Ships logs, errors, and W3C-propagated traces from Cloudflare Workers, Vercel, Node.js, or the browser to FlareLog or any OTLP backend. One SDK, every platform.
Documentation
Complete documentation with installation guides, API reference, framework integrations, and platform-specific setup.
Quick Start
npm install @flarelog/sdkimport { flarelog } from "@flarelog/sdk";
const logger = flarelog({});
logger.info("Hello!"); // → console (zero config)Add your API key to ship to the dashboard:
FLARELOG_API_KEY=fl_your_keyAI Inference Observability
Zero-config instrumentation for OpenAI, Anthropic, Cloudflare Workers AI, Vercel AI SDK, and any OpenAI-compatible gateway. Captures tokens, latency, cost in USD, tool calls, and errors — viewable in the AI observability dashboard.
import { flarelog } from "@flarelog/sdk";
const logger = flarelog({
apiKey: process.env.FLARELOG_API_KEY,
ai: true, // one flag — every fetch() to OpenAI/Anthropic/etc. is captured
});Need fine-grained control? Pass a config object instead:
const logger = flarelog({
apiKey: process.env.FLARELOG_API_KEY,
ai: {
captureSamples: true,
priceOverrides: { "gpt-4o": { input: 2.5, output: 10 } },
},
});You can also use flarelogAI directly (re-exported from the main package):
import { flarelog, flarelogAI } from "@flarelog/sdk";
const logger = flarelog({ apiKey: process.env.FLARELOG_API_KEY });
const handle = flarelogAI(logger);
// handle.dispose() to remove instrumentation laterStreaming OpenAI calls capture tokens when you enable usage reporting (Anthropic and Workers AI capture usage automatically):
await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.OPENAI_API_KEY}` },
body: JSON.stringify({
model: "gpt-4o",
stream: true,
stream_options: { include_usage: true }, // ← required for streaming token capture
messages: [{ role: "user", content: "Hello" }],
}),
});See the AI Observability guide for the full docs.
Features
- Zero dependencies — nothing to audit, nothing to conflict
- Any JavaScript runtime — Cloudflare Workers, Vercel, Node.js, browsers
- W3C trace propagation — distributed tracing across services
- Auto-detection — environment, release, platform
- OTLP-compatible — ships to Grafana, Honeycomb, Datadog, or any OTLP backend
- AI inference observability — zero-config token, cost, and latency tracking for OpenAI, Anthropic, Workers AI, Vercel AI SDK, and any OpenAI-compatible gateway
License
MIT
