Repository navigation
Langfuse: resolve providers, import cost-bearing types, carry tags, timing and attribution (0.8.0) - #39
Conversation
…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>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| if _VERTEX_ANTHROPIC.match(lowered): | ||
| return "vertex-ai", model |
There was a problem hiding this comment.
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>
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 intags), embeddings were never imported, and latency, user, release, version, metadata and prompt were not carried.What changes
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-4obecomesopenai/gpt-4o, with the original kept aslangfuse_model) and more families (o4-, Mistral, Llama, Cohere, Grok, Qwen, Kimi).reported_cost_usd, with per-bucketreported_cost_details.observation_type.build_base_paramsstill defaults to GENERATION, so library callers are unchanged until they opt in.langfuse.tag.<tag>: "true".tagsalso holdslangfuse.release,langfuse.version,langfuse.prompt.name/.versionandlangfuse.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.latency_ms,ttft_ms,user_id,trace_name,release,version,prompt_name,prompt_versionandmodel_parameters.Retry-Afteror with doubling waits capped at 120 s.syncrenews its lease after each wait.pull langfuse --exclude-content/--include-content. The default is unchanged: content is still included.--user-id,--session-idand--metadata KEY=VALUEon bothpullandsync.sync langfusehelp no longer claims content is uploaded with no opt-out.pull langfuserows now carry the import identitysyncrows already had (import_source,import_source_scope,import_event_id= the observation id, the same id asspan_id), so pushing an overlapping pull again stores nothing twice. The scope defaults to a digest of the host and public key;--source-scopesets it, for example to matchsync.CHANGELOG.md, README.Tests and evidence
tests/fixtures/langfuse_v2/, every observation type), not hand-written JSON.--exclude-contentbehave as expected.tests/e2e/langfuse_ingest.pyreads all 11 fixture rows back from/v1/callswith tag pairs, latency, TTFT, user and reported cost intact. No attribution field was omitted.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.Not published to PyPI.
🤖 Generated with Claude Code