Search by

crabphp / sentry

bangnokia

Error reporting for the Crab framework: errors the application logs, sent to Sentry or a Sentry-compatible tracker (Crab Trap, Harbor), with no SDK

Package info

github.com/crabphp/sentry

pkg:composer/crabphp/sentry

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-11-22 19:00 UTC

This package is not auto-updated.

Last update: 2026-11-22 19:17:47 UTC


README

Error reporting for the Crab framework: the errors your application logs, sent to Sentry or a Sentry-compatible tracker such as Crab Trap or Harbor. No SDK: one HTTP request per error, over the framework's own client.

  • Nothing changes in your log. Every record is still written where it was; errors (and above) are reported as well.
  • Never in the way. Inside a worker (a request, a queue job, a scheduled task) the report is sent in its own task, so nothing waits on the tracker. A tracker that is down or slow is dropped silently, never your failure.
  • No secrets. A context key that names a secret (password, token, key, secret, auth, cookie, credential) is neither sent nor filled into the message; stack frames carry no arguments.
  • Wired everywhere, off until set. Without a DSN nothing is reported.

Install

composer require crabphp/sentry
// app.php
->withPlugins([\Crab\Sentry\SentryPlugin::class])
// config/sentry.php
return [
    'dsn' => env('SENTRY_DSN'),          // https://{key}@{host}/{project}; empty reports nothing
    // 'environment' => 'production',    // default: development with app.debug on, else production
    // 'server_name' => 'app.example.com', // default: the host of app.url
    // 'release' => '1.4.0',
    // 'threshold' => 'error',           // the lowest level reported
    // 'timeout' => 3,                   // seconds a send may take
];

Then wrap your logger so its errors are reported, in your application's setup:

use Crab\Contracts\Log\Logger;
use Crab\Contracts\Sentry\Reporter;
use Crab\Sentry\ReportingLogger;
use Crab\Sentry\SentryPlugin;

$container->singleton(Logger::class, fn($container) => new ReportingLogger(
    new \Crab\Log\Logger($app->path(config('log.path')), config('log.level'), $container->get(\Crab\Contracts\Clock\Clock::class)),
    $container->get(Reporter::class),
    SentryPlugin::threshold($container),
));
$container->singleton(\Psr\Log\LoggerInterface::class, Logger::class);

The framework's container cannot wrap a binding a plugin did not make, and a package may not build the framework's logger, so this one step is yours (see docs/framework-feedback.md).

Report by hand

public function __construct(private \Crab\Contracts\Sentry\Reporter $reporter) {}

$this->reporter->report('error', 'Payment {id} failed', ['id' => $id, 'exception' => $error]);

context['exception'] is sent with its chain and stack; context['method'] and context['path'] become the request; other scalar values go as extra data.

Testing

Set 'reporter' => 'array' in your tests' configuration, then assert on what would have been sent:

$reports = $app->container->get(\Crab\Sentry\ArrayReporter::class)->reports();

Send to Crab Trap or Harbor

Create a project there and use its DSN. Events go to /api/{project}/store/ with X-Sentry-Auth, as Sentry's own SDKs send them.