Enable Discovery debug logging for production troubleshooting

- Add DISCOVERY_LOG_LEVEL=debug
- Add DISCOVERY_SHOW_PROGRESS=true
- Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
2025-08-11 20:13:26 +02:00
parent 59fd3dd3b1
commit 55a330b223
3683 changed files with 2956207 additions and 16948 deletions

View File

@@ -0,0 +1,103 @@
<?php
declare(strict_types=1);
namespace App\Framework\ErrorReporting;
use App\Framework\Database\ConnectionInterface;
use App\Framework\DateTime\Clock;
use App\Framework\DI\Container;
use App\Framework\DI\Initializer;
use App\Framework\ErrorReporting\Analytics\ErrorAnalyticsEngine;
use App\Framework\ErrorReporting\Processors\RequestContextProcessor;
use App\Framework\ErrorReporting\Processors\UserContextProcessor;
use App\Framework\ErrorReporting\Storage\DatabaseErrorReportStorage;
use App\Framework\ErrorReporting\Storage\ErrorReportStorageInterface;
use App\Framework\Http\Session\Session;
use App\Framework\Logging\Logger;
use App\Framework\Queue\Queue;
/**
* Initializer for Error Reporting system
*/
final readonly class ErrorReportingInitializer
{
#[Initializer]
public function initialize(Container $container): void
{
// Storage
$container->bind(ErrorReportStorageInterface::class, function (Container $container) {
return new DatabaseErrorReportStorage(
connection: $container->get(ConnectionInterface::class)
);
});
// Analytics Engine
$container->bind(ErrorAnalyticsEngine::class, function (Container $container) {
return new ErrorAnalyticsEngine(
storage: $container->get(ErrorReportStorageInterface::class),
clock: $container->get(Clock::class)
);
});
// Error Reporter
$container->bind(ErrorReporter::class, function (Container $container) {
$processors = [];
$filters = [];
// Add built-in processors
if ($container->has(RequestContextProcessor::class)) {
$processors[] = $container->get(RequestContextProcessor::class);
}
if ($container->has(UserContextProcessor::class)) {
$processors[] = $container->get(UserContextProcessor::class);
}
// Add environment-based filters
if (($_ENV['ERROR_REPORTING_FILTER_LEVELS'] ?? null)) {
$allowedLevels = explode(',', $_ENV['ERROR_REPORTING_FILTER_LEVELS']);
$filters[] = function (ErrorReport $report) use ($allowedLevels) {
return in_array($report->level, $allowedLevels);
};
}
// Add environment filter for production
if (($_ENV['APP_ENV'] ?? 'production') === 'production') {
$filters[] = function (ErrorReport $report) {
// Don't report debug/info in production
return ! in_array($report->level, ['debug', 'info']);
};
}
return new ErrorReporter(
storage: $container->get(ErrorReportStorageInterface::class),
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),
processors: $processors,
filters: $filters
);
});
// Middleware
$container->bind(ErrorReportingMiddleware::class, function (Container $container) {
return new ErrorReportingMiddleware(
reporter: $container->get(ErrorReporter::class),
enabled: (bool) ($_ENV['ERROR_REPORTING_ENABLED'] ?? true)
);
});
// Processors
$container->bind(RequestContextProcessor::class, function (Container $container) {
return new RequestContextProcessor();
});
$container->bind(UserContextProcessor::class, function (Container $container) {
// Session is not a singleton service - it's created per-request by SessionManager
// Don't try to resolve it here as it may not exist or trigger circular dependencies
return new UserContextProcessor(null);
});
}
}