Skip to content

Dashboards: equations lose the unit of their fields ($, duration) #124678

Description

@sergical

What happens

On a spans dashboard, a plain aggregate of a currency field shows as money. An equation on the same field shows as a plain number.

Widget query Shows
sum(gen_ai.cost.total_tokens) $13.82
equation|sum(gen_ai.cost.total_tokens) / count_unique(gen_ai.conversation.id) 0.152

The events API returns meta.fields = "number" for every equation|... column, so the widget cannot know that the result is money.

"Cost per run" and "cost per pull request" are the numbers people want most from AI agent traces, and both are equations.

Expected

An equation keeps the unit of its field when the other side has no unit:

  • currency ÷ or × a count, count_unique, or a constant → currency
  • duration ÷ or × a count or a constant → duration
  • currency ± currency → currency; duration ± duration → duration

Other mixes (for example currency ÷ currency) stay a plain number.

Where it happens

  • Backend: get_unit_and_type() in src/sentry/api/bases/organization_events.py handles only rate units inside equations (added in fix(api): Fix rate units not populating for equation fields #108043). All other equations return "number".
  • Frontend: getFieldRendererBase() in static/app/utils/discover/fieldRenderers.tsx uses a typed renderer for an equation only when the equation text matches a special field exactly.

Steps to reproduce

  1. Send spans with gen_ai.usage.input_tokens, so that Sentry adds gen_ai.cost.total_tokens.
  2. Make a big number widget with sum(gen_ai.cost.total_tokens). It shows $.
  3. Make a big number widget with equation|sum(gen_ai.cost.total_tokens) / count_unique(gen_ai.conversation.id). It shows no $.

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions