agentleFS
lifegenieailifegenieai/claude-code-observability/skills/langfuse/SKILL.md

langfuse

Skill2 starsChanged 8 months agoMITView on GitHub

Query, analyze, and score Claude Code session traces in LangFuse. Use this skill whenever you need to check session costs, token usage, tool execution patterns, or agent performance in LangFuse. Also use when creating scores, investigating trace data, comparing runs, or when the user mentions LangFuse, observability, telemetry, traces, session costs, or wants to understand what happened in a previous Claude Code session. This skill covers both reading traces and writing scores/annotations back to LangFuse.

  • Reads credentials

10 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 10 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When the telemetry bridge is running, it catches those signals and forwards them to your LangFuse instance.

    line 20
  2. Distinctive:

    Every trace from Claude Code includes these OTEL signals:

    line 113
  3. Very specific:

    Subagent correlation: All subagent API calls and tool executions share the parent trace's prompt.id.

    line 123
  4. Distinctive:

    Create score configs to define your scoring schema, then attach scores to traces:

    line 127
  5. Distinctive:

    If the CLI doesn't surface what you're looking for:

    line 168

“Common” is measured: kept by at least 6 in 10 of the 10 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

LangFuse Observability

Access and analyze Claude Code session telemetry stored in LangFuse. This skill covers querying traces, analyzing costs and performance, and writing scores back to LangFuse.

How the Setup Works

Claude Code emits OpenTelemetry (OTEL) signals — metrics, events, and distributed traces — on every API call and tool execution, including subagent calls. These signals are configured to export to localhost:4318.

When the telemetry bridge is running, it catches those signals and forwards them to your LangFuse instance. When the bridge is off, exports silently fail with zero impact.

Claude Code (OTEL always active)
    → localhost:4318 (OTLP HTTP/JSON)
    → lainra/claude-code-telemetry bridge (Node.js)
    → cloud.langfuse.com (LangFuse Cloud)

Bridge location: ~/.claude/telemetry/claude-code-telemetry/ Bridge control: record-start / record-stop (shell functions) Credentials: LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, LANGFUSE_HOST set in your shell profile.

Primary Tool: LangFuse CLI

The langfuse-cli is installed globally and is the primary way to interact with LangFuse. Auth is handled via environment variables already configured in the shell.

langfuse api <resource> <action> [options]

Discovery pattern — when you're unsure what's available:

langfuse api __schema              # List all resources
langfuse api <resource> --help     # List actions for a resource
langfuse api <resource> <action> --help  # Show flags for an action
langfuse api <resource> <action> --curl  # Preview the curl command

Key Resources

ResourceWhat it holds
tracesOne per user prompt. Contains cost, tokens, metadata.
observationsIndividual steps within a trace (API calls, tool executions)
sessionsGroups of traces from one Claude Code CLI session
scoresQuality ratings attached to traces or observations
score-configsSchema definitions for score types
metricsAggregated data (costs, tokens, latency) across dimensions
promptsManaged prompts (not relevant to OTEL traces)
datasetsEvaluation datasets

Common Queries

List recent traces:

langfuse api traces list --limit 10

Get a specific trace by ID:

langfuse api traces get <trace-id>

List traces for a specific session:

langfuse api traces list --session-id <session-id>

List observations with cost/token data:

langfuse api observations list --fields core,usage,model --limit 20

Get aggregated metrics (cost by model):

langfuse api metrics list --view observations --measures totalCost --dimensions providedModelName --from-timestamp <ISO-date>

List sessions:

langfuse api sessions list --limit 5

For complex queries, read references/cli-patterns.md for advanced filtering, pagination, and aggregation examples.

Data Model

Understanding how LangFuse structures data helps you query effectively.

Session → contains multiple Traces → each trace contains multiple Observations

  • Session (session.id): One Claude Code CLI session. All prompts within that session share the same session ID.
  • Trace (prompt.id): One user prompt and everything it triggered — API calls, tool executions, subagent work. The trace name field shows conversation-N (the Nth prompt in the session).
  • Observation: A single step within a trace. Types:
    • GENERATION — an API call to Claude (has model, tokens, cost)
    • SPAN — a tool execution or logical grouping (has duration)
    • EVENT — a discrete event (tool_result, user_prompt, etc.)

Scores can be attached to traces or observations. They have a name, value, dataType (NUMERIC, BOOLEAN, CATEGORICAL), and source (API, ANNOTATION, EVAL).

What's Captured in Each Trace

Every trace from Claude Code includes these OTEL signals:

SignalKey Fields
api_requestmodel, cost_usd, input/output/cache tokens, duration_ms, speed
tool_resulttool_name, success, duration_ms, tool_parameters, tool_input
user_promptprompt text, prompt_length
api_errormodel, error, status_code, duration_ms
tool_decisiontool_name, decision (accept/reject), source

Subagent correlation: All subagent API calls and tool executions share the parent trace's prompt.id. A multi-agent command with 12 subagents produces one trace with all their events correlated.

Writing Scores

Create score configs to define your scoring schema, then attach scores to traces:

Create a score config:

langfuse api score-configs create --name "response-quality" --data-type NUMERIC --min-value 1 --max-value 5 --description "Quality of agent response"

Score a trace via the ingestion API:

langfuse api ingestions create --body '{
  "batch": [{
    "id": "unique-event-id",
    "type": "score-create",
    "timestamp": "2026-04-03T00:00:00Z",
    "body": {
      "traceId": "<trace-id>",
      "name": "response-quality",
      "value": 4,
      "dataType": "NUMERIC",
      "source": "API"
    }
  }]
}'

Documentation & References

NeedWhere to look
CLI command referencelangfuse api <resource> <action> --help
Full API referencehttps://api.reference.langfuse.com
Data modelhttps://langfuse.com/docs/observability/data-model
Scores & evaluationhttps://langfuse.com/docs/evaluation/overview
Metrics APIhttps://langfuse.com/docs/metrics/features/metrics-api
OTEL signals from Claude Codehttps://code.claude.com/docs/en/monitoring-usage
LangFuse docs MCPAvailable as mcp__langfuse-docs__searchLangfuseDocs in session
Advanced CLI patternsRead references/cli-patterns.md
Bridge setup detailsRead references/bridge-architecture.md

When You Can't Find What You Need

If the CLI doesn't surface what you're looking for:

  1. Use the LangFuse docs MCP — mcp__langfuse-docs__searchLangfuseDocs is available for semantic search across all LangFuse documentation.
  2. Check the API reference — langfuse api <resource> <action> --curl previews the raw HTTP request, which you can adapt.
  3. Fetch a docs page directly — mcp__langfuse-docs__getLangfuseDocsPage with a path like /docs/evaluation/overview.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.