, \Psr\Log\LogLevel::*> */ protected $levels = [ // ]; /** * A list of the exception types that are not reported. * * @var array> */ protected $dontReport = [ AuthenticationException::class, AuthorizationException::class, Entities\AuthorizationException::class, HttpException::class, ModelNotFoundException::class, TokenMismatchException::class, ValidationException::class, PDOException::class, ]; /** * A list of the inputs that are never flashed to the session on validation exceptions. * * @var array */ protected $dontFlash = [ 'current_password', 'password', 'password_confirmation', ]; public function register(): void { $this->reportable(function (Throwable $e) { if (app()->bound('sentry')) { app('sentry')->captureException($e); } }); } /** * Get the default context variables for logging. * * @return array */ protected function context(): array { $traceId = Str::uuid()->toString(); try { // Only add trace_id to error response if Filter::getErrorResponseFilterName() method exists Filter::listen(Filter::getErrorResponseFilterName(), static function (array|null $data = []) use ($traceId) { $data['trace_id'] = $traceId; return $data; }); } catch (Throwable $exception) { } $requestContent = collect(rescue(fn() => request()->all(), [], false)) ->map(function ($item, string $key) { if (Str::contains($key, ['screenshot', 'password', 'secret', 'token', 'api_key'], true)) { return '***'; } return $item; })->toArray(); if (config('app.debug') === false){ try { $requestContent = Crypt::encryptString(json_encode($requestContent, JSON_THROW_ON_ERROR)); } catch (Throwable $exception) { } } return array_merge(parent::context(), [ 'trace_id' => $traceId, 'request_uri' => request()->getRequestUri(), 'request_content' => $requestContent ]); } public function render($request, $e): Response { $this->convert($e, [ MethodNotAllowedHttpException::class => fn($e) => throw new MethodNotAllowedException($e->getMessage()), AuthenticationException::class => fn($e ) => throw new Entities\AuthorizationException(Entities\AuthorizationException::ERROR_TYPE_UNAUTHORIZED), ]); $this->convertDefaultException($e); if ($e instanceof HttpException) { return $this->renderResponse($e); } return responder()->error($e->getCode(), $e->getMessage())->respond(); } }