[+] подключение сентри и новый метод логирования

This commit is contained in:
rsgrinko committed 2022-06-30 17:10:08 +03:00
1 parent 295eca8f8a
commit b55f76ade5
7 files changed
+1983 -4

No files matched your search

+28 -1
View File
@@ -1,7 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/vendor/sentry/sentry" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/container" />
<excludeFolder url="file://$MODULE_DIR$/vendor/http-interop/http-factory-guzzle" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-message" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/log" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-client" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-factory" />
<excludeFolder url="file://$MODULE_DIR$/vendor/clue/stream-filter" />
<excludeFolder url="file://$MODULE_DIR$/vendor/php-http/httplug" />
<excludeFolder url="file://$MODULE_DIR$/vendor/php-http/message" />
<excludeFolder url="file://$MODULE_DIR$/vendor/php-http/client-common" />
<excludeFolder url="file://$MODULE_DIR$/vendor/php-http/discovery" />
<excludeFolder url="file://$MODULE_DIR$/vendor/php-http/message-factory" />
<excludeFolder url="file://$MODULE_DIR$/vendor/php-http/promise" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-client" />
<excludeFolder url="file://$MODULE_DIR$/vendor/jean85/pretty-package-versions" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-uuid" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/options-resolver" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php73" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/deprecation-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/promises" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/service-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/psr7" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php80" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-client-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/ralouphie/getallheaders" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
Generated
+29 -1
View File
@@ -6,7 +6,35 @@
<path value="$PROJECT_DIR$/vendor/composer" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
<path value="$PROJECT_DIR$/vendor/sentry/sentry" />
<path value="$PROJECT_DIR$/vendor/psr/container" />
<path value="$PROJECT_DIR$/vendor/http-interop/http-factory-guzzle" />
<path value="$PROJECT_DIR$/vendor/psr/http-message" />
<path value="$PROJECT_DIR$/vendor/psr/log" />
<path value="$PROJECT_DIR$/vendor/psr/http-client" />
<path value="$PROJECT_DIR$/vendor/psr/http-factory" />
<path value="$PROJECT_DIR$/vendor/clue/stream-filter" />
<path value="$PROJECT_DIR$/vendor/php-http/httplug" />
<path value="$PROJECT_DIR$/vendor/php-http/message" />
<path value="$PROJECT_DIR$/vendor/php-http/client-common" />
<path value="$PROJECT_DIR$/vendor/php-http/discovery" />
<path value="$PROJECT_DIR$/vendor/php-http/message-factory" />
<path value="$PROJECT_DIR$/vendor/php-http/promise" />
<path value="$PROJECT_DIR$/vendor/symfony/http-client" />
<path value="$PROJECT_DIR$/vendor/jean85/pretty-package-versions" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-uuid" />
<path value="$PROJECT_DIR$/vendor/symfony/options-resolver" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php73" />
<path value="$PROJECT_DIR$/vendor/symfony/deprecation-contracts" />
<path value="$PROJECT_DIR$/vendor/guzzlehttp/promises" />
<path value="$PROJECT_DIR$/vendor/symfony/service-contracts" />
<path value="$PROJECT_DIR$/vendor/guzzlehttp/psr7" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
<path value="$PROJECT_DIR$/vendor/symfony/http-client-contracts" />
<path value="$PROJECT_DIR$/vendor/ralouphie/getallheaders" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.4" />
<component name="PhpProjectSharedConfiguration" php_language_level="8.0">
<option name="suggestChangeDefaultLanguageLevel" value="false" />
</component>
</project>
+2 -1
View File
@@ -15,6 +15,7 @@
}
],
"require": {
"twig/twig": "^3.0"
"twig/twig": "^3.0",
"sentry/sdk": "^3.2"
}
}
Generated
+1864 -1
View File
File diff suppressed because it is too large. Load diff
+23
View File
@@ -10,6 +10,29 @@
session_start();
}
require_once __DIR__ . '/../vendor/autoload.php';
\Sentry\init(
[
'dsn' => 'https://8657ac1a900c44e5bc51714bb4c00dbb@o1303100.ingest.sentry.io/6541634',
'error_types' => E_ALL,
]
);
Sentry\configureScope(function (Sentry\State\Scope $sentryScope) {
$sentryScope->setExtra('user_id', $_SESSION['id']);
$sentryScope->setExtra('user_login', $_SESSION['login']);
$sentryScope->setExtra('user_token', $_SESSION['token']);
});
/*
try {
$this->functionFailsForSure();
} catch (\Throwable $exception) {
\Sentry\captureException($exception);
}
// OR
\Sentry\captureLastError();
*/
ob_start(function ($buffer) {
+34
View File
@@ -116,4 +116,38 @@
return $result ?: 0;
}
/**
* Метод сохранения логов в Sentry
*
* @param string $sentryMessage Сообщение, передаваемое в Sentry и отображающееся как заголовок Issue
* @param string $sentryErrorLevel Уровень события Sentry (FATAL, ERROR, WARNING, INFO, DEBUG)
* @param array $sentryData Массив данных лога
*
* @return bool
*/
public static function logToSentry(
string $sentryMessage,
string $sentryErrorLevel = 'DEBUG',
array $sentryData = []
): bool {
$sentryErrorLevelArray = ['FATAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'];
if (empty(trim($sentryMessage))
|| !in_array($sentryErrorLevel, $sentryErrorLevelArray)) {
return false;
}
if (is_array($sentryData) && count($sentryData) > 0) {
\Sentry\configureScope(function (\Sentry\State\Scope $sentryScope) use ($sentryData) {
foreach ($sentryData as $paramName => $paramValue) {
$sentryScope->setExtra($paramName, $paramValue);
}
});
}
\Sentry\captureMessage($sentryMessage, \Sentry\Severity::$sentryErrorLevel());
return true;
}
}
+3
View File
@@ -4,7 +4,10 @@
require_once $_SERVER['DOCUMENT_ROOT'] . '/core/bootstrap.php';
use Core\ExternalServices\TelegramSender;
use Core\Helpers\Log;
rfrf
//Log::logToSentry('Тестовая ошибка', 'ERROR', $_REQUEST);
die();
$numProc = 4;
if (empty($argv[1])) {