Added Sentry error logging.
This commit is contained in:
parent
4836a52548
commit
ba54f09ccd
5 changed files with 1733 additions and 13 deletions
|
@ -3,7 +3,8 @@
|
|||
"prefer-stable": true,
|
||||
"require": {
|
||||
"flashwave/index": "dev-master",
|
||||
"flashwave/syokuhou": "dev-master"
|
||||
"flashwave/syokuhou": "dev-master",
|
||||
"sentry/sdk": "^3.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^1.10"
|
||||
|
@ -12,5 +13,10 @@
|
|||
"psr-4": {
|
||||
"EEPROM\\": "src"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"php-http/discovery": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
1697
composer.lock
generated
1697
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -13,3 +13,7 @@ domain:api eeprom.flashii.net
|
|||
|
||||
; List of allowed remote domains
|
||||
cors:origins flashii.net chat.flashii.net sockchat.flashii.net
|
||||
|
||||
;sentry:dsn https://sentry dsn here
|
||||
;sentry:tracesRate 1.0
|
||||
;sentry:profilesRate 1.0
|
||||
|
|
22
eeprom.php
22
eeprom.php
|
@ -23,18 +23,18 @@ date_default_timezone_set('utc');
|
|||
|
||||
$cfg = SharpConfig::fromFile(PRM_ROOT . '/config.cfg');
|
||||
|
||||
set_exception_handler(function(\Throwable $ex) {
|
||||
http_response_code(500);
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
if(PRM_DEBUG)
|
||||
echo (string)$ex;
|
||||
exit;
|
||||
});
|
||||
if($cfg->hasValues('sentry:dsn'))
|
||||
(function($cfg) {
|
||||
\Sentry\init([
|
||||
'dsn' => $cfg->getString('dsn'),
|
||||
'traces_sample_rate' => $cfg->getFloat('tracesRate', 0.2),
|
||||
'profiles_sample_rate' => $cfg->getFloat('profilesRate', 0.2),
|
||||
]);
|
||||
|
||||
set_error_handler(function(int $errno, string $errstr, string $errfile, int $errline) {
|
||||
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
|
||||
return true;
|
||||
}, -1);
|
||||
set_exception_handler(function(\Throwable $ex) {
|
||||
\Sentry\captureException($ex);
|
||||
});
|
||||
})($cfg->scopeTo('sentry'));
|
||||
|
||||
if(!is_dir(PRM_UPLOADS))
|
||||
mkdir(PRM_UPLOADS, 0775, true);
|
||||
|
|
|
@ -5,6 +5,19 @@ use Index\Http\HttpFx;
|
|||
|
||||
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 {
|
||||
global $cfg;
|
||||
|
||||
|
@ -182,12 +195,14 @@ if($isApiDomain) {
|
|||
$appInfo->getExpiry(), true
|
||||
);
|
||||
} catch(UploadCreationFailedException $ex) {
|
||||
\Sentry\captureException($ex);
|
||||
return 500;
|
||||
}
|
||||
|
||||
try {
|
||||
$file->moveTo($fileInfo->getPath());
|
||||
} catch(\RuntimeException $ex) {
|
||||
\Sentry\captureException($ex);
|
||||
return 500;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue