Added Sentry error logging.

This commit is contained in:
flash 2023-10-31 16:19:58 +00:00
parent 4836a52548
commit ba54f09ccd
5 changed files with 1733 additions and 13 deletions

View file

@ -3,7 +3,8 @@
"prefer-stable": true, "prefer-stable": true,
"require": { "require": {
"flashwave/index": "dev-master", "flashwave/index": "dev-master",
"flashwave/syokuhou": "dev-master" "flashwave/syokuhou": "dev-master",
"sentry/sdk": "^3.5"
}, },
"require-dev": { "require-dev": {
"phpstan/phpstan": "^1.10" "phpstan/phpstan": "^1.10"
@ -12,5 +13,10 @@
"psr-4": { "psr-4": {
"EEPROM\\": "src" "EEPROM\\": "src"
} }
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
} }
} }

1697
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,3 +13,7 @@ domain:api eeprom.flashii.net
; List of allowed remote domains ; List of allowed remote domains
cors:origins flashii.net chat.flashii.net sockchat.flashii.net cors:origins flashii.net chat.flashii.net sockchat.flashii.net
;sentry:dsn https://sentry dsn here
;sentry:tracesRate 1.0
;sentry:profilesRate 1.0

View file

@ -23,18 +23,18 @@ date_default_timezone_set('utc');
$cfg = SharpConfig::fromFile(PRM_ROOT . '/config.cfg'); $cfg = SharpConfig::fromFile(PRM_ROOT . '/config.cfg');
set_exception_handler(function(\Throwable $ex) { if($cfg->hasValues('sentry:dsn'))
http_response_code(500); (function($cfg) {
header('Content-Type: text/plain; charset=utf-8'); \Sentry\init([
if(PRM_DEBUG) 'dsn' => $cfg->getString('dsn'),
echo (string)$ex; 'traces_sample_rate' => $cfg->getFloat('tracesRate', 0.2),
exit; 'profiles_sample_rate' => $cfg->getFloat('profilesRate', 0.2),
}); ]);
set_error_handler(function(int $errno, string $errstr, string $errfile, int $errline) { set_exception_handler(function(\Throwable $ex) {
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); \Sentry\captureException($ex);
return true; });
}, -1); })($cfg->scopeTo('sentry'));
if(!is_dir(PRM_UPLOADS)) if(!is_dir(PRM_UPLOADS))
mkdir(PRM_UPLOADS, 0775, true); mkdir(PRM_UPLOADS, 0775, true);

View file

@ -5,6 +5,19 @@ use Index\Http\HttpFx;
require_once __DIR__ . '/../eeprom.php'; require_once __DIR__ . '/../eeprom.php';
set_exception_handler(function(\Throwable $ex) {
\Sentry\captureException($ex);
ob_clean();
http_response_code(500);
if(PRM_DEBUG) {
header('Content-Type: text/plain; charset=utf-8');
echo (string)$ex;
} else echo '500';
exit;
});
function eepromOriginAllowed(string $origin): bool { function eepromOriginAllowed(string $origin): bool {
global $cfg; global $cfg;
@ -182,12 +195,14 @@ if($isApiDomain) {
$appInfo->getExpiry(), true $appInfo->getExpiry(), true
); );
} catch(UploadCreationFailedException $ex) { } catch(UploadCreationFailedException $ex) {
\Sentry\captureException($ex);
return 500; return 500;
} }
try { try {
$file->moveTo($fileInfo->getPath()); $file->moveTo($fileInfo->getPath());
} catch(\RuntimeException $ex) { } catch(\RuntimeException $ex) {
\Sentry\captureException($ex);
return 500; return 500;
} }
} }