# Sending Logs: Rust

`tailcove` is a Rust crate that sends your `tracing` events to Tailcove. It's a `tracing` layer that batches lines and
sends them from its own thread, so it needs no async runtime and works the same in Axum, Actix, a CLI or a worker. In a
[Laravel Rust](https://laravel.com/rust/docs) app it's one service provider and one line in `.env`.

Logging never blocks on the network and never panics. If Tailcove can't be reached, the batch is reported to
`on_error` and dropped; your app carries on.

## Install

```bash
cargo add tailcove
```

For a Laravel Rust app, turn on the `laravel` feature:

```bash
cargo add tailcove --features laravel
```

The crate needs Rust 1.88 or newer (Laravel Rust itself needs 1.99).

## Laravel Rust

Create a source in Tailcove and copy its ingest token, then add it to `.env`:

```dotenv
TAILCOVE_TOKEN=your-source-ingest-token
```

Register the provider in `src/app.rs`:

```rust
.with_providers(|providers| {
    providers.add(tailcove::TailcoveServiceProvider);
})
```

That's it. Everything your app logs with `tracing::info!`, `warn!` and `error!` goes to Tailcove as well as your usual
log channels. Each line carries the request, command or job it came from, the values you added with
`laravel::context::add`, and the event's own fields. A reported error arrives with its type, location and causes.

Without `TAILCOVE_TOKEN` the provider adds nothing, so local development and tests stay quiet.

Errors are sent right away. To also send the last few other lines when the app stops, flush at the end of
`src/main.rs`:

```rust
fn main() -> std::process::ExitCode {
    let code = app::configure().run();
    tailcove::flush(std::time::Duration::from_secs(2));
    code
}
```

### Settings

All optional except the token:

- `TAILCOVE_TOKEN`: your source's ingest token.
- `TAILCOVE_LEVEL`: lines below this level aren't sent. Default `info`, so the framework's own `debug` lines (every
  query, every cache hit) stay local. One of `debug`, `info`, `notice`, `warning`, `error`, `critical`.
- `TAILCOVE_ENABLED`: `false` turns sending off.
- `TAILCOVE_MASK_SECRETS`: `false` sends passwords and tokens as they are. Default `true`.
- `TAILCOVE_SECRET_KEYS`: extra field names to mask, separated by commas (`customer_ssn,tax_id`).
- `TAILCOVE_ENDPOINT`: only if you self-host. Default `https://ingest.tailcove.dev/api/v1/logs`.
- `TAILCOVE_BATCH_SIZE` and `TAILCOVE_BATCH_MS`: send after this many lines or this many milliseconds. Default 50
  and 2000.

Laravel Rust checks these when the app boots, so a typo like `TAILCOVE_MASK_SECRETS=flase` stops the app with a clear
message instead of quietly changing what's sent. To change a setting in code, use `with_config`:

```rust
.with_config(|config, _| {
    config.section_mut::<tailcove::TailcoveConfig>().secret_keys.push("customer_ssn".into());
})
```

## Any other Rust app

Add the layer to your `tracing` subscriber:

```rust
use std::time::Duration;
use tracing_subscriber::prelude::*;

fn main() {
    let tailcove = tailcove::Tailcove::new(tailcove::Options::new(std::env::var("TAILCOVE_TOKEN").unwrap_or_default()));

    tracing_subscriber::registry()
        .with(tracing_subscriber::fmt::layer())
        .with(tailcove.layer())
        .init();

    tracing::info!(user_id = 42, "Signed in");
    tracing::error!(order_id = 99, reason = "card_declined", "Payment failed");

    tailcove.flush(Duration::from_secs(2));
}
```

Lines also go out when the last clone of the client is dropped.

### Options

- `endpoint`: the ingest URL, for self-hosting.
- `level`: lines below it aren't sent. Default `Level::Debug`.
- `flush_level`: lines at or above it are sent right away. Default `Level::Error`.
- `batch_size`, `batch_interval`, `timeout`: default 50 lines, 2 seconds, 2 seconds.
- `context`: values added to every line, like `.context("release", "1.4.2")`.
- `host`: defaults to the machine's hostname.
- `mask_secrets`, `secret_keys`: see below.
- `before_send`: sees each line after masking. Return it, changed or not, or `None` to drop it.
- `on_error`: called when a batch can't be sent. Otherwise failures are silent.
- `enabled`: `false` keeps the client from sending anything.

You can also log without `tracing`: `tailcove.log(Level::Info, "Deployed", context)`.

## Secret masking

Passwords, tokens, API keys and cookies are masked before a line leaves your process. `token=abc` becomes
`token=[redacted]`, a field named `password` or `api_key` becomes `[redacted]`, and anything that looks like a JWT, an
AWS key, a Stripe, GitHub, Slack or Google key, or a private key block becomes `[key]`. These are the same rules the
Tailcove server uses, so a line reads the same whichever side masked it.

## What gets sent

Each line is one JSON object, batched as NDJSON:

```json
{"message":"Payment failed","level":"error","host":"web-1","ts":"2026-12-02T10:00:00.123Z",
 "context":{"order_id":99,"reason":"card_declined","target":"app::billing",
            "request":{"method":"POST","path":"/checkout"}}}
```

`tracing`'s `TRACE` and `DEBUG` are both sent as `debug`, and `WARN` as `warning`.

In a Laravel Rust app, an error the framework reports arrives with its type, location and causes, and Tailcove groups
it into an [issue](https://tailcove.dev/docs/issues). A plain `tracing::error!` line is an ordinary log line: you can search it and
[alert](https://tailcove.dev/docs/alerts) on it, but it doesn't open an issue.

The crate is open source: [tailcove/rust on GitHub](https://github.com/tailcove/rust) and
[crates.io](https://crates.io/crates/tailcove).
