diff --git a/README.md b/README.md index 5cd0864..92ada69 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,10 @@ Options: -s, --pyroscope=STRING Url of the pyroscope server. Example: https://your-pyroscope-sever.com + -auth, --pyroscopeAuthToken=STRING + Pyroscope Auth Token. + Example: psx-BWlqy_dW1Wxg6oBjuCWD28HxGCkB1Jfzt-jjtqHzrkzI + -a, --app=STRING Name of app. All samples will be saved under given app name. Example: app diff --git a/app/Commands/RunCommand.php b/app/Commands/RunCommand.php index 4673080..b70667d 100644 --- a/app/Commands/RunCommand.php +++ b/app/Commands/RunCommand.php @@ -26,6 +26,12 @@ protected function configure(): void { InputOption::VALUE_REQUIRED, 'Url of the pyroscope server. Example: https://your-pyroscope-sever.com' ), + new InputOption( + 'pyroscopeAuthToken', + 'auth', + InputOption::VALUE_OPTIONAL, + 'Pyroscope Auth Token. Example: psx-BWlqy_dW1Wxg6oBjuCWD28HxGCkB1Jfzt-jjtqHzrkzI' + ), new InputOption( 'app', 'a', @@ -116,6 +122,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int throw new InvalidArgumentException('sendSampleFutureLimit must be positive value'); } + $pyroscopeAuthToken = (string)$input->getOption('pyroscopeAuthToken'); + $tags = []; foreach ((array) $input->getOption('tags') as $tag) { if (strpos($tag, '=') === false) { @@ -140,7 +148,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $processor = new Processor( $interval, $batch, - new Sender($pyroscope, $app, $rateHz, $tags), + new Sender($pyroscope, $app, $rateHz, $tags, $pyroscopeAuthToken), array_values(array_filter($plugins)), $sendSampleFutureLimit, $concurrentRequestLimit, diff --git a/app/Sender.php b/app/Sender.php index b86699d..21c4e81 100644 --- a/app/Sender.php +++ b/app/Sender.php @@ -18,6 +18,7 @@ public function __construct( private readonly string $appName, private readonly int $rateHz, private readonly array $tags, + private readonly string $authToken = '', ) { $this->client = (new HttpClientBuilder()) ->retry(0) @@ -34,6 +35,9 @@ public function sendSample(Sample $sample): bool { $request->setTlsHandshakeTimeout(5 * 60); $request->setTransferTimeout(60 * 60); $request->setInactivityTimeout(60 * 60); + if (!empty($this->authToken)) { + $request->addHeader('Authorization', 'Bearer ' . $this->authToken); + } $response = $this->client->request($request); if ($response->getStatus() === 200) { return true;