linkage-crm / critical-alerting-bundle
Send critical exceptions in prod to telegram channel
Installs: 36
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.2
- symfony/framework-bundle: *
- symfony/http-client: *
README
Symfony-bundle для отправки сообщений в ТГ о выбрасываемых исключениях в prod окружении.
Установка:
- Установка выполняется через пакетный менеджер composer
composer require linkage-crm/critical-alerting-bundle
- Добавить в config/bundles.php строку с этим бандлом:
<?php return [ // Others bundles LinkageCrm\CriticalAlertingBundle\CriticalAlertingBundle::class => ['prod' => true], ];
Необходимые переменные в env-файлах
APP_ENV=prod
CRITICAL_ALERTING_PROJECT_NAME=<your_project_name>
CRITICAL_ALERTING_TG_BOT_TOKEN=<your_bot_token>
CRITICAL_ALERTING_TG_CHAT_ID=<your_chat_id>
Примеры:
- Через наследование исключения TelegramNotifiableException:
use LinkageCrm\CriticalAlertingBundle\Exception\Notifiable\TelegramNotifiableException; class MyCustomException extends TelegramNotifiableException { } try{ // Your code which throws MyCustomException } catch (MyCustomException $e){ // Handling exception }
- Без наследования TelegramNotifiableException:
use LinkageCrm\CriticalAlertingBundle\Exception\Notifiable\TelegramNotifiableException; try{ // Your code which throws TelegramNotifiableException } catch (TelegramNotifiableException $e){ // Handling exception }
- Собственное исключение с другой логикой уведомления:
use LinkageCrm\CriticalAlertingBundle\Exception\Notifiable\AbstractNotifiableException; class MyCustomException extends AbstractNotifiableException { protected function notify(): void { // Your notification logic } } try{ // Your code which throws MyCustomException } catch (MyCustomException $e){ // Handling exception }
- Уведомление при возникновении любого необработанного исключения, если скрипт был запущен контроллером
<?php use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class TestBundleController extends AbstractController { /** * @throws \Exception */ #[Route('/test-alerting', name: 'test-alerting')] public function test4():Response { throw new \Exception('Test alerting'); return $this->json(['ok']); } }
Вид сообщения с ошибкой:
- Название сервера
- Referer
- Текст ошибки
- Стек вызова ошибки