# Adding custom context


Every report already tells you a lot: the stack trace, the environment, the version of your crate, the host, and during a request the method, URL, route and headers. The full list is on [reporting errors](/docs/rust/errors/reporting-errors#what-a-report-contains).

What Flare can't know is what matters in your app: the tenant, the order that was being processed, the feature flag that was on. That's what custom context is for. It shows up under custom context on the report in Flare.

## Adding context to every report

Use `configure_scope` and `set_context`:

```rust
use serde_json::json;

flareapp::configure_scope(|scope| {
    scope.set_context("tenant", json!({ "id": 12, "plan": "pro" }));
});
```

The value can be anything that converts into a `serde_json::Value`: a string, a number, a bool, or a whole object built with `json!`. Setting the same key again replaces the old value, and `remove_context` takes it off again:

```rust
flareapp::configure_scope(|scope| {
    scope.remove_context("tenant");
});
```

Where the context ends up depends on where you call `configure_scope`. Called at startup, it lands on every report your app sends. Called inside a request, with the axum or Actix Web middleware in place, it only lands on the reports of that request, so the tenant of one customer never shows up on the error of another. [Scopes](/docs/rust/data-collection/scopes) explains how that works, and how to get the same for jobs and background tasks.

## Adding context to one report

When the context only makes sense for a single error, pass it along with the report itself:

```rust
use serde_json::json;

flareapp::report_error_with(&error, |report| {
    report.set_context("payment", json!({ "provider": "mollie", "order_id": 7 }));
});
```

This works with `flareapp::anyhow::report_with` as well. When a key is set both on the scope and on the report, the report wins.

## Adding context right before sending

To add or change context on every report in one place, including panics you never see coming, use the [`before_send` hook](/docs/rust/errors/client-hooks):

```rust
fn flare_config() -> flareapp::Config {
    flareapp::config!().before_send(|report| {
        report.set_context("region", "eu-west-1");

        true
    })
}

#[flareapp::main(config = flare_config)]
fn main() {}
```

The same hook can blank out context you'd rather not send, by setting its key to `Value::Null`. See [removing sensitive data](/docs/rust/errors/client-hooks#removing-sensitive-data).

## Context, users and glows

Context is one of the things a scope holds. The others have their own page:

- [Identifying users](/docs/rust/data-collection/identifying-users): who ran into the error.
- [Adding glows](/docs/rust/data-collection/adding-glows): what your app did right before the error.
