diff --git a/agent/src/Console/Log.php b/agent/src/Console/Log.php index 1ee6e70..54e5beb 100644 --- a/agent/src/Console/Log.php +++ b/agent/src/Console/Log.php @@ -11,9 +11,19 @@ class Log { private const LEVEL_INFO = 'INFO'; private const LEVEL_ERROR = 'ERROR'; + private const LEVEL_DEBUG = 'DEBUG'; + + /** + * @var bool Whether to output debug messages or not + */ + private static $verbose = false; private static function output(string $level, string $message): void { + if ($level === self::LEVEL_DEBUG && !self::$verbose) { + return; + } + echo \sprintf("sentry-agent [%-19s] [%-5s] %s\n", date('Y-m-d H:i:s'), $level, $message); } @@ -26,4 +36,14 @@ public static function error(string $message): void { self::output(self::LEVEL_ERROR, $message); } + + public static function debug(string $message): void + { + self::output(self::LEVEL_DEBUG, $message); + } + + public static function setVerbose(bool $verbose): void + { + self::$verbose = $verbose; + } } diff --git a/agent/src/sentry-agent.php b/agent/src/sentry-agent.php index 1f28b7e..6dbf89a 100755 --- a/agent/src/sentry-agent.php +++ b/agent/src/sentry-agent.php @@ -9,40 +9,118 @@ use Sentry\Agent\EnvelopeQueue; use Sentry\Agent\Server; -// @TODO: Improve the help output to be a little more useful and explain the different options -if (($argv[1] ?? '') === 'help' || ($argv[1] ?? '') === '--help' || ($argv[1] ?? '') === '-h') { - echo 'Usage: ./sentry-agent [listen_address] [listen_port] [upstream_timeout] [upstream_concurrency] [queue_limit]' . \PHP_EOL; - exit; -} +$vendorPath = __DIR__ . '/../vendor'; if (class_exists('Phar') && Phar::running(false) !== '') { // If running the .phar directly from ./vendor/bin/, we don't want to use $_composer_autoload_path since this // will load the projects files and lead to ClassNotFound errors. // We want to use the autoload.php from the phar itself. - require __DIR__ . '/../vendor/autoload.php'; + require_once "{$vendorPath}/autoload.php"; } else { // This works fine for local development or if running the phar from ./vendor/sentry/sentry-agent/bin/ - require $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php'; + require_once $_composer_autoload_path ?? "{$vendorPath}/autoload.php"; +} + +$sentryAgentVersion = '0.0.0'; + +if (file_exists("{$vendorPath}/composer/installed.php")) { + $installed = require "{$vendorPath}/composer/installed.php"; + + $sentryAgentVersion = $installed['root']['pretty_version'] ?? $sentryAgentVersion; +} + +function printHelp(): void +{ + global $sentryAgentVersion; + + echo << Starting Sentry agent, listening on {$listenAddress} with config:"); -Log::info(" > upstream timeout: {$upstreamTimeout}"); -Log::info(" > upstream concurrency: {$upstreamConcurrency}"); -Log::info(" > queue limit: {$queueLimit}"); +Log::info("Starting Sentry Agent ({$sentryAgentVersion}), listening on {$listenAddress} (timeout:{$upstreamTimeout}, concurrency:{$upstreamConcurrency}, queue:{$queueLimit})"); $forwarder = new EnvelopeForwarder( $upstreamTimeout, @@ -57,9 +135,9 @@ function (Psr\Http\Message\ResponseInterface $response) { $eventId = ''; } - Log::info("Envelope sent successfully (ID: {$eventId}, http status: {$response->getStatusCode()})."); + Log::debug("Envelope sent successfully (ID: {$eventId}, http status: {$response->getStatusCode()})."); } else { - Log::info("Envelope sent successfully (http status: {$response->getStatusCode()})."); + Log::debug("Envelope sent successfully (http status: {$response->getStatusCode()})."); } } else { Log::error("Envelope send error: {$response->getStatusCode()} {$response->getReasonPhrase()}"); @@ -97,7 +175,7 @@ function (Throwable $exception) { Log::error("Incoming connection error: {$exception->getMessage()}"); }, function (Envelope $envelope) use ($queue) { - Log::info('Envelope received, queueing forward to Sentry...'); + Log::debug('Envelope received, queueing forward to Sentry...'); $queue->enqueue($envelope); } diff --git a/bin/sentry-agent b/bin/sentry-agent index 48ec775..39afa62 100755 Binary files a/bin/sentry-agent and b/bin/sentry-agent differ diff --git a/bin/sentry-agent.sig b/bin/sentry-agent.sig index 138bcb7..3859eee 100644 --- a/bin/sentry-agent.sig +++ b/bin/sentry-agent.sig @@ -1 +1 @@ -251F7E40F033195CDCE72336B54B36ECC79AFB1C485636619D7E82DB61E57F5327A49A895AB91034379396FEFAA343607073D192A775284D340D2D45EC873FA2 +FFC8683782E15055AD138282CE25F5DA03544D28FEBEAEDD35908E6DE6733B368D3679EB5F13AC88AB20AD8E88B11ACE54F78D41180E33F42B541265270618C1