Langfuse

Send BrainstormRouter observability data to Langfuse for tracing and analytics.

Overview

BrainstormRouter's observability engine can broadcast events directly to Langfuse via OTLP. Every completion, error, and memory operation flows into Langfuse traces.

Setup

1. Get Langfuse credentials

From your Langfuse dashboard, get your:

  • Public key
  • Secret key
  • Host URL (default: https://cloud.langfuse.com)

2. Add OTLP destination

import BrainstormRouter from "brainstormrouter";

const client = new BrainstormRouter({ apiKey: "br_live_..." });

await client.observability.addDestination({
  name: "Langfuse",
  type: "otlp",
  config: {
    endpoint: "https://cloud.langfuse.com/api/public/ingestion",
    headers: {
      "X-Langfuse-Public-Key": "pk-...",
      "X-Langfuse-Secret-Key": "sk-...",
    },
  },
  event_types: ["usage", "quality", "error"],
});

await client.observability.setEnabled(true);
curl
curl -X POST https://api.brainstormrouter.com/v1/observability/destinations \
  -H "Authorization: Bearer br_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Langfuse",
    "type": "otlp",
    "config": {
      "endpoint": "https://cloud.langfuse.com/api/public/ingestion",
      "headers": {
        "X-Langfuse-Public-Key": "pk-...",
        "X-Langfuse-Secret-Key": "sk-..."
      }
    },
    "event_types": ["usage", "quality", "error"]
  }'

3. Test the connection

const destinations = await client.observability.destinations();
const langfuse = destinations.destinations.find((d) => d.name === "Langfuse");
await client.observability.testDestination(langfuse!.id);

What you get in Langfuse

BrainstormRouter eventLangfuse trace
usageGeneration trace with model, tokens, cost, latency
qualityScore attached to trace (tool-call accuracy)
errorError event with provider, status, message
guardrailSpan with safety scan results
auditMemory operation logged as observation

Memory events (unique)

BrainstormRouter is the only gateway that sends memory operation events to Langfuse. Track what the agent learns:

  • audit:append — new fact stored
  • audit:replace — fact updated
  • audit:delete — fact removed
  • audit:evict — fact evicted by sleep-time

This enables Langfuse dashboards that show memory growth, PII incidents, and sleep-time refinement activity over time.

Batching

For high-throughput workloads, add batching to reduce HTTP overhead:

await client.observability.addDestination({
  name: "Langfuse",
  type: "otlp",
  config: { endpoint: "...", headers: { ... } },
  batch: { max_size: 100, flush_interval_ms: 10000 },
});