Use cases and traces
Tie every call to the use case that made it, so its cost and its speed show up where you look for them.
Every call can say which use case of your map it belongs to. Then «what does AI cost us?» becomes «what does each thing people do cost us?», and a slow answer shows up in the trace of the case a person was in.
Saying the case
await ai.chat({ task: 'allergen-answer', case: 'ask-about-a-product', messages });or the header Sypnia-Case: ask-about-a-product. The id is the one in your map, from cases/<area>/<id>.case.yaml (Cases).
When your server is traced with Telemetry’s SDK, the case of the current request is already known: @sypnia/ai reads it, and sends the trace along, so you can leave case out.
An id that is not on the map is accepted and marked case_unknown in usage. When the project is linked to Cases, it also appears there as a scope error, with the case to add.
The use case says it uses AI
id: ask-about-a-product
title: Ask about a product
actor: customer
goal: Know whether a product is safe for me before I order it
where: shop.product-detail
ai:
tasks: [allergen-answer]
failures:
- name: TooManyQuestions
when: the customer reached today's limit of questions
tell: «You asked a lot today. You can ask us at the counter, or again tomorrow.»The Cases check compares that with reality: a case that calls a task it does not list, or lists one it never calls, is reported.
In the trace
Each call is a step (a span) inside the trace of its case, next to the database queries and the page that started it:
| Span | What it carries |
|---|---|
chat allergen-answer | the route, the model that answered, tokens read and written, time to the first token, total time, credits, call_id |
attempt (one per fallback tried) | the model, why it failed |
The names follow OpenTelemetry’s conventions for AI calls, so any OpenTelemetry tool reads them. See Logs in Telemetry for every attribute.