This extension is the way to integrate Rollbar service with your Yii2 application.
The preferred way to install this extension is through composer.
To install, either run
$ php composer.phar require sorokinmedia/yii2-rollbar
or add
"sorokinmedia/yii2-rollbar": "dev-master"
to the require
section of your composer.json
file.
If you want to use it with Yii prior to 2.0.13, you need yii2-rollbar of the version 1.6.*
.
- Add the component configuration in your global
main.php
config file:
'bootstrap' => ['rollbar'],
'components' => [
'rollbar' => [
'class' => \sorokinmedia\rollbar\Rollbar::class,
'accessToken' => 'YOUR_ACCESS_TOKEN',
'environment' => 'local',
'root' => '@root',
// You can specify exceptions to be ignored by yii2-rollbar:
'ignoreExceptions' => [
['yii\web\HttpException', 'statusCode' => [400, 403, 404]],
['yii\web\ForbiddenHttpException', 'statusCode' => [403]],
['yii\web\UnauthorizedHttpException', 'statusCode' => [401,403]],
],
],
],
- Add the web error handler configuration in your web config file:
'components' => [
'errorAction' => 'site/error',
'class' => \sorokinmedia\rollbar\web\ErrorHandler::class,
// You can include additional data in a payload:
'payloadDataCallback' => function (\sorokinmedia\rollbar\web\ErrorHandler $errorHandler) {
return [
'exceptionCode' => $errorHandler->exception->getCode(),
'rawRequestBody' => Yii::$app->request->getRawBody(),
];
},
],
- Add the console error handler configuration in your console config file:
'components' => [
'errorHandler' => [
'class' => \sorokinmedia\rollbar\console\ErrorHandler::class,
],
],
You may want to collect your logs produced by Yii::error()
, Yii::info()
, etc. in Rollbar.
Put the following code in your config:
'log' => [
'targets' => [
[
'class' => \sorokinmedia\rollbar\log\Target::class,
'levels' => ['error', 'warning', 'info'], // Log levels you want to appear in Rollbar
// It is highly recommended that you specify certain categories.
// Otherwise, the exceptions and errors handled by the error handlers will be duplicated.
'categories' => ['application'],
],
],
],
The log target also appends category
and request_id
parameters to the log messages.
request_id
is useful if you want to have a yii2-debug-like grouping.