PHP code example of nohnaimer / yii2-sentry
1. Go to this page and download the library: Download nohnaimer/yii2-sentry library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nohnaimer / yii2-sentry example snippets
return [
'components' => [
'sentry' => [
'class' => 'nohnaimer\sentry\Component',
'dsn' => 'http://2682ybvhbs347:[email protected] /1',
// Additional options for `Sentry\init`:
'clientOptions' => [
'release' => '[email protected] ',
//Performance Monitoring
'traces_sample_rate' => 1.0,
],
//collect JavaScript errors, default false
'jsNotifier' => true,
//Collect javascript errors to different project
'jsDsn' => 'http://[email protected] /2',
// Additional options for javascript `Sentry\init`:
'jsClientOptions' => [
'release' => '[email protected] ',
//Performance Monitoring
'integrations' => '[new Sentry.Integrations.BrowserTracing()]',
'tracesSampleRate' => 0.2,
],
// Write the context information (the default is true):
'context' => true,
//add Environment application
'environment' => 'test',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'nohnaimer\sentry\Target',
'levels' => ['error', 'warning'],
],
],
],
],
];
\Yii::error('message', 'category');
\Yii::warning([
'msg' => 'message',
'extra' => 'value',
], 'category');
'targets' => [
[
'class' => 'nohnaimer\sentry\Target',
'levels' => ['error', 'warning'],
'extraCallback' => function ($message, $extra) {
// some manipulation with data
$extra['some_data'] = \Yii::$app->someComponent->someMethod();
return $extra;
}
],
],
\Yii::warning([
'msg' => 'message',
'extra' => 'value',
'tags' => [
'extraTagKey' => 'extraTagValue',
]
], 'category');
return [
// ...
'on beforeAction' => function (\yii\base\ActionEvent $event) {
/** @var \yii\web\User $user */
$user = Yii::$app->has('user', true) ? Yii::$app->get('user', false) : null;
if ($user && ($identity = $user->getIdentity(false))) {
\Sentry\configureScope(function (\Sentry\State\Scope $scope) use ($identity) {
$scope->setUser([
// User ID and IP will be added by logger automatically
'username' => $identity->username,
'email' => $identity->email,
]);
});
}
return $event->isValid;
},
// ...
];