{ "html": "
\n

Installation

\n

There are various ways to install the PHP integration for Sentry. The\nrecommended way is to use Composer:

\n
$ composer require "sentry/sentry"\n
\n
\n

Alternatively you can manually install it:

\n
    \n
  1. Download and extract the latest sentry-php archive\nto your PHP project.

    \n
  2. \n
  3. Require the autoloader in your application:

    \n
    require_once '/path/to/Raven/library/Raven/Autoloader.php';\nRaven_Autoloader::register();\n
    \n
    \n
  4. \n
\n
\n\n\n
\n

Monolog

\n
\n

Capturing Errors

\n

Monolog supports Sentry out of the box, so you’ll just need to configure a handler:

\n
$client = new Raven_Client('___DSN___');\n\n$handler = new Monolog\\Handler\\RavenHandler($client);\n$handler->setFormatter(new Monolog\\Formatter\\LineFormatter("%message% %context% %extra%\\n"));\n\n$monolog->pushHandler($handler);\n
\n
\n
\n
\n

Adding Context

\n

Capturing context can be done via a monolog processor:

\n
$monolog->pushProcessor(function ($record) {\n    // record the current user\n    $user = Acme::getCurrentUser();\n    $record['context']['user'] = array(\n        'name' => $user->getName(),\n        'username' => $user->getUsername(),\n        'email' => $user->getEmail(),\n    );\n\n    // Add various tags\n    $record['context']['tags'] = array('key' => 'value');\n\n    // Add various generic context\n    $record['extra']['key'] = 'value';\n\n    return $record;\n});\n
\n
\n
\n
\n

Breadcrumbs

\n

Sentry provides a breadcrumb handler to automatically send logs along as crumbs:

\n
$client = new Raven_Client('___DSN___');\n\n$handler = new \\Raven_Breadcrumbs_MonologHandler($client);\n$monolog->pushHandler($handler);\n
\n
\n
\n
\n", "link": "https://docs.getsentry.com/clients/php/integrations/monolog/", "id": "php-monolog", "name": "Monolog" }