diff --git a/.github/workflows/phpstan.yaml b/.github/workflows/phpstan.yaml index 6804a8f..e678e94 100644 --- a/.github/workflows/phpstan.yaml +++ b/.github/workflows/phpstan.yaml @@ -11,24 +11,6 @@ permissions: contents: read jobs: - phpstan: - name: PHPStan - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 - - - name: Setup PHP - uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4``` - with: - php-version: '8.4' - - - name: Install dependencies - run: composer update --no-progress --no-interaction --prefer-dist - - - name: Run script - run: vendor/bin/phpstan analyse - phpstan-agent: name: PHPStan (agent) runs-on: ubuntu-latest diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 5e52092..ac68d47 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -41,7 +41,6 @@ ->setFinder( PhpCsFixer\Finder::create() ->in([ - __DIR__ . '/src', __DIR__ . '/agent/src', ]) ); diff --git a/README.md b/README.md index 9cc7b51..f4630a6 100644 --- a/README.md +++ b/README.md @@ -21,20 +21,22 @@ _Bad software is everywhere, and we're tired of it. Sentry is on a mission to he ### Install -Install the agent using [Composer](https://getcomposer.org/). +Install the agent alongside the [PHP SDK](https://github.com/getsentry/sentry-php) using [Composer](https://getcomposer.org/). ```bash -composer require sentry/sentry-agent +composer require sentry/sentry sentry/sentry-agent ``` ### Configuration -The agent is configured as a custom HTTP client for the [PHP](https://github.com/getsentry/sentry-php) (also [Symfony](https://github.com/getsentry/sentry-symfony) & [Laravel](https://github.com/getsentry/sentry-laravel)) SDKs. +Use the SDK-provided agent client as the custom HTTP client for the [PHP](https://github.com/getsentry/sentry-php) (also [Symfony](https://github.com/getsentry/sentry-symfony) & [Laravel](https://github.com/getsentry/sentry-laravel)) SDKs. ```php +use Sentry\Agent\Transport\AgentClientBuilder; + Sentry\init([ 'dsn' => '___PUBLIC_DSN___', - 'http_client' => new \Sentry\Agent\Transport\AgentClient(), + 'http_client' => AgentClientBuilder::create()->getClient(), ]); ``` diff --git a/agent/composer.json b/agent/composer.json index 6dd852f..43fe971 100644 --- a/agent/composer.json +++ b/agent/composer.json @@ -16,7 +16,7 @@ "clue/mq-react": "^1.6", "react/http": "^1.11", "react/socket": "^1.16", - "sentry/sentry": "^4.19.1" + "sentry/sentry": "^4.26.0" }, "autoload": { "psr-4": { diff --git a/agent/composer.lock b/agent/composer.lock index 395bfea..ca6f985 100644 --- a/agent/composer.lock +++ b/agent/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "96c9e58e39082c47dc720fcd114c68b6", + "content-hash": "2440bbf4663b7a18044fdda6212dac74", "packages": [ { "name": "clue/mq-react", @@ -1035,16 +1035,16 @@ }, { "name": "sentry/sentry", - "version": "4.19.1", + "version": "4.26.0", "source": { "type": "git", "url": "https://github.com/getsentry/sentry-php.git", - "reference": "1c21d60bebe67c0122335bd3fe977990435af0a3" + "reference": "7597fd10c443929c62489d7cf38d1cb8341d6608" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/getsentry/sentry-php/zipball/1c21d60bebe67c0122335bd3fe977990435af0a3", - "reference": "1c21d60bebe67c0122335bd3fe977990435af0a3", + "url": "https://api.github.com/repos/getsentry/sentry-php/zipball/7597fd10c443929c62489d7cf38d1cb8341d6608", + "reference": "7597fd10c443929c62489d7cf38d1cb8341d6608", "shasum": "" }, "require": { @@ -1065,12 +1065,18 @@ "guzzlehttp/promises": "^2.0.3", "guzzlehttp/psr7": "^1.8.4|^2.1.1", "monolog/monolog": "^1.6|^2.0|^3.0", + "nyholm/psr7": "^1.8", + "open-telemetry/api": "^1.0", + "open-telemetry/exporter-otlp": "^1.0", + "open-telemetry/sdk": "^1.0", "phpbench/phpbench": "^1.0", "phpstan/phpstan": "^1.3", - "phpunit/phpunit": "^8.5|^9.6", - "vimeo/psalm": "^4.17" + "phpunit/phpunit": "^8.5.52|^9.6.34", + "spiral/roadrunner-http": "^3.6", + "spiral/roadrunner-worker": "^3.6" }, "suggest": { + "ext-excimer": "Enable Sentry profiling with the Excimer PHP extension.", "monolog/monolog": "Allow sending log messages to Sentry by using the included Monolog handler." }, "type": "library", @@ -1107,7 +1113,7 @@ ], "support": { "issues": "https://github.com/getsentry/sentry-php/issues", - "source": "https://github.com/getsentry/sentry-php/tree/4.19.1" + "source": "https://github.com/getsentry/sentry-php/tree/4.26.0" }, "funding": [ { @@ -1119,7 +1125,7 @@ "type": "custom" } ], - "time": "2025-12-02T15:57:41+00:00" + "time": "2026-04-30T12:50:22+00:00" }, { "name": "symfony/options-resolver", @@ -1190,16 +1196,16 @@ }, { "name": "symfony/polyfill-php80", - "version": "v1.33.0", + "version": "v1.37.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608" + "reference": "dfb55726c3a76ea3b6459fcfda1ec2d80a682411" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/0cc9dd0f17f61d8131e7df6b84bd344899fe2608", - "reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/dfb55726c3a76ea3b6459fcfda1ec2d80a682411", + "reference": "dfb55726c3a76ea3b6459fcfda1ec2d80a682411", "shasum": "" }, "require": { @@ -1250,7 +1256,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.33.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.37.0" }, "funding": [ { @@ -1270,7 +1276,7 @@ "type": "tidelift" } ], - "time": "2025-01-02T08:10:11+00:00" + "time": "2026-04-10T16:19:22+00:00" } ], "packages-dev": [ diff --git a/bin/sentry-agent b/bin/sentry-agent index 2018297..93990e2 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 cee0682..5682139 100644 --- a/bin/sentry-agent.sig +++ b/bin/sentry-agent.sig @@ -1 +1 @@ -D8B94BAD7E5B61D6310089C043AA6B9A3BEFD4FB4B41752004863AB4B822A2A43B49CC2587FB83446D8AA5AC8FE6A5AA6095D8DC932DE00334D1359F70C1D9A8 +F3CE4B37DC4AC5C3890CC9497A95351E29641DA3BAD0699B727A8D77002C6B36913EB82B55ACB1BA683D27CBAF123007D2CE68AA10773CF4012292D38E5F1904 diff --git a/composer.json b/composer.json index 5d4e697..d324618 100644 --- a/composer.json +++ b/composer.json @@ -12,37 +12,20 @@ ], "require": { "php": "^7.2|^8", - "ext-json": "*", - "sentry/sentry": "^4.19.1" - }, - "autoload": { - "psr-4": { - "Sentry\\Agent\\": "src/" - } + "ext-json": "*" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.70", - "phpstan/phpstan": "^2.1", - "phpunit/phpunit": "^8.5|^9.6" - }, - "autoload-dev": { - "psr-4": { - "Sentry\\Agent\\Tests\\": "tests/" - } + "friendsofphp/php-cs-fixer": "^3.70" }, "bin": [ "bin/sentry-agent" ], "scripts": { "check": [ - "@cs-check", - "@phpstan", - "@tests" + "@cs-check" ], - "tests": "vendor/bin/phpunit --verbose", "cs-check": "vendor/bin/php-cs-fixer fix --verbose --diff --dry-run", "cs-fix": "vendor/bin/php-cs-fixer fix --verbose --diff", - "phpstan": "vendor/bin/phpstan analyse", "build": "scripts/build.sh" }, "config": { diff --git a/examples/send.php b/examples/send.php index 065ee3c..d501145 100644 --- a/examples/send.php +++ b/examples/send.php @@ -2,11 +2,15 @@ declare(strict_types=1); -require_once __DIR__ . '/../vendor/autoload.php'; +use Sentry\Agent\Transport\AgentClientBuilder; + +require_once __DIR__ . '/../agent/vendor/autoload.php'; Sentry\init([ - 'dsn' => '___PUBLIC_DSN___', - 'http_client' => new Sentry\Agent\Transport\AgentClient(), + 'dsn' => getenv('SENTRY_DSN') ?: 'https://public@example.com/1', + 'http_client' => AgentClientBuilder::create() + ->disableFallbackClient() + ->getClient(), ]); $startTime = microtime(true); diff --git a/phpstan.neon b/phpstan.neon deleted file mode 100644 index 3e639cd..0000000 --- a/phpstan.neon +++ /dev/null @@ -1,4 +0,0 @@ -parameters: - level: 9 - paths: - - src diff --git a/src/Transport/AgentClient.php b/src/Transport/AgentClient.php deleted file mode 100644 index a97047e..0000000 --- a/src/Transport/AgentClient.php +++ /dev/null @@ -1,101 +0,0 @@ -host = $host; - $this->port = $port; - } - - public function __destruct() - { - $this->disconnect(); - } - - /** - * @phpstan-assert-if-true resource $this->socket - */ - private function connect(): bool - { - if ($this->socket !== null) { - return true; - } - - // We set the timeout to 10ms to avoid blocking the request for too long if the agent is not running - // @TODO: 10ms should be low enough? Do we want to go lower and/or make this configurable? Only applies to initial connection. - $socket = fsockopen($this->host, $this->port, $errorNo, $errorMsg, 0.01); - - // @TODO: Error handling? See $errorNo and $errorMsg - if ($socket === false) { - return false; - } - - // @TODO: Set a timeout for the socket to prevent blocking (?) if the socket connection stops working after the connection (e.g. the agent is stopped) if needed - $this->socket = $socket; - - return true; - } - - private function disconnect(): void - { - if ($this->socket === null) { - return; - } - - fclose($this->socket); - - $this->socket = null; - } - - private function send(string $message): void - { - if (!$this->connect()) { - return; - } - - // @TODO: Make sure we don't send more than 2^32 - 1 bytes - $contentLength = pack('N', \strlen($message) + 4); - - // @TODO: Error handling? - fwrite($this->socket, $contentLength . $message); - } - - public function sendRequest(Request $request, Options $options): Response - { - $body = $request->getStringBody(); - - if (empty($body)) { - return new Response(400, [], 'Request body is empty'); - } - - $this->send($body); - - // Since we are sending async there is no feedback so we always return an empty response - return new Response(202, [], ''); - } -}