You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(otel): emit cost + full usage on spans (gen_ai.usage.cost, total_tokens, cache/reasoning details, duration) #721
otelMiddleware emits only two usage attributes — gen_ai.usage.input_tokens and gen_ai.usage.output_tokens (from usage.promptTokens / usage.completionTokens). The TokenUsage it receives already carries more that never reaches the span.
Because cost is absent from the span, backends (e.g. PostHog $ai_generation) must re-derive cost from tokens × their own price table. Provider-reported actual cost — cache discounts, gateway markup (OpenRouter), etc. — is therefore lost, and duration-billed activities have no cost signal at all.
Proposal
When present on usage, emit (all optional/guarded so spans stay clean when a provider doesn't report them):
This is independently useful for chat today. It also matters most for the cross-activity case in #720: media activities have no tokens to derive cost from, so without an explicit gen_ai.usage.cost a backend gets nothing.
Activity
season179 commentedon Jun 11, 2026
I'll take this on since it is related to previous work I did
feat(ai): emit full usage on otel spans (cost, totals, cache/reasonin…
feat(ai): emit cost + full usage on otel spans (TanStack#747)