Search by

klaxon / laravel

petrocenasek

Klaxon for Laravel: captures application errors and sends them to the Klaxon server through the application's queue.

v0.1.4 2026-12-02 13:09 UTC

This package is auto-updated.

Last update: 2026-12-02 13:09:13 UTC


README

A Laravel library that captures application errors and sends them through the application's queue to the Klaxon server – a central overview of errors from all your projects (a lightweight alternative to Sentry).

  • PHP 8.2+, Laravel 11, 12 and 13. No extra dependencies (only illuminate/* and Laravel's HTTP client).
  • Never slows down or breaks the application: a captured error is only kept in memory and, at the end of the request, pushed to the application's queue as a SendEvents job; the user's request never touches the network. When the queue cannot be used (database down, sync queue), the error waits in a fallback store in storage/klaxon. Whatever fails inside the library, the application keeps running; at most one line per process goes to error_log().
  • Repeats of the same error are merged: a loop throwing 10,000 identical exceptions ends up as one event with count: 10000.
  • Passwords, tokens, cookies and the Authorization header are never sent; from the request body only field names.

Protocol between the library and the server: docs/protocol.md in the server repository.

Installation

  1. composer require klaxon/laravel
    php artisan klaxon:install

    klaxon:install publishes config/klaxon.php, adds the variables to .env.example, checks that storage/klaxon is writable and, based on the application's queue, suggests what to set.

  2. In .env:

    KLAXON_URL=https://klaxon.example.com
    KLAXON_KEY=klx_…              # Klaxon → project → Keys
    # applications without a worker (queue:work) also set:
    KLAXON_QUEUE=klaxon           # dedicated queue – processed by the scheduler or by a poke
    KLAXON_POKE_SECRET=…          # poking: enter the same secret in Klaxon in the project settings, together with the URL
  3. php artisan klaxon:test – sends a test error right away (outside the queue) and prints the server's answer. The error shows up in the project overview.

Nothing else is needed: the library registers itself (package discovery) and captures everything Laravel logs from the warning level up – unhandled exceptions, report($e) and manual Log::warning()/Log::error(). No changes to bootstrap/app.php. The application's queue must not be sync (QUEUE_CONNECTION=database is enough).

Applications without package discovery (providers listed by hand in config/app.php, dont-discover, a custom base path) have to add Klaxon\Laravel\KlaxonServiceProvider::class to their providers – otherwise the library never boots: klaxon:* commands are missing and a poke gets 404.

How errors are sent

Repeats of the same error within a request are counted together; at the end of the request, command or job a Klaxon\Laravel\Queue\SendEvents job goes to the application's queue (batches of at most 25 events). It sends them over HTTPS (gzip, 5 s timeout). Who processes the job depends on what the application has:

Path How When
queue the application's queue:work – the job is sent as soon as it is its turn the application has a worker (default queue; with KLAXON_QUEUE the worker must listen to it too)
schedule the package registers klaxon:flush every minute: it processes the dedicated KLAXON_QUEUE and the fallback store cron without a worker – KLAXON_QUEUE=klaxon
poke the Klaxon server calls POST /_klaxon/flush with an HMAC signature every minute; the library processes the dedicated queue and the fallback store and returns its status neither worker nor cron – KLAXON_QUEUE=klaxon, KLAXON_POKE_SECRET and the URL https://app/_klaxon/flush in Klaxon

klaxon:flush and a poke only process the dedicated KLAXON_QUEUE, never the application's shared queue.

Poking is useful for an application with cron as well – as a check that it is alive (the server calls it instead of waiting for a heartbeat). When klaxon:flush ran from the scheduler within the last 3 minutes, a poke does not process the queue and only returns the status (flushed.status = skipped). Should cron stop running, the poke takes over sending by itself.

The job is sent by whichever process handles it, with that process's KLAXON_KEY. Several applications sharing one queue (one Redis and Horizon for an API and an admin panel) therefore belong to one Klaxon project with the same key – the applications are told apart by the request URL. To keep projects separate, give each application its own KLAXON_QUEUE and worker.

The job never throws (nothing in failed_jobs, nothing in the log): when the server does not answer, it is delayed by 1, 2, 4 … up to 60 minutes; with an invalid key by an hour. Events older than 7 days are dropped. The fallback store is capped at 1,000 files / 20 MB; dropped events are counted and the server shows them in the project detail. After a successful send (at most once every 5 minutes) a heartbeat goes to the server as well – library version, release, state of the queue and the fallback store, last sending error.

Configuration

Variable Default Meaning
KLAXON_ENABLED true main switch
KLAXON_URL – Klaxon server address
KLAXON_KEY – the project's server key; without a URL or a key the library does nothing at all
KLAXON_ENVIRONMENT APP_ENV environment (production, staging …)
KLAXON_RELEASE automatic application version; otherwise version from composer.json, otherwise the version of Composer's root package (a monorepo's shared composer.json), otherwise the short hash from .git/HEAD, otherwise the commit Composer installed from
KLAXON_LEVEL warning minimum log level that is sent
KLAXON_QUEUE_CONNECTION QUEUE_CONNECTION queue connection for SendEvents jobs
KLAXON_QUEUE default queue dedicated queue; set it without a worker (e.g. klaxon)
KLAXON_POKE_SECRET – enables the poke route
KLAXON_SEND_USER_PII false send the user's name and e-mail (otherwise only the ID)
KLAXON_SCHEDULE true register klaxon:flush in the scheduler
KLAXON_BREADCRUMBS_QUERIES false add SQL queries (without values) to the trail before an error
KLAXON_CAPTURE_IN_TESTS false capture during the application's tests too (APP_ENV=testing)

Everything else is in config/klaxon.php (after klaxon:install): ignored exception classes (ignore_exceptions), extra filtered keys (scrub_keys), headers to send, limits of the fallback store and of event sizes.

What is sent

  • message and exception chain (max 5) with stack traces – paths relative to the application root, vendor/ frames marked, ±5 lines of code for the 10 topmost application frames;
  • HTTP: method, URL (sensitive parameters filtered), route, Referer, selected headers, body field names;
  • Livewire/Filament: for /livewire/update the component name and the called method – otherwise every error would look like "POST /livewire/update"; the Referer shows the real page;
  • console: command and arguments (values of options like --password filtered); queue: job class, queue, attempt;
  • user: ID only (name and e-mail only with KLAXON_SEND_USER_PII=true);
  • context of the log call (Log::error('…', ['order_id' => 42]));
  • trail before the error (breadcrumbs): the last 30 log records below the sending threshold, optionally SQL queries;
  • environment, release and runtime (PHP, Laravel, hostname, SAPI).

Values under the keys password, password_confirmation, token, _token, secret, api_key, authorization, cookie, set-cookie, x-csrf-token, x-xsrf-token, session (and those from scrub_keys) are replaced with [Filtered], regardless of case and depth. Cookies and values from .env are never sent.

Custom grouping

The server groups errors by exception type and code locations (without line numbers), log messages by the normalized message. A custom fingerprint can be forced:

Log::error("Order {$id} sync timed out", ['klaxon_fingerprint' => 'orders-sync-timeout']);

Commands

Command What it does
klaxon:install publishes the configuration, adds to .env.example, checks that storage/klaxon is writable
klaxon:test creates a test exception and sends it synchronously; prints the server's answer
klaxon:flush processes the dedicated Klaxon queue and the fallback store, sends a heartbeat (run by the scheduler; --timeout=30)
klaxon:status configuration (without the key), pending and dropped events, last success and error, pause, modes

Development

composer install
vendor/bin/phpunit

Tests run on Orchestra Testbench; compatibility is also checked on Laravel 11 and 12 (testbench 9 and 10).

Trying it out in an application next to it without a release: in the application's composer.json "repositories": [{ "type": "path", "url": "../Klaxon/library/laravel" }] and composer require klaxon/laravel:@dev.

Branches: work happens on develop; main holds released code and is the default branch Packagist reads. A release merges develop into main and tags vX.Y.Z on main (the Klaxon::VERSION constant must match the tag); Packagist picks it up by itself through the GitHub webhook.

License

MIT, see LICENSE. The fingerprint test vectors in tests/Fixtures/fingerprint-vectors.json are a copy from the server (docs/) and must stay identical to it.