# Introduction


Tracing shows you where the time goes in your app: which requests are slow, which queries they run, and which calls to other services keep them waiting. If your app doesn't send traces yet, follow the [quick start](/docs/rust/getting-started/quick-start#send-logs-and-traces) first. This page explains how the Flare SDK turns your `tracing` spans into traces, and what you'll see in Flare.

You don't need a new API for any of this. You keep using the `tracing` crate the way you already do: `#[instrument]`, `info_span!`, and the spans your libraries create. The Flare layer turns those spans into spans in Flare. On top of that, the axum and Actix Web middleware add a span for every request, the reqwest middleware adds one for every outgoing call, and every SQLx query becomes a span too.

## Turning tracing on

Tracing is off until you set a sample rate, with the `FLARE_TRACES_SAMPLE_RATE` environment variable or in code:

```rust
#[flareapp::main(traces_sample_rate = 0.1)]
fn main() {}
```

The rate is the share of traces Flare sends, from `0.0` to `1.0`. Flare decides once per trace, at its first span, so you always get a trace as a whole or not at all. When a request comes in with a `traceparent` header, the service that sent it already made that decision, and Flare follows it.

Start with `1.0` while you set things up, so every request shows up. Once real traffic comes in, lower it: every span counts against your quota, and a busy app produces a lot of them.

## Which spans are sent

Flare sends spans at INFO or above. `#[instrument]` and `info_span!` create INFO spans, so your own spans make it into your traces. Libraries tend to create theirs at DEBUG, like the `request` span of `tower-http`, so those stay out of your traces and out of your span quota. You don't need a filter on your subscriber for that.

If you do want the DEBUG spans, set the level on the layer:

```rust
flareapp::tracing::layer()
    .send_logs(tracing::Level::INFO)
    .spans(tracing::Level::DEBUG);
```

A span below the level is left out, but what happens inside it isn't. Its child spans, log rows, error reports and SQLx queries move up to the closest parent span that is sent. A child span with no such parent starts a trace of its own.

## What you see in Flare

A Rust project has these lists under Performance:

- **Routes**: incoming HTTP requests, grouped on the method and the route, like `GET /users/{id}`. The axum and Actix Web middleware send these. When a request has no route, Flare groups it on the path, with ids and numbers replaced by `*`, so `/orders/42` becomes `/orders/*`.
- **Queries**: SQL queries, grouped on the query text, the database system and the database name. SQLx queries show up here with no extra code. See [database queries](/docs/rust/tracing/instrumenting-your-code#database-queries).
- **Database commands**: Redis commands, grouped on the command and the key pattern, like `GET user:*:profile`.
- **Jobs**: messages your app takes from a queue, grouped on the queue name. See [queue consumers](/docs/rust/tracing/instrumenting-your-code#queue-consumers).
- **Commands**: runs of the subcommands of a command line tool, grouped on the name of the span. A span becomes a command with `flare.span_type = "command"`. See [commands](/docs/rust/data-collection/entry-points#commands).
- **External HTTP**: requests your app sends to other services, grouped on the method, the host and the path. See [outgoing HTTP calls](/docs/rust/tracing/instrumenting-your-code#outgoing-http-calls).
- **Operations**: every other unit of work, like a background task, a scheduled job or a run of a command line tool. Flare groups them on the span name and the module of the function. See [background work](/docs/rust/tracing/instrumenting-your-code#background-work).

There are no Views or Livewire lists for Rust. A run of a command line tool without command spans shows up under Operations.

## How Flare decides what a span is

Flare looks at the fields of each span, and the first rule that matches decides its type:

| Order | When the span has | It becomes | Listed under |
|-------|-------------------|------------|--------------|
| 1 | a `db.system.name`, `db.query.text` or `db.statement` field, like the span of a SQLx query | a query | Queries, or Database commands for Redis |
| 2 | `otel.kind = "server"` and an `http.request.method` field, like the span of the axum or Actix Web middleware | a request | Routes |
| 3 | `otel.kind = "client"` and an `http.request.method` field, like the span of the reqwest middleware | an outgoing HTTP call | External HTTP |
| 4 | `otel.kind = "producer"` | a message sent to a queue | not listed |
| 5 | `otel.kind = "consumer"` | a job | Jobs |
| 6 | no parent | an operation | Operations |
| 7 | a parent | a function | not listed |

A span without a parent is the first span of a trace in your app. That's also true for a span whose parent lives in another service and came in through a `traceparent` header.

Rule 6 makes sure every unit of work ends up in a list, even when you didn't tell Flare what it is. Rule 7 covers all the spans that `#[instrument]` creates inside a request, a job or an operation.

A `flare.span_type` field skips these rules, and Flare uses the type you set. With `flare.span_type = "command"`, a span is a command, listed under Commands and grouped on its name. See [commands](/docs/rust/data-collection/entry-points#commands).

The fields `otel.name`, `otel.kind`, `otel.status_code` and `otel.status_description` work just like they do in `tracing-opentelemetry`. They set the name, kind and status of the span, and aren't stored as attributes. Every other field becomes an attribute. The [aggregations](/docs/protocol/traces/aggregations) page of the protocol docs lists exactly which attributes each list groups on.

## What a trace shows

Open a trace to see every span of a request, a job or an operation in one waterfall.

Spans from `#[instrument]` show up as functions, labeled with their module path and name, like `db::find_post`. Click one to see its source file and line, its module and target, and the arguments `#[instrument]` recorded.

Flare tells your own code apart from your dependencies by the file path. Relative paths such as `src/db.rs` are your code. Files from crates.io, from Cargo git dependencies and from the Rust standard library are library code. For your own functions, the label leaves out the name of your crate. A function from a dependency keeps its full module path, like `axum_login::service::call`.

### Events inside a span

What happens inside a span shows up as rows in the trace:

- A `tracing` event at INFO or above, like `info!`, `warn!` or `error!`, shows as a log row with its level and fields. See [logs inside a trace](/docs/rust/logs/introduction#logs-inside-a-trace).
- An error report shows as an exception row, with the exception class, the message and whether your code handled it. That covers panics, `report_error`, `report_message`, `anyhow` reports and the server errors of the Actix Web middleware. The error itself shows up under Errors as usual.

### Failed requests, jobs and operations

Flare counts a request, a job or an operation as failed when its own span has the error status. A span gets that status when:

- An `error!` event happens inside it.
- A panic happens inside it.
- It's the span of the axum or Actix Web middleware, and the response has a `5xx` status.
- It's a span of the reqwest middleware, and the response has a `4xx` or `5xx` status, or the call fails.
- You set `otel.status_code = "error"` yourself.

An error in a child span, like a failed query, doesn't mark the whole request as failed. And a status you set yourself with `otel.status_code` is never changed by the SDK.

## How traces are sent

Flare keeps the finished spans of a trace in memory until the first span of that trace closes. Then it sends the whole trace at once, from a background thread. In practice, a request shows up in Flare once its response is sent, and a job once it's done.

There's one catch: the first span of a trace only closes when every span below it has closed. A task you `tokio::spawn` from a request, with the request span as its parent, keeps that span open when it runs longer than the request does. Flare then only sends the trace when the task is done. Give such a task a trace of its own, as described in [spawned tasks](/docs/rust/tracing/instrumenting-your-code#spawned-tasks).

Flare sends at most one batch of traces every 5 seconds per process. Every request counts against the per-minute trace limit of your plan, so with many replicas, lower your sample rate.

## Statistics

For every row in a list, Flare shows how often it ran, how long it took and how often it failed, plus the response status codes for requests and outgoing HTTP calls.

A few statistics are only available for apps that use the Flare PHP and Laravel clients for now: the number of queries or HTTP calls per request, the links between rows (like the queries a route runs), and boot time. You can still open any trace to see every span of a request.

## Limits and quota

Every span you send counts against the span quota of your plan. That includes function spans, SQLx queries and the INFO spans that your libraries create. A request with a handful of functions and queries easily adds up to ten spans.

A trace keeps at most 1024 spans, and Flare drops the spans after that. A span keeps at most 128 attributes and 128 events. Flare drops the rest, and counts how many it dropped.

To send fewer spans:

- Use `#[instrument(level = "debug")]` on functions you only want to see locally. Flare skips DEBUG spans, unless you [change the level](#which-spans-are-sent).
- Leave out small functions that run often and take little time.
- Lower `FLARE_TRACES_SAMPLE_RATE`.

## Read more

- [Instrumenting your code](/docs/rust/tracing/instrumenting-your-code): functions, background work, queue consumers, queries and outgoing HTTP calls.
- [Traces payload](/docs/protocol/traces/payload) and [aggregations](/docs/protocol/traces/aggregations) in the protocol docs.
- [Working with traces](/docs/flare/performance/working-with-traces) in Flare.
