# Use cases and places

> How Sypnia measures each use case of your app in production, and checks with real clicks that people move through your app the way its navigation map says.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://telemetry.docs.sypnia.com/concepts/use-cases-and-places/

For agents: Use cases: a server span carries sypnia.case (the case id, e.g. place-order) and sypnia.case.outcome (the outcome or failure name it ended in, e.g. OrderPlaced, OutOfStock; an on_all window that closes before every event arrives shows as WindowExpired, counted under outcomes); set by Sypnorm's telemetry hook, by Sypnia Run for the cases it runs, or by hand with setSpanAttributes() of @sypnia/telemetry 0.4.0 (/node, /next/server) or the OpenTelemetry API. The trace takes the case of its first span that carries one. Per case: runs, outcomes by name, error share (threw, 5xx, or ended in no declared outcome — a declared failure like OutOfStock is not an error), p50/p95 duration, recent problems. Places: the browser SDK (0.4.0) adds `place` (the nearest data-sypnia-place attribute, innermost wins, e.g. shop.checkout) to page_view, click, rage_click and dead_click events; Sypnia Design pieces and @sypnia/ui set it from the case's `where`. Moves = click in place A followed by a page_view in place B. With a Cases map linked: outcomes seen vs declared (an undeclared outcome is a gap), cases never seen in 30 days, case ids not on the map, moves not on the navigation tree, places never reached in 30 days, routes with no place. API: GET /v1/cases, GET /v1/places, GET /v1/traces?case=. Place ids are names from your code, never content.

This page is for anyone who builds with use cases: a map of what people can do in your app, kept in [Sypnia Cases](https://cases.docs.sypnia.com/) or written as code with Sypnorm. It works with the open-source engine and with Sypnia Cloud. Without a map, nothing here changes how the rest of Sypnia works.

> **In plain words**
>
> A use case is one thing a person can do in your app, such as «Place an order». Sypnia counts how often each one happens, how it ends and how long it takes. It also watches where people actually click, and tells you when that differs from the map of your app you agreed on.

## A use case in a trace

When a request or a job serves a use case, its span carries two attributes:

| Attribute             | What it holds                                                   | Example                     |
| --------------------- | --------------------------------------------------------------- | --------------------------- |
| `sypnia.case`         | The case id, as it is on the map                                | `place-order`               |
| `sypnia.case.outcome` | How the case ended: the name of one of its outcomes or failures | `OrderPlaced`, `OutOfStock` |

You rarely set them yourself:

- **Sypnorm** sets both on every use case it runs: each run is a span `usecase <case id>` carrying `sypnia.case`, and the outcome (`error` when the run threw) is set on that same span, with `setSpanAttributes()` of `@sypnia/telemetry` 0.4.0 or later, or with the OpenTelemetry API when one is registered. With an older `@sypnia/telemetry`, whose `span()` takes its attributes when it starts, the ending is recorded as a second, short span `usecase <case id> → <Outcome>` with both attributes.
- **Sypnia Run** sets both on the cases it runs: routes, scheduled jobs and listeners ([how Run runs use cases](https://run.docs.sypnia.com/cases/how-cases-run)).
- **Any other code** sets them on the span that serves the case, with `setSpanAttributes()` of `@sypnia/telemetry` (from version 0.4.0; in Next.js from `@sypnia/telemetry/next/server`). It finds the request's span for you, and the outcome can be set after the work ended ([Node SDK](https://telemetry.docs.sypnia.com/sdks/node#activespan-and-setspanattributesvalues)):

`checkout.ts`

```ts
import { setSpanAttributes } from '@sypnia/telemetry/node';

setSpanAttributes({ 'sypnia.case': 'place-order' });
// … the work of the case …
setSpanAttributes({ 'sypnia.case.outcome': 'OrderPlaced' });
```

With OpenTelemetry, the same with its API:

`checkout.ts`

```ts
import { trace } from '@opentelemetry/api';

const span = trace.getActiveSpan();
span?.setAttribute('sypnia.case', 'place-order');
// … the work of the case …
span?.setAttribute('sypnia.case.outcome', 'OrderPlaced');
```

A trace belongs to the case of its first span that carries one. Calls made inside that work, to Sypnia AI, Files, Mail or your own services, are spans of the same trace, so the case shows everything it did. Both attributes are in the [semantic conventions](https://telemetry.docs.sypnia.com/reference/semantic-conventions#sypnia.case).

## What each case shows

| Figure       | What it counts                                                                                              |
| ------------ | ----------------------------------------------------------------------------------------------------------- |
| **Runs**     | How many times the case ran in the range, and the trend                                                     |
| **Outcomes** | How many runs ended in each outcome and each failure, by name                                               |
| **Errors**   | Runs that threw, answered `500` or above, or ended without any outcome the case declares                    |
| **Duration** | p50 and p95 of the span that carries the case                                                               |
| **Problems** | The [problems](https://telemetry.docs.sypnia.com/concepts/problems) whose failures happened inside the case |

A declared failure is not an error. When the bread is sold out, `OutOfStock` is the case doing its job: it is counted under outcomes, with the message people saw. An error is something the case did not plan for. So a problem reads «3 people could not finish Place an order: the card form never loaded», and the case's page shows it next to the 41 runs that ended in `OrderPlaced`.

A case that starts only when several events have arrived (`on_all` in Cases) has a window to wait for them. When the window closes before they all arrive, the case does not run, and its page shows the wait as `WindowExpired`, with the events that did arrive. It is counted under outcomes, not as an error.

## Places: where people are

Inside an app, every use case has a place: a screen, a tab, a dialog or a menu, on the app's navigation map. In Cases this is the case's `where`, and each place has one parent, so the way to get there is always known: «Shop › Checkout».

The browser SDK reads places from your pages. The element that shows a place carries its id:

```html
<main data-sypnia-place="shop.checkout">
  …
  <dialog open data-sypnia-place="shop.checkout.change-address">…</dialog>
</main>
```

Every [`page_view`](https://telemetry.docs.sypnia.com/reference/event-schema#page_view) and [`click`](https://telemetry.docs.sypnia.com/reference/event-schema#click), rage and dead clicks included, then carries `place` (from version 0.4.0 of the browser SDK): the id of the innermost place around it. A dialog open over the checkout is its own place. Pieces generated by [Sypnia Design](https://design.docs.sypnia.com/) and the components of `@sypnia/ui` set the attribute for you from the case's `where`. A place id is a name from your code: it is never the page's content, and masking does not change it.

## The navigation check

From those events Sypnia knows how people move: a click in one place, then the next place they see. With the project linked to a Cases map, it compares those moves with the navigation tree:

| What Sypnia finds                 | What it means                                  | What to do                                          |
| --------------------------------- | ---------------------------------------------- | --------------------------------------------------- |
| A move along the tree             | People get there the way the map says          | Nothing                                             |
| A move the tree does not have     | A shortcut or a link nobody put on the map     | Add it to the map as a shortcut, or remove the link |
| A place nobody reached in 30 days | A screen people cannot find, or no longer need | Check the way to it, or remove it from the map      |
| A route with no place             | A screen that is not on the map                | Give it a place, or find out why it exists          |

It does the same for use cases:

| What Sypnia finds                           | What it means                                                                                                            |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| An outcome the case does not declare        | A **gap in the map**: something happens that no one agreed on. Cases proposes a change to the case, with what people saw |
| A case on the map that never ran in 30 days | It is not built, not reachable, or not used                                                                              |
| A case id that is not on the map            | Code that does something no case describes                                                                               |

The comparison happens where the map lives: Sypnia Cases reads these figures from Sypnia and shows them on each case and each place ([Cases and Telemetry](https://cases.docs.sypnia.com/links/telemetry)). A self-hosted Cases engine reads them from your own engine with an API token.

## Reading the figures

- **In the app**, each use case and each place has its page, linked from the traces and problems that belong to it.
- **The API** gives the same figures: [`GET /v1/cases`](https://telemetry.docs.sypnia.com/api/traces#list-use-cases), [`GET /v1/places`](https://telemetry.docs.sypnia.com/api/traces#list-places), and the `case` filter on [`GET /v1/traces`](https://telemetry.docs.sypnia.com/api/traces#list-traces).

## How Sypnia uses it

Sypnia measures its own products this way. Every product of the suite has its map of cases, and their spans and places arrive in Sypnia Telemetry, the pilot: [Telemetry, the pilot](https://telemetry.docs.sypnia.com/start/the-pilot).
