From c3aed2883faf9d11ed1d4db7b54a224d80921b02 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Mon, 22 Sep 2025 13:06:32 +0200 Subject: [PATCH 1/4] Improve the CLI output and interactions --- agent/src/Console/Log.php | 20 ++++++ agent/src/sentry-agent.php | 128 +++++++++++++++++++++++++++++-------- 2 files changed, 123 insertions(+), 25 deletions(-) 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..65f8ece 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; -} - 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'; + $vendorPath = __DIR__ . '/../vendor'; } 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'; + $vendorPath = $_composer_autoload_path ?? __DIR__ . '/../vendor'; +} + +require_once "{$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); } From d7f1d99bbf888a4f9ee4fbd057a1cee23bddca5f Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 22 Sep 2025 11:34:49 +0000 Subject: [PATCH 2/4] Add PHAR artifact --- bin/sentry-agent | Bin 1745506 -> 1747752 bytes bin/sentry-agent.sig | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/sentry-agent b/bin/sentry-agent index 48ec7759bac603117263291d70ba898f0bc99c7f..2d94f974746fc37b33a0189d302fe39068697e40 100755 GIT binary patch delta 3473 zcma)9U2GiH6^_A<%{V5Gf5#!9gR{--g7?o#Rd+H|mpYz@CeCM3&Pp_SS{loKbJX0DR9^ba@$q(PI@K3mK?fcKaP|EMw-|ao* zpZ9d%XZ);dn|O`lJ9}g8_R*(9<%^+m7uqdox1x2U^`LD>>qYBByA4f3>qpyxHh^|J z+D^1Vv|VUJXv1hDXrpLjXyY59viw>1Mx`q6@7f!x5u<3*ld4mJH01Mh51h{DAqGl3 z7K?jh?01H|Hn3?T`&U)o&6Z4AZYT$&x+GDu>}r(cO`||yaxE~q9#>t*)J?S*vntl) z0Z9tk#Bk{9Y#Be!5^8Ivfv%NA4F7O9Nh?9Pr0FD29@A{c4sY46U{)>DCN!=YwxhB` z*@3?3WF!J>65uN&p6WU&;+{ULEr3`eJ22khNW_AUXxiK46l$7|vY1mWN*rf3U-KX< zi*V==bU2IPqvRR|hab$Mn&BKHx)qM3pk``C$-~(w>*kWGciun%BZZ0y2M-=RmYF{( zWd&s*ID@qgUh5!9bHpxC&EkGjxWz2!W&vHOoM><=sslO_N(>uHW`lyiXLjyEK@>r* zK{bjvNLN%^v~dZkf@AVeDB`eYAglf=3;+@lLpRbH8$ED`vAD-&)bp4#1r&RcPded! z=hLE{$a`cza89cI+p0P0eUaEloF$`nm(O5btaQtz+KpT z%kslB!R5)|>SdR>1dm?ToOI^++06WjlbM!pT%DuxgOi(AC%pC18WJ4E@GN1TaEd1y z4^@Z(wrg3shB4#;^AI&;jPR0MhAMK1L&&2ScZ6=6I++3!7ts~XCdi+@3WQRV zdV0}}lG$FTQsQk$iju^&%k!Zjg?uq!R+fo_Kf+2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@fe~L(S?G|!vX~ZEGDHzpac^0cnI;vKOR$TQ+1v>*6MB2YhR7|=4$i^oC`2NCkV>T>qK}9`b#)c~ ze?A&*WIQ|}k6Wz-056)!+YouhF>*8kv3>^`h;kH1$Yj=Hj--6v$Yup~oVo2l(H3&< zWteq~jug}=%u80Fs2MZ1Lm8WAT!D%*WehL6)TQ$lD=;}1ff!tz9-p2co0?2ENGvm% z3{>h}78&uW4=;2aP}Aw24z;q;)2$W@WO=8ci!KxDeTy7cK~9KT+vo|7R|0{1O$ar( zd(=ZvVlt1F9|o+iDQqr}1CtR4LoUY_WFdri0a{5Yp}wl`4pniy#4jRJL|dM3)< z!U7czmgQknvE{rhSfdU#L?)ja9*jSuDK)ROQO5qGE3ofOpS?h(#8XQ~S$o5w7R^Wu z>$9MW5#$65XdKfP!0i$)#bx+48K<#8xY3Vi8|{G9eeE9{IvE?l&mcB829boWbJHM0 zo`E#GzNA;Pvo<$b&c(KR?$iBKQ;Q^8Jq`}z844xzEwUCa=Zxoc6%G7qTWEbao6%zv ziDpqi)8LlPb11Lr2E8-asU_RBvZzNC49hA**7mjoL36HU2tX?Ux<%4u8Bh}?a`;e_ z^$CylP;8(f#MZ1-#C>bF%=+x~U5zFr|Izc;S` z@CNzJr?z7LP6dDX_o(C=N!Gt#BQN>Xk9Q8n)u&g<-r87=AiC>gwVrp6jX(9omD9hU z=)U;#ug6AiPK@0B_WIvP#?Ox!?_GKGC*zmuOl0%=)mOg=#!s$a`{%EXv#%AMt+zjN Xd(-iK(XqR=(GUFiSNy`6^qGGF>38Vo diff --git a/bin/sentry-agent.sig b/bin/sentry-agent.sig index 138bcb7..226fd52 100644 --- a/bin/sentry-agent.sig +++ b/bin/sentry-agent.sig @@ -1 +1 @@ -251F7E40F033195CDCE72336B54B36ECC79AFB1C485636619D7E82DB61E57F5327A49A895AB91034379396FEFAA343607073D192A775284D340D2D45EC873FA2 +2489A2B51295B1A976162DED711AA34EE67DDCBD6AE926BDDDC447302D31D55223519FDDC2A599AC19A7F9F38AA54663947CDA5AFDD4A182382ED25BCC32D055 From ac34190883c8b147b9ad7dd414eabc9cf1018be0 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Mon, 22 Sep 2025 14:02:09 +0200 Subject: [PATCH 3/4] Fix requiring the autoloader --- agent/src/sentry-agent.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/agent/src/sentry-agent.php b/agent/src/sentry-agent.php index 65f8ece..6dbf89a 100755 --- a/agent/src/sentry-agent.php +++ b/agent/src/sentry-agent.php @@ -9,18 +9,18 @@ use Sentry\Agent\EnvelopeQueue; use Sentry\Agent\Server; +$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. - $vendorPath = __DIR__ . '/../vendor'; + require_once "{$vendorPath}/autoload.php"; } else { // This works fine for local development or if running the phar from ./vendor/sentry/sentry-agent/bin/ - $vendorPath = $_composer_autoload_path ?? __DIR__ . '/../vendor'; + require_once $_composer_autoload_path ?? "{$vendorPath}/autoload.php"; } -require_once "{$vendorPath}/autoload.php"; - $sentryAgentVersion = '0.0.0'; if (file_exists("{$vendorPath}/composer/installed.php")) { From d111ccf31dd7f8e6a160186650bb610135798518 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 22 Sep 2025 12:03:03 +0000 Subject: [PATCH 4/4] Add PHAR artifact --- bin/sentry-agent | Bin 1747752 -> 1747757 bytes bin/sentry-agent.sig | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/sentry-agent b/bin/sentry-agent index 2d94f974746fc37b33a0189d302fe39068697e40..39afa62857b794156070051218622ee75e7ce4b8 100755 GIT binary patch delta 262 zcmZ2+Eo<$ytPL$`0utg33=P+IWPs@YC)2((Pf2T^lEw(cOhC*G#4JF}3dC$c%nrmH zK+FlmTtLhX#5_RE3&eat%n!r@Kr9HvLO?7G#3Dc}3dCYSEWUk8nnW|}bnjdVwe4a# z5~hsP_3|XNrx)f*RB#ui7M5lfrN-yyB~PE1BO%RXZ$I5CPePutwml+G0*EEIN90L$ z*m(RukzwBSFd%fTa8uJc)vvdhLwq&)0rD dF64W!qXeJv7wr(CRCP9qgDeaT4DL?8P5@v{X1M?W delta 288 zcmZ2`Eo;TKtPL$`0>a`93=P+IWPoUerXz99Q_|X}q%i_96A&{4F$)m00x=s9vjZ^) z5OV@C7Z7s;F%J;)0x=&D^8>K}5DNma5D*Iku?P^00c`5lt0f{9U3bxY~^CV=Y13e>H+YPq