Skip to content

Commit 14e7579

Browse files
author
Peter
committed
iss30676 | Sentry: Модуль отправки логов back-end ошибок в Sentry
1 parent 76021f5 commit 14e7579

File tree

6 files changed

+134
-0
lines changed

6 files changed

+134
-0
lines changed

composer.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "webpractik/sentry",
3+
"description": "Module sending logs to sentry",
4+
"keywords": ["bitrix", "sentry", "log"],
5+
"type": "bitrix-d7-module",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Петр Кленкин (mnlght)",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"require": {
14+
"composer/installers": ">=1.0.22 <2.0",
15+
"sentry/sdk": "2.0.2"
16+
}
17+
}

include.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

install/index.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
defined('B_PROLOG_INCLUDED') and (B_PROLOG_INCLUDED === true) or die();
4+
5+
use Bitrix\Main\Config\Configuration;
6+
use Bitrix\Main\ModuleManager;
7+
8+
/**
9+
* Class webpractik_sentry
10+
*/
11+
Class webpractik_sentry extends \CModule
12+
{
13+
14+
private static $arParametersForFullInstall = [
15+
'debug' => false,
16+
'handled_errors_types' => 4437,
17+
'exception_errors_types' => 4437,
18+
'ignore_silence' => false,
19+
'assertion_throws_exception' => true,
20+
'assertion_error_type' => 256,
21+
'log' =>
22+
array (
23+
'settings' =>
24+
array (
25+
'file' => 'local/php_interface/error.log',
26+
'log_size' => 1000000,
27+
),
28+
'class_name' => '\\Webpractik\\Sentry\\ExceptionMailer',
29+
'extension' => '',
30+
'required_file' => '/modules/webpractik.sentry/lib/exceptionmailer.php',
31+
),
32+
];
33+
34+
private static $arParametersForPartialInstall = [
35+
'class_name' => '\\Webpractik\\Sentry\\ExceptionMailer',
36+
'extension' => '',
37+
'required_file' => '/modules/webpractik.sentry/lib/exceptionmailer.php',
38+
];
39+
/**
40+
* webpractik_sentry constructor.
41+
*/
42+
public function __construct()
43+
{
44+
$arModuleVersion = [];
45+
include __DIR__ . '/version.php';
46+
47+
$this->MODULE_NAME = 'Webpractik';
48+
$this->MODULE_DESCRIPTION = 'Модуль для отправки логов в sentry';
49+
$this->MODULE_ID = 'webpractik.sentry';
50+
$this->MODULE_VERSION = $arModuleVersion['VERSION'];
51+
$this->MODULE_VERSION_DATE = $arModuleVersion['VERSION_DATE'];
52+
$this->MODULE_GROUP_RIGHTS = 'N';
53+
$this->PARTNER_NAME = 'Webpractik';
54+
$this->PARTNER_URI = 'https://webpractik.ru';
55+
}
56+
57+
public function DoInstall()
58+
{
59+
ModuleManager::registerModule($this->MODULE_ID);
60+
$this->addPointToSettings();
61+
}
62+
63+
public function DoUninstall()
64+
{
65+
ModuleManager::unRegisterModule($this->MODULE_ID);
66+
}
67+
68+
public function addPointToSettings()
69+
{
70+
$configuration = Configuration::getInstance();
71+
72+
if(empty($configuration['exception_handling']) || (int)$configuration['exception_handling']['handled_errors_types'] !== 4437) {
73+
$configuration->add('exception_handling', self::$arParametersForFullInstall);
74+
$configuration->saveConfiguration();
75+
76+
} else {
77+
$fconf = $configuration['exception_handling'];
78+
$log = array_merge($configuration['exception_handling']['log'], self::$arParametersForPartialInstall);
79+
$fconf['log'] = $log;
80+
$configuration->add('exception_handling', $fconf);
81+
$configuration->saveConfiguration();
82+
}
83+
}
84+
}

install/version.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
$arModuleVersion = [
3+
'VERSION' => '1.0.0',
4+
'VERSION_DATE' => '2018-07-09 10:00:00'
5+
];

lang/ru/lib/exceptionmailer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?
2+
$MESS['KEY'] = 'test';
3+
$MESS['NUMBER'] = 'test';

lib/exceptionmailer.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Webpractik\Sentry;
4+
5+
use Bitrix\Main\Diag\ExceptionHandlerFormatter;
6+
use Bitrix\Main\Diag\ExceptionHandlerLog;
7+
use Bitrix\Main\Localization\Loc;
8+
9+
IncludeModuleLangFile(__FILE__);
10+
11+
class ExceptionMailer extends ExceptionHandlerLog
12+
{
13+
private $URL;
14+
15+
public function initialize(array $options){
16+
\Sentry\init(['dsn' => 'https://'.Loc::getMessage('KEY').'@sentry.w6p.ru/'.Loc::getMessage('NUMBER') ]);
17+
18+
}
19+
20+
public function write($exception, $logType)
21+
{
22+
\Sentry\init(['dsn' => 'https://'.Loc::getMessage('KEY').'@sentry.w6p.ru/'.Loc::getMessage('NUMBER') ]);
23+
}
24+
}

0 commit comments

Comments
 (0)