Skip to content

Langfuse: resolve providers, import cost-bearing types, carry tags, timing and attribution (0.8.0) - #39

Merged
sam-bretz merged 6 commits into
mainfrom
langfuse-normalizer
Nov 23, 2026
Merged

sam-bretz merged 6 commits into
mainfrom
langfuse-normalizer

Conversation

@sam-bretz

@sam-bretz sam-bretz commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Langfuse import: priced and attributed rows, tags that land, 0.8.0.

Why

Measured against a live Langfuse project, relay rows recorded 62% of Langfuse's cost (Bedrock, gateway-style and unrecognized model names came through as provider unknown), every Langfuse tag was dropped at ingest (they were sent as one list, and metergraph keeps only string values in tags), embeddings were never imported, and latency, user, release, version, metadata and prompt were not carried.

What changes

  • Provider resolution. Uses metadata hints (provider, ls_provider, gen_ai.system, gen_ai.provider.name), then the model's shape: Bedrock ids and ARNs, Vertex paths, Anthropic-on-Vertex versions, gateway prefixes (openai/gpt-4o becomes openai / gpt-4o, with the original kept as langfuse_model) and more families (o4-, Mistral, Llama, Cohere, Grok, Qwen, Kimi).
  • Langfuse's cost stays on every row as reported_cost_usd, with per-bucket reported_cost_details.
  • More observation types. Imports every GENERATION, and any EMBEDDING, AGENT, TOOL, CHAIN, RETRIEVER, EVALUATOR or GUARDRAIL observation with a model and usage or cost, keeping observation_type. build_base_params still defaults to GENERATION, so library callers are unchanged until they opt in.
  • Tags. Each Langfuse tag becomes langfuse.tag.<tag>: "true". tags also holds langfuse.release, langfuse.version, langfuse.prompt.name/.version and langfuse.metadata.<key>, with SDK-written keys left out. That is at most 32 pairs, Langfuse tags first, using the key names metergraph's SDK uses.
  • New row fields. latency_ms, ttft_ms, user_id, trace_name, release, version, prompt_name, prompt_version and model_parameters.
  • Retries. HTTP 429/502/503/504 are retried up to six times, after Retry-After or with doubling waits capped at 120 s. sync renews its lease after each wait.
  • CLI.
    • pull langfuse --exclude-content / --include-content. The default is unchanged: content is still included.
    • --user-id, --session-id and --metadata KEY=VALUE on both pull and sync.
    • The sync langfuse help no longer claims content is uploaded with no opt-out.
  • Re-pulls deduplicate. pull langfuse rows now carry the import identity sync rows already had (import_source, import_source_scope, import_event_id = the observation id, the same id as span_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.
  • Version 0.8.0, CHANGELOG.md, README.

Tests and evidence

  • 918 unit tests pass. New tests run against a scrubbed fixture of real Langfuse Cloud responses (tests/fixtures/langfuse_v2/, every observation type), not hand-written JSON.
  • Live Langfuse. Every selector and --exclude-content behave as expected.
  • Round trip through metergraph's hosted ingest (local stack): tests/e2e/langfuse_ingest.py reads all 11 fixture rows back from /v1/calls with tag pairs, latency, TTFT, user and reported cost intact. No attribution field was omitted.
  • Re-sync dedup on the same stack. The e2e now pushes the same pull twice: 2 batches and 22 rows accepted, 11 calls stored, no duplicate request ids on read-back.
  • Live pull pushed to the same stack. 26 rows: 22 priced, 0 with provider unknown, all carrying Langfuse's cost. Metergraph's effective cost is 85.4% of Langfuse's (62% before). The remaining unpriced rows are a Bedrock id and an OpenAI embedding that the server catalog does not price yet; their Langfuse cost is on the row for the server to fall back to.
  • Cross-model review (Codex): one finding. Fractional usage (for example audio seconds) was not counted when deciding to import a non-generation observation. Fixed, with a test.

Not published to PyPI.

🤖 Generated with Claude Code

sam-bretz and others added 5 commits November 22, 2026 18:39
…iming and attribution

- Resolve the provider from metadata hints and model shape (Bedrock ids and
  ARNs, Vertex paths, gateway prefixes, more model families); strip a gateway
  prefix and keep the original as langfuse_model.
- Import every GENERATION and any other generation-like observation with a
  model and usage or cost, keeping observation_type on the row.
- Emit one string pair per Langfuse tag and the customer's metadata in tags,
  which metergraph keeps; previously every tag was dropped at ingest.
- Carry latency_ms, ttft_ms, user_id, trace_name, release, version,
  prompt_name/version, model_parameters and reported_cost_details.
- Retry 429 and gateway errors after Retry-After.
- pull langfuse: --exclude-content/--include-content, and --user-id,
  --session-id and --metadata selectors on pull and sync; correct the sync
  help text about content.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… prompt and metadata

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…bservation

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sam-bretz
sam-bretz marked this pull request as ready for review November 23, 2026 02:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T18:11:23.211016Z 79babdf New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e11759f310

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +522 to +523
if _VERTEX_ANTHROPIC.match(lowered):
return "vertex-ai", model

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve Claude cache accounting when resolving Vertex models

For a Claude-on-Vertex model such as claude-3-5-sonnet-v2@20241022 without explicit provider metadata, this changes the inferred provider from anthropic to vertex-ai, but normalize_observation still passes only that provider to map_usage_details. Since vertex-ai is not in CACHE_EXCLUSIVE_INPUT_PROVIDERS, usage such as {"input":100,"input_cache_read":900,"output":10} now produces input_tokens=1000 instead of 100, while retaining cache_read_tokens=900. This double-counts cached tokens in downstream pricing. Keep the Vertex provider attribution, but make usage normalization model-aware, as the existing reports_input_without_cache(provider, model) helper already supports.

Useful? React with 👍 / 👎.

pull langfuse rows now carry import_source, import_source_scope and
import_event_id (the observation id, the same id as span_id), as sync
rows already did. The server stores each identity once, so pushing an
overlapping pull again no longer stores every observation twice. The
scope defaults to a digest of the host and public key; --source-scope
sets it, for example to match a sync of the same project.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sam-bretz
sam-bretz merged commit 8e29b9e into main Nov 23, 2026
9 checks passed
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.

1 participant