PHP

PHP SDK

For plain PHP applications (not using Laravel), use the Sentry PHP SDK directly.

Installation

composer require sentry/sentry

Setup

Initialize Sentry once, at application bootstrap:

\Sentry\init([
    'dsn' => 'https://your-key@your-hostname.tindra.sh/1',
    'environment' => 'production',
    'release' => '1.4.2',
    'traces_sample_rate' => 0.1,
]);

Capturing exceptions

Automatic

Install the error and exception handlers to capture unhandled errors automatically:

\Sentry\init([
    'dsn' => '...',
    'attach_stacktrace' => true,
]);

The SDK registers set_error_handler and set_exception_handler on init.

Manual

try {
    processOrder($order);
} catch (\Throwable $e) {
    \Sentry\captureException($e);
    throw $e;
}

Capture a message

\Sentry\captureMessage('Suspicious login attempt', \Sentry\Severity::warning());

User context

\Sentry\configureScope(function (\Sentry\State\Scope $scope) use ($user) {
    $scope->setUser([
        'id' => $user->id,
        'email' => $user->email,
        'ip_address' => $_SERVER['REMOTE_ADDR'],
    ]);
});

Extra context

\Sentry\configureScope(function (\Sentry\State\Scope $scope) use ($orderId) {
    $scope->setExtra('order_id', $orderId);
    $scope->setTag('checkout_flow', 'express');
});

Performance monitoring

$transaction = \Sentry\startTransaction(new \Sentry\Tracing\TransactionContext());
$transaction->setName('checkout.process');
$transaction->setOp('function');

// ... your work

$transaction->finish();

Testing

\Sentry\captureException(new \RuntimeException('Hello Tindra'));

Check your dashboard. The event should appear within a few seconds.