Files
strukto-ai--mirage/docs/python/resource/langfuse.mdx
T
wehub-resource-sync bcbd1bdb22
Integ / changes (push) Has been skipped
Pre-commit / pre-commit (push) Failing after 1s
CLI exit codes / changes (push) Has been skipped
Test (Install) / changes (push) Has been skipped
Test (Python) / changes (push) Has been skipped
Test (TypeScript) / changes (push) Has been skipped
CLI exit codes / cli-gate (push) Has been cancelled
Test (Install) / test-install-gate (push) Has been cancelled
Integ / integ-gate (push) Has been cancelled
Test (Python) / test-python-gate (push) Has been cancelled
Test (TypeScript) / test-typescript-gate (push) Has been cancelled
Test (Install) / python-minimal (3.12) (push) Has been cancelled
Test (Install) / python-minimal (3.11) (push) Has been cancelled
Test (Install) / python-extra (agno, mirage.agents.agno) (push) Has been cancelled
Test (Install) / python-extra (chroma, mirage.resource.chroma) (push) Has been cancelled
Test (Install) / python-extra (pdf, mirage.core.filetype.pdf) (push) Has been cancelled
Integ / integ (push) Has been cancelled
Integ / integ-database (push) Has been cancelled
Integ / integ-database-ts (push) Has been cancelled
Integ / integ-data (push) Has been cancelled
Integ / integ-ssh (push) Has been cancelled
Integ / integ-ssh-ts (push) Has been cancelled
Test (Python) / audit (push) Has been cancelled
Test (TypeScript) / test (push) Has been cancelled
Test (TypeScript) / python-fs-shim (push) Has been cancelled
CLI exit codes / Python CLI (push) Has been cancelled
CLI exit codes / TypeScript CLI (push) Has been cancelled
CLI exit codes / Cross-language snapshot interop (push) Has been cancelled
Test (Python) / test (push) Has been cancelled
Test (Python) / import-isolation (deepagents, openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Python) / import-isolation (deepagents, pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Integ / integ-ts (push) Has been cancelled
Integ / integ-fuse (push) Has been cancelled
Test (Install) / python-extra (databricks, mirage.resource.databricks_volume) (push) Has been cancelled
Test (Install) / python-extra (deepagents, mirage.agents.langchain) (push) Has been cancelled
Test (Install) / python-extra (email, mirage.resource.email) (push) Has been cancelled
Test (Install) / python-extra (fuse, mirage.fuse.mount) (push) Has been cancelled
Test (Install) / python-extra (hdf5, mirage.core.filetype.hdf5) (push) Has been cancelled
Test (Install) / python-extra (hf, mirage.resource.hf_buckets) (push) Has been cancelled
Test (Install) / python-extra (lancedb, mirage.resource.lancedb) (push) Has been cancelled
Test (Install) / python-extra (langfuse, mirage.resource.langfuse) (push) Has been cancelled
Test (Install) / python-extra (mongodb, mirage.resource.mongodb) (push) Has been cancelled
Test (Install) / python-extra (nextcloud, mirage.resource.nextcloud) (push) Has been cancelled
Test (Install) / python-extra (openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Install) / python-extra (openhands, mirage.agents.openhands, 3.12) (push) Has been cancelled
Test (Install) / python-extra (parquet, mirage.core.filetype.parquet) (push) Has been cancelled
Test (Install) / python-extra (postgres, mirage.resource.postgres) (push) Has been cancelled
Test (Install) / python-extra (pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Test (Install) / python-extra (qdrant, mirage.resource.qdrant) (push) Has been cancelled
Test (Install) / python-extra (redis, mirage.resource.redis) (push) Has been cancelled
Test (Install) / python-extra (s3, mirage.resource.s3) (push) Has been cancelled
Test (Install) / python-extra (ssh, mirage.resource.ssh) (push) Has been cancelled
Test (Install) / ts-minimal (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:44 +08:00

228 lines
6.6 KiB
Plaintext

---
title: Langfuse
description: Mount Langfuse traces, observations, prompts, datasets, and scores as a Mirage virtual filesystem.
icon: chart-line
---
The Langfuse resource exposes LLM observability data (traces, observations,
prompts, datasets, scores) as a virtual filesystem mounted at some prefix
such as `/langfuse/`.
For credential setup, see [Langfuse Setup](/python/setup/langfuse).
## Config
```python
import os
from mirage import MountMode, Workspace
from mirage.resource.langfuse import LangfuseConfig, LangfuseResource
config = LangfuseConfig(
public_key=os.environ["LANGFUSE_PUBLIC_KEY"],
secret_key=os.environ["LANGFUSE_SECRET_KEY"],
host=os.environ.get("LANGFUSE_HOST", "https://cloud.langfuse.com"),
)
resource = LangfuseResource(config=config)
ws = Workspace({"/langfuse": resource}, mode=MountMode.READ)
```
| Config field | Required | Default | Description |
| ---------------------- | -------- | ---------------------------- | ------------------------------------------------ |
| `public_key` | yes | | Langfuse project public key |
| `secret_key` | yes | | Langfuse project secret key |
| `host` | no | `https://cloud.langfuse.com` | Langfuse API host URL |
| `default_trace_limit` | no | 100 | Default trace/observation cap for listings |
| `default_search_limit` | no | 50 | Default result cap for search at directory scope |
## Filesystem Layout
```text
/langfuse/
traces/
<trace-id>.json
...
sessions/
<session-id>/
<trace-id>.json
...
prompts/
<prompt-name>/
<version>.json
...
datasets/
<dataset-name>/
items.jsonl
runs/
<run-name>.jsonl
...
```
Example:
```text
/langfuse/
traces/
abc123.json
def456.json
sessions/
chat-session-1/
abc123.json
ghi789.json
prompts/
summarize/
1.json
2.json
classify/
1.json
datasets/
eval-v1/
items.jsonl
runs/
run-2026-04-01.jsonl
```
### Traces
`/langfuse/traces/` lists recent traces (capped at `default_trace_limit`).
Each trace is a `.json` file containing the full trace object with nested
observations (spans, generations, events).
### Sessions
`/langfuse/sessions/` groups traces by session ID. Each session directory
contains trace `.json` files belonging to that session.
### Prompts
`/langfuse/prompts/` lists prompt names as directories. Each prompt directory
contains version files (`1.json`, `2.json`, etc.) with the prompt content
and metadata.
### Datasets
`/langfuse/datasets/` lists dataset names as directories. Each contains
`items.jsonl` (dataset items) and `runs/` with run results.
## Smart Commands
### grep at different scopes
```bash
# FILE level - downloads the file, greps locally
grep "error" "/langfuse/traces/abc123.json"
# TRACES level - uses Langfuse trace filter API (name, tags, metadata)
grep "error" "/langfuse/traces/"
# SESSIONS level - uses Langfuse session listing
grep "chat" "/langfuse/sessions/"
# PROMPTS level - filters prompt names
grep "classify" "/langfuse/prompts/"
# ROOT level - searches across all resource types
grep "error" "/langfuse/"
```
At directory scope, the resource uses Langfuse's filter API instead of
downloading data:
- **traces/**: filters by trace name, user ID, or tags
- **sessions/**: filters by session listing
- **prompts/**: filters by prompt name
### head / tail
`head` and `tail` on `traces/` use Langfuse API pagination with sort order
instead of downloading all traces:
```bash
# Returns 10 most recent traces
head -n 10 "/langfuse/traces/"
# Returns 10 oldest traces
tail -n 10 "/langfuse/traces/"
```
## Limits
| Command | Limit behavior |
| ------------------------ | ---------------------------------------------------- |
| `ls traces/` | Returns up to `default_trace_limit` traces |
| `cat traces/<id>.json` | Full trace (single doc, no limit needed) |
| `grep` (directory level) | Server-side filter, capped at `default_search_limit` |
| `wc -l traces/` | Not supported (Langfuse has no count endpoint) |
## Cache
The Langfuse resource uses `IndexCacheStore` (same as other resources).
Index entries store trace IDs, session IDs, and prompt names.
## Example
```python
import asyncio
import os
from dotenv import load_dotenv
from mirage import MountMode, Workspace
from mirage.resource.langfuse import LangfuseConfig, LangfuseResource
load_dotenv(".env.development")
config = LangfuseConfig(
public_key=os.environ["LANGFUSE_PUBLIC_KEY"],
secret_key=os.environ["LANGFUSE_SECRET_KEY"],
)
resource = LangfuseResource(config=config)
async def main():
ws = Workspace({"/langfuse": resource}, mode=MountMode.READ)
# List top-level resources
r = await ws.execute("ls /langfuse/")
print(await r.stdout_str())
# List recent traces
r = await ws.execute("ls /langfuse/traces/")
print(await r.stdout_str())
# Read a specific trace
traces = r.stdout_str().strip().splitlines()
if traces:
r = await ws.execute(f'cat "/langfuse/traces/{traces[0]}"')
print(r.stdout_str()[:500])
# List prompts
r = await ws.execute("ls /langfuse/prompts/")
print(await r.stdout_str())
# Search traces (uses Langfuse filter API)
r = await ws.execute('grep "error" "/langfuse/traces/"')
print(await r.stdout_str())
# List datasets
r = await ws.execute("ls /langfuse/datasets/")
print(await r.stdout_str())
if __name__ == "__main__":
asyncio.run(main())
```
## Shell Commands
| Command | Notes |
| --------------- | ------------------------------------------------------ |
| `ls` | List traces, sessions, prompts, datasets |
| `cat` | Read trace JSON, prompt version, dataset items |
| `head` / `tail` | Paginated trace listing with sort |
| `grep` / `rg` | Smart: uses Langfuse filter API at directory scope |
| `jq` | Query JSON trace/prompt data |
| `stat` | Metadata (trace count, prompt versions, dataset items) |
| `find` | Search across resources with `-name` |
| `tree` | Directory tree view |