glassbrain-js
v0.1.3
Published
GlassBrain SDK for JavaScript and TypeScript - AI app error tracking, LLM tracing, and observability
Maintainers
Readme
glassbrain-js
JavaScript / TypeScript SDK for Glassbrain - AI app error tracking, LLM tracing, and observability.
Install
npm install glassbrain-jsQuick Start
import { GlassBrain } from "glassbrain-js";
const gb = new GlassBrain({
apiKey: "gb_your_api_key",
environment: "production", // optional, defaults to "production"
});
// Manually capture errors
try {
riskyOperation();
} catch (err) {
await gb.captureError(err, { userId: "u_123" });
}
// Capture warnings / info
await gb.captureWarning("Disk usage above 90%");
await gb.captureInfo("Deployment started", { version: "1.4.0" });Auto-Capture
By default the SDK installs global error handlers that capture uncaught exceptions and unhandled promise rejections. Disable this with:
const gb = new GlassBrain({ apiKey: "...", autoCapture: false });LLM Tracing
Trace every OpenAI or Anthropic request automatically:
import OpenAI from "openai";
import { GlassBrain, wrapOpenAI } from "glassbrain-js";
const gb = new GlassBrain({ apiKey: "gb_..." });
const openai = wrapOpenAI(new OpenAI(), gb);
// All chat completion calls are now traced
const res = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello!" }],
});The same pattern works for Anthropic:
import Anthropic from "@anthropic-ai/sdk";
import { GlassBrain, wrapAnthropic } from "glassbrain-js";
const gb = new GlassBrain({ apiKey: "gb_..." });
const anthropic = wrapAnthropic(new Anthropic(), gb);
const res = await anthropic.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello!" }],
});Wrapping Async Work
const result = await gb.wrap("fetchUserProfile", async () => {
return await db.users.findById(userId);
});If the wrapped function throws, the error is captured as a trace and re-thrown.
Fix Suggestions
const { id } = await gb.captureError(new Error("something broke"));
const suggestions = await gb.getSuggestions(id);
console.log(suggestions);Graceful Shutdown
process.on("SIGTERM", async () => {
await gb.flush();
process.exit(0);
});Configuration
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| apiKey | string | required | Your project API key from the Glassbrain dashboard |
| endpoint | string | https://glassbrain.dev/api/v1 | API endpoint URL |
| environment | string | production | Environment tag for traces |
| autoCapture | boolean | true | Auto-capture uncaught errors |
Documentation
Full docs at glassbrain.dev/docs
License
MIT
