Skip to Content

Laravel Rust

Send traces, logs, and errors from a Laravel Rust app to Everr. Hand the setup to your agent, or wire it up yourself.

Sendstraceslogserrors

Laravel Rust exports OpenTelemetry traces on its own: requests, database queries, cache and Redis operations, outgoing HTTP, queued jobs, workflows, scheduled tasks, mail, and console commands. It keeps its log lines local and records failures only on spans, so on its own it fills Everr's traces but not its logs or Errors page.

The everr-laravel-rust crate adds the rest. It sends your log lines to the same endpoint, and turns every failure Laravel reports, whether a request, job, or command error or a panic, into an error that Everr groups by where it happened.

In development

The everr-laravel-rust crate and the Laravel Rust setup in the everr-setup-telemetry skill are still in development, in everr-labs/everr#736. Until they're released, cargo add everr-laravel-rust and the Agent setup below don't work yet. Laravel's own trace export works today: enable the opentelemetry feature and configure the endpoint.

Let your agent wire it up

/everr-setup-telemetry Instrument this Laravel Rust app and send traces, logs, and errors to Everr

The Agent enables Laravel's tracing, adds everr-laravel-rust, and verifies the data in your local collector.

Alternative: wire it up by hand

Enable the opentelemetry feature on laravel-rust in Cargo.toml. The starter app leaves it off. Keep your database feature:

Cargo.toml
laravel-rust = { version = "0.1", features = ["database-postgres", "opentelemetry"] }

Add the crate:

cargo add everr-laravel-rust

Export logs and errors from src/app.rs:

src/app.rs
Application::configure()
    .with_logging(everr_laravel_rust::logs)
    // ...

If you already have a with_logging callback, such as for Sentry, call everr_laravel_rust::logs(logging, config) inside it instead.

Run the app through the crate in src/main.rs. It sends buffered log lines when the process stops, and records panics that Laravel doesn't catch, such as one in a task started with tokio::spawn:

src/main.rs
fn main() -> ExitCode {
    everr_laravel_rust::run(app::configure())
}

Route templates in the browser

If your app also sends browser telemetry with @everr/otel-web, add the crate's route header to both middleware groups in src/app.rs:

src/app.rs
Application::configure().with_middleware(|middleware, _| {
    middleware.web(|web| {
        web.append(everr_laravel_rust::route_header);
    });
    middleware.api(|api| {
        api.append(everr_laravel_rust::route_header);
    });
})

Each response then carries an x-everr-route header with the route that handled it, such as /api/orders/{id}. The browser SDK names its span for the request after it, so fetch("/api/orders/42") shows up as GET /api/orders/{id}, the same name as the server's span. For requests from another origin, also list x-everr-route in Access-Control-Expose-Headers.

Pages need one more step, because your page routes live in Rust and the browser can't map /users/42 to /users/{user}. With Inertia, share the route as a prop in src/http/middleware/handle_inertia_requests.rs:

src/http/middleware/handle_inertia_requests.rs
everrRoute => request.current_route().map(|route| route.uri().to_owned()),

Then tell the SDK how to read it, in the module that sets up @everr/otel-web:

resources/js/telemetry.ts
import { setRouteResolver } from "@everr/otel-web";

type InertiaPage = { url: string; props?: { everrRoute?: unknown } };
const patterns = new Map<string, string>();

function remember(page: InertiaPage | null | undefined): void {
  const route = page?.props?.everrRoute;
  if (page && typeof route === "string") {
    patterns.set(new URL(page.url, window.location.origin).pathname, route);
  }
}

// The first page is in the HTML: a JSON script in Inertia 3, a `data-page` attribute before.
const initial = document.querySelector("[data-page]");
if (initial) {
  const json =
    initial instanceof HTMLScriptElement ? initial.textContent : initial.getAttribute("data-page");
  remember(JSON.parse(json ?? "null"));
}

// Learn every page Inertia visits, even one that sends no record while it's current.
document.addEventListener("inertia:navigate", (event) => {
  remember((event as CustomEvent<{ page: InertiaPage }>).detail.page);
});

setRouteResolver({
  page: (url) => {
    // A visit pushes the new page to history before the SDK records its page view.
    remember(window.history.state?.page);
    return patterns.get(new URL(url).pathname);
  },
});

Import it first in resources/js/app.tsx, so the resolver is set before the app's other imports run:

resources/js/app.tsx
import "./telemetry";

Page views, page leaves, errors, and web vitals then carry the page's route as everr.route.pattern. With Inertia's encryptHistory option on, page views after the first miss it, because the SDK records them before Inertia's navigate event, but each page's other records still carry it.

Configure the endpoint

Laravel reads OpenTelemetry settings from .env, and variables set in the process environment take precedence.

For local development, use the otlp: URL from everr local status:

.env
OTEL_EXPORTER_OTLP_ENDPOINT=<otlp-url-from-status>
OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=development

For production, use an API key with the Send telemetry capability (see Production telemetry) and keep it in your secret manager:

.env
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.everr.dev
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20<your-api-key>
OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=production
  • Use the base endpoint. Laravel adds /v1/traces, and the crate adds /v1/logs.
  • The service name defaults to APP_NAME. Set OTEL_SERVICE_NAME if APP_NAME isn't a stable name for the service.
  • LOG_LEVEL sets which log lines are sent, as it does for Laravel's local log channels. RUST_LOG takes precedence when it's set.

What is sent

  • Traces from Laravel, with the standard OpenTelemetry attributes. A job's spans join the trace of the request that dispatched it.
  • Your application's log lines, as written, with the trace of the request or job they ran in. Keep secrets and personal data out of them.
  • One error per failure, with its type, message, location, and causes. Panics are recorded as fatal, including panics outside a request or job, such as in a spawned task. When the failure comes from a framework error, such as a database or HTTP client error, Laravel's summary (for example database error 22P02) replaces the error's text, which can quote query values, URLs, or response bodies.
  • Laravel's own log lines, with only the fields Laravel itself exports with its traces. Lines that quote message content, such as mail recipients or subjects, stay local.
  • Warnings and errors from dependencies, such as a database pool timeout or a reset connection. Their lower-level lines stay local, and so do SQLx's statement lines at any level, since they can quote SQL literals or payloads.

Verify

Exercise a route that touches the database, a route that fails, and a queued job (laravel dev runs a worker). Stop the app, then check the errors it sent. Replace my-service with your service name:

everr local query "SELECT Timestamp, SeverityText, Body, LogAttributes.\`exception.type\` AS type FROM logs WHERE ServiceName = 'my-service' AND SeverityNumber >= 17 AND Timestamp >= now() - INTERVAL 15 MINUTE ORDER BY Timestamp DESC LIMIT 20"

To check traces and other log lines, see Instrument your app.