fix(Discovery): Add comprehensive debug logging for router initialization
- Add initializer count logging in DiscoveryServiceBootstrapper - Add route structure analysis in RouterSetup - Add request parameter logging in HttpRouter - Update PHP production config for better OPcache handling - Fix various config and error handling improvements
This commit is contained in:
@@ -48,7 +48,8 @@ final readonly class ErrorReport
|
||||
public static function fromThrowable(
|
||||
Throwable $throwable,
|
||||
string $level = 'error',
|
||||
array $context = []
|
||||
array $context = [],
|
||||
?string $environment = null
|
||||
): self {
|
||||
return new self(
|
||||
id: self::generateId(),
|
||||
@@ -60,7 +61,7 @@ final readonly class ErrorReport
|
||||
line: $throwable->getLine(),
|
||||
trace: $throwable->getTraceAsString(),
|
||||
context: $context,
|
||||
environment: $_ENV['APP_ENV'] ?? 'production',
|
||||
environment: $environment ?? 'production',
|
||||
serverInfo: self::getServerInfo()
|
||||
);
|
||||
}
|
||||
@@ -72,7 +73,8 @@ final readonly class ErrorReport
|
||||
string $level,
|
||||
string $message,
|
||||
array $context = [],
|
||||
?Throwable $exception = null
|
||||
?Throwable $exception = null,
|
||||
?string $environment = null
|
||||
): self {
|
||||
return new self(
|
||||
id: self::generateId(),
|
||||
@@ -84,7 +86,7 @@ final readonly class ErrorReport
|
||||
line: $exception?->getLine() ?? debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]['line'] ?? 0,
|
||||
trace: $exception?->getTraceAsString() ?? self::getCurrentTrace(),
|
||||
context: $context,
|
||||
environment: $_ENV['APP_ENV'] ?? 'production',
|
||||
environment: $environment ?? 'production',
|
||||
serverInfo: self::getServerInfo()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\ErrorReporting;
|
||||
|
||||
use App\Framework\Config\Environment;
|
||||
use App\Framework\Database\ConnectionInterface;
|
||||
use App\Framework\DateTime\Clock;
|
||||
use App\Framework\DI\Container;
|
||||
@@ -25,7 +26,8 @@ final readonly class ErrorReportingInitializer
|
||||
#[Initializer]
|
||||
public function initialize(Container $container): void
|
||||
{
|
||||
$enabled = (bool) ($_ENV['ERROR_REPORTING_ENABLED'] ?? true);
|
||||
$env = $container->get(Environment::class);
|
||||
$enabled = $env->getBool('ERROR_REPORTING_ENABLED', true);
|
||||
|
||||
// Storage
|
||||
$container->bind(ErrorReportStorageInterface::class, function (Container $container) use ($enabled) {
|
||||
@@ -55,6 +57,7 @@ final readonly class ErrorReportingInitializer
|
||||
return new NullErrorReporter();
|
||||
}
|
||||
|
||||
$env = $container->get(Environment::class);
|
||||
$processors = [];
|
||||
$filters = [];
|
||||
|
||||
@@ -68,15 +71,17 @@ final readonly class ErrorReportingInitializer
|
||||
}
|
||||
|
||||
// Add environment-based filters
|
||||
if (($_ENV['ERROR_REPORTING_FILTER_LEVELS'] ?? null)) {
|
||||
$allowedLevels = explode(',', $_ENV['ERROR_REPORTING_FILTER_LEVELS']);
|
||||
$filterLevels = $env->getString('ERROR_REPORTING_FILTER_LEVELS', '');
|
||||
if ($filterLevels !== '') {
|
||||
$allowedLevels = explode(',', $filterLevels);
|
||||
$filters[] = function (ErrorReport $report) use ($allowedLevels) {
|
||||
return in_array($report->level, $allowedLevels);
|
||||
};
|
||||
}
|
||||
|
||||
// Add environment filter for production
|
||||
if (($_ENV['APP_ENV'] ?? 'production') === 'production') {
|
||||
$appEnv = $env->getString('APP_ENV', 'production');
|
||||
if ($appEnv === 'production') {
|
||||
$filters[] = function (ErrorReport $report) {
|
||||
// Don't report debug/info in production
|
||||
return ! in_array($report->level, ['debug', 'info']);
|
||||
@@ -88,7 +93,7 @@ final readonly class ErrorReportingInitializer
|
||||
clock: $container->get(Clock::class),
|
||||
logger: $container->has(Logger::class) ? $container->get(Logger::class) : null,
|
||||
queue: $container->has(Queue::class) ? $container->get(Queue::class) : null,
|
||||
asyncProcessing: (bool) ($_ENV['ERROR_REPORTING_ASYNC'] ?? true),
|
||||
asyncProcessing: $env->getBool('ERROR_REPORTING_ASYNC', true),
|
||||
processors: $processors,
|
||||
filters: $filters
|
||||
);
|
||||
@@ -100,6 +105,7 @@ final readonly class ErrorReportingInitializer
|
||||
throw new \RuntimeException('ErrorReporter is disabled. Use ErrorReporterInterface instead.');
|
||||
}
|
||||
|
||||
$env = $container->get(Environment::class);
|
||||
$processors = [];
|
||||
$filters = [];
|
||||
|
||||
@@ -113,15 +119,17 @@ final readonly class ErrorReportingInitializer
|
||||
}
|
||||
|
||||
// Add environment-based filters
|
||||
if (($_ENV['ERROR_REPORTING_FILTER_LEVELS'] ?? null)) {
|
||||
$allowedLevels = explode(',', $_ENV['ERROR_REPORTING_FILTER_LEVELS']);
|
||||
$filterLevels = $env->getString('ERROR_REPORTING_FILTER_LEVELS', '');
|
||||
if ($filterLevels !== '') {
|
||||
$allowedLevels = explode(',', $filterLevels);
|
||||
$filters[] = function (ErrorReport $report) use ($allowedLevels) {
|
||||
return in_array($report->level, $allowedLevels);
|
||||
};
|
||||
}
|
||||
|
||||
// Add environment filter for production
|
||||
if (($_ENV['APP_ENV'] ?? 'production') === 'production') {
|
||||
$appEnv = $env->getString('APP_ENV', 'production');
|
||||
if ($appEnv === 'production') {
|
||||
$filters[] = function (ErrorReport $report) {
|
||||
// Don't report debug/info in production
|
||||
return ! in_array($report->level, ['debug', 'info']);
|
||||
@@ -133,17 +141,17 @@ final readonly class ErrorReportingInitializer
|
||||
clock: $container->get(Clock::class),
|
||||
logger: $container->has(Logger::class) ? $container->get(Logger::class) : null,
|
||||
queue: $container->has(Queue::class) ? $container->get(Queue::class) : null,
|
||||
asyncProcessing: (bool) ($_ENV['ERROR_REPORTING_ASYNC'] ?? true),
|
||||
asyncProcessing: $env->getBool('ERROR_REPORTING_ASYNC', true),
|
||||
processors: $processors,
|
||||
filters: $filters
|
||||
);
|
||||
});
|
||||
|
||||
// Middleware
|
||||
$container->bind(ErrorReportingMiddleware::class, function (Container $container) {
|
||||
$container->bind(ErrorReportingMiddleware::class, function (Container $container) use ($enabled) {
|
||||
return new ErrorReportingMiddleware(
|
||||
reporter: $container->get(ErrorReporter::class),
|
||||
enabled: (bool) ($_ENV['ERROR_REPORTING_ENABLED'] ?? true)
|
||||
enabled: $enabled
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user