Skip to Content
Rius

How do I alert on cost per trace for one step?

In Rius, you alert on cost per trace for one step by creating a custom alert with a Step filter and a rule on the Cost metric, such as avg(Cost) above a USD value. The Step filter limits the alert to spans with that exact name, and Cost aggregates per trace over a rolling window. Rules in one alert are combined with AND, and you can add more of them.

How it works

A custom alert has three parts: optional filters, one or more rules, and one shared rolling window. See Custom alerts for the full builder. For this question, two parts matter.

  • The Step filter. Filters select which spans feed the rules, before any aggregation. Step matches the span name exactly. Each filter matches a span’s own value, so every span with that name feeds the rule. Only the matched spans count. Cost lives on LLM spans, so the step must be the model-call span itself. A parent span such as a function you wrapped with observe, or a tool span, carries no cost, and its children do not count toward it. To watch the cost of a whole agent or service, filter by Agent or Service instead.
  • The Cost metric. Cost is a numeric metric in USD. It offers avg, min, max, p50, p95 and p99. Numeric aggregations use per-trace semantics, so avg(Cost) is the average cost per trace in the window, not the workspace total.

A few metrics are measured per LLM call instead of per trace: Time to first token, Context usage and LLM calls. Their aggregations run over calls. An LLM call is an inference call, the kind of span the trace view badges as LLM. Agent, tool, retrieval and embedding spans never count as LLM calls, even when they carry a model. Cost is not in that group, so a cost rule reads per trace.

Cost is a list-price estimate in US dollars. A span whose model has no known price carries no cost, so it adds nothing to the reading. A cost alert is only as complete as your pricing coverage.

Set it up

  1. Create a custom alert in the builder. This is the only step that touches shared setup. You need traces already flowing, so the Step values are suggested from your live data.
  2. Add a filter on Step. Pick = for one step, or in to cover several step names. Use the span name exactly as it appears in your traces. Spans from the 1.0.0 SDKs that you did not name yourself are named after their operation and target, such as execute_tool search_orders.
  3. Add a rule on Cost. Choose avg for the typical trace, or p95 or p99 to catch the most expensive traces. Set the comparison operator and a USD value.
  4. Set the window. It can be anywhere from 5 minutes to 24 hours, and all rules in the alert share it.
  5. Attach a channel and choose a Renotify policy, off or every N minutes. Read the plain-language preview in the builder to confirm it describes the condition you want.

The rule then reads like this:

FILTERS Step = summarize-step (the name of an LLM span) RULES avg(Cost) > $0.50 WINDOW 15 minutes

To require something else at the same time, add another rule to the same alert, for example count(Errors) above a number. Both rules must hold in the window for the alert to fire. For either-or behavior, create a second alert, since there is no OR.

What you get

  • An alert that fires when the average, or a high percentile, of per-trace cost for one step crosses your threshold in the window.
  • A details page with the generated description, the editable rule, attached channels and firings. Each firing records the observed value of every rule against its threshold, so you can see which condition tripped.
  • A coverage ratio on firings for Cost, so you can tell a real reading from one based on partly priced spans. A rule held under its threshold by low coverage stays quiet, so check which models are priced on the Usage and cost page before relying on the alert.
  • Limits that leave room: up to 10 filters with 50 values each, and up to 10 rules per alert. Read Alerts for how firings, renotify and channels work together.

When something else fits

  • If you want one rule for several steps, use the in operator on the Step filter. If you want a separate threshold per step, create one alert per step.
  • Cost offers avg, min, max and percentiles, not a total. For total spend over a period, use the Usage and cost summary on Home instead of an alert.
  • For cost that is not tied to one step, leave out the Step filter, or scope by Service, Agent or Model instead.

Still stuck? Get help

Last updated on