Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Changelog

## 0.8.0

Langfuse import (`pull langfuse` and `sync langfuse`):

- **Every cost-bearing observation.** Besides `GENERATION`, any `EMBEDDING`,
`AGENT`, `TOOL`, `CHAIN`, `RETRIEVER`, `EVALUATOR` or `GUARDRAIL`
observation that names a model and carries usage or a cost is imported.
Each row carries `observation_type`.
- **Provider resolution.** Resolved from the observation's metadata
(`provider`, `ls_provider`, `gen_ai.system`, `gen_ai.provider.name`) or the
model name: Bedrock model ids and ARNs, Vertex resource paths and
Anthropic-on-Vertex versions, gateway prefixes and more model families
(`o4-`, Mistral, Llama, Cohere, Grok, Qwen, Kimi). A stripped gateway prefix
keeps the original model as `langfuse_model`.
- **Langfuse's cost** is kept on every row as `reported_cost_usd`, with the
per-bucket `reported_cost_details`.
- **Tags land.** Each Langfuse tag is one `tags` pair,
`langfuse.tag.<tag>: "true"`. They used to be sent as one list, which
metergraph drops because it keeps only string values. `tags` also carries
`langfuse.release`, `langfuse.version`, `langfuse.prompt.name`,
`langfuse.prompt.version` and the metadata as `langfuse.metadata.<key>`
(scalar values as strings, without SDK-written keys), at most 32 pairs with
Langfuse tags first.
- **Timing and attribution.** Rows carry `latency_ms`, `ttft_ms`, `user_id`,
`trace_name`, `release`, `version`, `prompt_name`, `prompt_version` and
`model_parameters` when Langfuse has them.
- **Rate limits.** HTTP 429, 502, 503 and 504 are retried up to six times,
after `Retry-After` when present, else with doubling waits capped at two
minutes. `sync` renews its lease after each wait.
- **Selectors.** `--user-id`, `--session-id` and repeatable
`--metadata KEY=VALUE` on `pull` and `sync`.
- **Content.** `pull langfuse --exclude-content` leaves input and output in
Langfuse (`--include-content`, the default, says so explicitly). The
`sync langfuse` help no longer claims content is uploaded with no opt-out.
- **Re-pulls deduplicate.** `pull langfuse` rows now carry the same import
identity as `sync` rows (`import_source`, `import_source_scope`,
`import_event_id` = the observation id), so pushing an overlapping pull
again stores nothing twice. The scope defaults to a digest of the host and
public key; `--source-scope` sets it, for example to match `sync`.

For library callers: `build_base_params` still requests `GENERATION` alone
unless given `observation_types`; pass `COST_BEARING_TYPES` and keep rows with
`is_importable_observation` to import the other types.
86 changes: 63 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ buckets; add a provider there, not in an adapter.

## Pull from Langfuse

Import Langfuse **GENERATION** observations (the LLM call records
Langfuse captures) into the same metergraph-native JSONL shape as
`pull openai`. Only `GENERATION` observations are imported — Langfuse
`SPAN`/`EVENT` observations and Scores/evals are never imported.
Requires Langfuse Cloud or **self-hosted v4+** (the version serving the
v2 Observations API); older self-hosted deployments are not supported.
Import the Langfuse observations that record an LLM call into the same
metergraph-native JSONL shape as `pull openai`: every `GENERATION`, and
any `EMBEDDING`, `AGENT`, `TOOL`, `CHAIN`, `RETRIEVER`, `EVALUATOR` or
`GUARDRAIL` observation that names a model and carries usage or a cost
(each row keeps its `observation_type`). Structural spans with no model,
`SPAN`/`EVENT` observations and scores are not imported. Requires
Langfuse Cloud or **self-hosted v4+** (the version serving the v2
Observations API); older self-hosted deployments are not supported.

**Setup:** add your Langfuse keys to `.env`:

Expand All @@ -176,37 +178,75 @@ set `LANGFUSE_BASE_URL` in `.env` (or pass `--base-url` per-command):
metergraphrelay pull langfuse -n 25 --output traces.jsonl
metergraphrelay push traces.jsonl

With no other flags, this imports the latest 100 `GENERATION`
observations overall (not 100 distinct traces).
With no other flags, this imports the latest 100 observations overall
(not 100 distinct traces).

**Narrowing what gets pulled**, beyond `-n`/`--count`:

metergraphrelay pull langfuse --since 2026-08-01T00:00:00Z --until 2026-08-07T00:00:00Z
metergraphrelay pull langfuse --trace-name support-bot-reply --trace-name billing-bot-reply --tag prod --tag tier-1
metergraphrelay pull langfuse --user-id user-42 --session-id chat-7 --metadata feature=support-triage

- `--trace-name` matches Langfuse's trace name — the closest Langfuse
- `--trace-name` matches Langfuse's trace name, the closest Langfuse
concept to a workflow or use case (e.g. `"support-bot-reply"`). It's
repeatable; multiple `--trace-name` values are **OR'd** together (any
match).
- `--tag` matches Langfuse trace tags — commonly used as customer-defined
- `--tag` matches Langfuse trace tags, commonly used as customer-defined
categories (a tenant, an experiment cohort, a priority tier); this is
a convention, not something Langfuse enforces. It's repeatable;
multiple `--tag` values require **all** of them to be present (AND).
`--tag` only matches tags that already exist on your historical
data — it can't require a tag that was never set, and if you don't
data: it can't require a tag that was never set, and if you don't
pass `--tag` at all, there's no tag-based narrowing (not "untagged
only").
- `--trace-name`, `--tag`, `--environment`, and `--since`/`--until` all
combine with each other using AND.
- `--count` is always a cap on the number of **GENERATION observations**
imported, never a count of distinct traces.

**Before running this against your own data:** `pull langfuse`
transfers every matched generation's prompt/response content from
Langfuse into your local JSONL file, and from there into metergraph via
`push`, with no separate opt-in step — unlike `pull openai`'s
`--include-content` flag, there is no way to pull Langfuse generations
without their content.
- `--user-id` and `--session-id` match Langfuse's user and session ids
exactly; `--metadata KEY=VALUE` matches one metadata key exactly and is
repeatable (AND).
- Every selector, `--environment` and `--since`/`--until` combine with
each other using AND.
- `--count` is always a cap on the number of **observations** imported,
never a count of distinct traces.

**What each row carries.** The provider is resolved from the
observation's metadata (`provider`, LangChain's `ls_provider`, OTel
`gen_ai.system`) or from the model name: Bedrock ids and ARNs
(`us.anthropic.claude-...`), Vertex resource paths, gateway prefixes
(`openai/gpt-4o` becomes provider `openai`, model `gpt-4o`, with the
original kept as `langfuse_model`) and model families (`gpt-`, `o4-`,
`claude-`, `gemini-`, `mistral-`, `llama-`...). Langfuse's own cost is
always kept as `reported_cost_usd` (with `reported_cost_details`), so a
model metergraph's catalog cannot price still has Langfuse's figure.
Each Langfuse tag lands in `tags` as its own pair,
`langfuse.tag.<tag>: "true"`, followed by `langfuse.release`,
`langfuse.version`, `langfuse.prompt.name`, `langfuse.prompt.version` and
the observation's metadata as `langfuse.metadata.<key>` (scalar values as
strings; SDK-written keys such as `resourceAttributes.*` are left out), at
most 32 pairs with Langfuse tags kept first. These are the key names
metergraph's SDK uses for Langfuse spans, so a call lands the same way on
either path. Rows also carry `latency_ms`, `ttft_ms`, `user_id`,
`session_id`, `trace_name`, `release`, `version`, `prompt_name`,
`prompt_version` and `model_parameters` when Langfuse has them.

**Rate limits.** HTTP 429 and gateway errors (502, 503, 504) are retried
up to six times, after Langfuse's `Retry-After` when it sends one, else
after 2, 4, 8... seconds, never more than two minutes at a time.

**Content.** By default `pull langfuse` copies every matched
observation's input and output from Langfuse into your local JSONL file,
and from there into metergraph via `push`. Pass `--exclude-content` to
leave it in Langfuse: the rows then carry usage, cost, timing and
attribution only, marked `content_opted_in: false`. (`--include-content`
states the default explicitly.) `sync langfuse` is the other way round:
content is uploaded only with `--include-content`.

**Re-pulling is safe.** Every row carries an import identity: the
Langfuse observation id plus a scope for the project. metergraph stores
each identity once, so pushing an overlapping pull again does not double
count. By default the scope is derived from the host and public key (a
digest, never the key itself), the same on every pull of a project. If
you also run `sync langfuse` for the project, give `pull` the same
`--source-scope` so the two never store an observation twice. A later
edit of an observation in Langfuse is not re-imported by a re-pull.

Full flag reference: `metergraphrelay pull langfuse --help`.

Expand Down Expand Up @@ -577,7 +617,7 @@ same cron line is safe from several machines.
metergraphrelay sync phoenix --source-scope my-project --initial-since 2026-08-01T00:00:00+00:00 --project my-project

Each takes the selectors of its `pull` counterpart (`--trace-name`/`--tag`/
`--environment`, `--project`, `--name`) plus `--route`, but **no
`--environment`/`--user-id`/`--session-id`/`--metadata`, `--project`, `--name`) plus `--route`, but **no
`--since`/`--until`/`--count`**: the server chooses the window and every
row in it must land before the checkpoint advances.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "metergraphrelay"
version = "0.7.9"
version = "0.8.0"
description = "Move LLM trace data between systems: pull from providers, push to metergraph."
readme = "README.md"
requires-python = ">=3.10"
Expand Down
2 changes: 1 addition & 1 deletion src/metergraphrelay/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.9"
__version__ = "0.8.0"
Loading