---
title: "Laravel for Rust"
description: "Learn how to report panics and send traces from your Laravel for Rust application to Sentry."
url: https://docs.sentry.io/platforms/rust/guides/laravel-rust/
---

# Sentry for Laravel for Rust

[Laravel for Rust](https://laravel.com/rust/docs) is a full-stack web framework for Rust, published as the `laravel-rust` crate. This guide sets up a Laravel for Rust application to send:

* Panics in request handlers to Sentry as issues, through the Sentry Rust SDK.
* Request traces to Sentry's [OTLP endpoint](https://docs.sentry.io/concepts/otlp.md), through Laravel for Rust's own OpenTelemetry export.

##### Provisional Setup

Sentry support for Laravel for Rust is in progress. Follow it in [getsentry/sentry-rust#1445](https://github.com/getsentry/sentry-rust/issues/1445). Until we have full support, use the setup on this page. Note the [Limitations](https://docs.sentry.io/platforms/rust/guides/laravel-rust.md#limitations).

## [Prerequisites](https://docs.sentry.io/platforms/rust/guides/laravel-rust.md#prerequisites)

* A Sentry [account](https://sentry.io/signup/) and [project](https://docs.sentry.io/product/projects.md)
* An application built with `laravel-rust`

## [Install](https://docs.sentry.io/platforms/rust/guides/laravel-rust.md#install)

Add the `sentry` crate to your Laravel for Rust app.

```bash
cargo add sentry
```

This setup was tested with `laravel-rust` 0.1.4 and `sentry` 0.49.6.

## [Configure](https://docs.sentry.io/platforms/rust/guides/laravel-rust.md#configure)

Set up the Sentry SDK in `src/app.rs` to report panics. Add the `with_services` and `booted` calls below to your existing configuration:

```rust
use laravel::Application;
use laravel::foundation::ApplicationBuilder;
use sentry::{ClientInitGuard, ClientOptions};

pub fn configure() -> ApplicationBuilder {
    Application::configure()
        // ...your existing configuration
        .with_services(|app| {
            app.singleton(|_| async {
                let options = ClientOptions::new()
                    .dsn("https://<key>@o<orgId>.ingest.sentry.io/<projectId>")
                    .maybe_release(sentry::release_name!());
                Ok(sentry::init(options))
            });
        })
        .booted(|app| async move { app.resolve::<ClientInitGuard>().await.map(drop) })
}
```

##### Set Up the SDK Exactly Like This

In most Rust applications, you call `sentry::init` at the start of `main`. Don't do that in Laravel for Rust: because of how it handles panics, Sentry can only capture panics in your request handlers when you set up the SDK as shown above.

## [Send Traces (Optional)](https://docs.sentry.io/platforms/rust/guides/laravel-rust.md#send-traces-optional)

Sending traces is optional, but recommended, because they show you how long each request takes. The Sentry SDK doesn't support capturing traces from Laravel for Rust well yet, so send them to Sentry's [OTLP endpoint](https://docs.sentry.io/concepts/otlp.md) instead. OTLP is the OpenTelemetry protocol, which Laravel for Rust can export traces with.

Start by enabling the `opentelemetry` feature of `laravel-rust`:

```bash
cargo add laravel-rust --features opentelemetry
```

Then set your project's OTLP traces endpoint and authentication header as environment variables, for example in your `.env` file:

```bash
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://o<orgId>.ingest.sentry.io/api/<projectId>/integration/otlp/v1/traces
OTEL_EXPORTER_OTLP_TRACES_HEADERS="x-sentry-auth=sentry sentry_key=<your-public-key>"
```

You can find the endpoint and key in [Project Settings > Client Keys (DSN)](https://sentry.io/orgredirect/organizations/:orgslug/settings/projects/:projectId/keys/). To send fewer traces, see [Laravel for Rust's sampling docs](https://laravel.com/rust/docs/tracing#sampling).

Each request then shows up in Sentry as a transaction named after its route, such as `GET /users/{id}`.

## [Verify](https://docs.sentry.io/platforms/rust/guides/laravel-rust.md#verify)

Add a route that panics:

```rust
use laravel::prelude::*;

pub fn routes(route: &mut Router) {
    // ...your existing routes
    route.get("/debug-sentry", async || -> &'static str {
        panic!("Everything is on fire!")
    });
}
```

Start your application and open `/debug-sentry` in your browser. Then, in [sentry.io](https://sentry.io):

* Go to **Issues** to find the panic, with a stack trace that points to your route.
* If you set up traces, go to **Explore > Traces** to find the `GET /debug-sentry` transaction.

## [Limitations](https://docs.sentry.io/platforms/rust/guides/laravel-rust.md#limitations)

This setup has the following limitations:

* Only panics are captured as errors. Failed requests still show up as failed spans when you use the OTLP export.
* Laravel for Rust's OpenTelemetry export marks a span as failed when your code logs at the `ERROR` level inside it, even if the response succeeded.
* Capturing logs from Laravel for Rust isn't well-supported.
* Panics aren't linked to the trace of the request that caused them.
* Traces started by a Sentry SDK in another service aren't continued.
* Spans don't have a release.
* Panics that happen before the application boots aren't captured.

## [Next Steps](https://docs.sentry.io/platforms/rust/guides/laravel-rust.md#next-steps)

These Rust SDK pages also apply to the panic setup on this page:

* [Options](https://docs.sentry.io/platforms/rust/configuration/options.md)
* [Filtering](https://docs.sentry.io/platforms/rust/configuration/filtering.md)
* [Releases](https://docs.sentry.io/platforms/rust/configuration/releases.md)
* [Data Management](https://docs.sentry.io/platforms/rust/data-management.md)

---

Find other pages: [Sitemap](https://docs.sentry.io/sitemap.md) lists every page with a one-line summary, and [llms.txt](https://docs.sentry.io/llms.txt) gives an overview with guidance for agents.
