Skip to content

Add Langfuse tracing for Codex and Claude Code runs#15

Closed
Quantumlyy wants to merge 1 commit into
TeichAI:mainfrom
AletheiaResearch:langfuse-tracing
Closed

Add Langfuse tracing for Codex and Claude Code runs#15
Quantumlyy wants to merge 1 commit into
TeichAI:mainfrom
AletheiaResearch:langfuse-tracing

Conversation

@Quantumlyy

Copy link
Copy Markdown
Contributor

Adds opt-in Langfuse tracing for agent sessions, configured through a single shared agent.langfuse block:

agent:
  langfuse:
    enabled: true
    public_key: pk-lf-...
    secret_key: sk-lf-...
    base_url: https://cloud.langfuse.com   # or a self-hosted / host-local URL

All three credentials are required when enabled is true. Tracing is side-channel only: each agent uses its own native integration, reads transcripts, fails open, and does not change agent behavior or Teich's output files. Coverage is partial by design — Codex and Claude Code are wired; other providers are left untouched.

Codex

The codex-observability plugin is baked into the runtime image at a staging CODEX_HOME and copied into each session's CODEX_HOME at run time, so containers seed offline with no per-run network. The generated config.toml enables plugin_hooks and the tracing plugin, and codex exec runs with --dangerously-bypass-hook-trust — non-interactive exec silently skips plugin hooks without it.

Claude Code

Each session's settings.json registers the official Langfuse Stop/SessionEnd hook. The langfuse SDK is installed into /opt/venv and the hook invokes that interpreter by absolute path, because Claude sanitizes a hook's PATH and would otherwise run a Python without the SDK. The plugin is pinned to a known-good commit for reproducible image builds.

Networking

A localhost / 127.0.0.1 Langfuse base_url is rewritten to host.docker.internal for both the in-container env value and the --add-host gate, so a host-local Langfuse instance is reachable from the sandbox.

Tests

Adds tests/test_codex_langfuse.py and tests/test_langfuse_agents.py covering config validation, the Codex and Claude env wiring, the config.toml plugin blocks, the base-URL rewrite, the trust-bypass flag, and the Claude hook registration.

Opt-in via a shared `agent.langfuse` block ({enabled, public_key,
secret_key, base_url}; all three credentials required when enabled).
Tracing is side-channel only: each agent uses its own native integration,
reads transcripts, fails open, and doesn't change agent behavior or
Teich's output files.

- Codex: the codex-observability plugin is baked into the runtime image at
  a staging CODEX_HOME and seeded into each session's CODEX_HOME offline;
  the generated config enables plugin_hooks, and `codex exec` runs with
  --dangerously-bypass-hook-trust (it silently skips plugin hooks otherwise).
- Claude Code: the Langfuse Stop/SessionEnd hook is registered per session.
  The langfuse SDK is installed into /opt/venv and the hook calls that
  interpreter by absolute path, since Claude strips /opt/venv from a hook's
  PATH. The plugin is pinned to a known-good commit.

A localhost/127.0.0.1 base_url is rewritten to host.docker.internal for the
in-container env value and the --add-host gate.

Copy link
Copy Markdown
Collaborator

Superseded by #16, which carries the Langfuse tracing changes on top of the merged #14 host-auth work and keeps default Docker rebuilds free of Langfuse-only dependencies. Closing this PR to avoid merging the stale fork branch.

@armand0e armand0e closed this Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants