diff --git a/composer.json b/composer.json index 5e1c8d74..5b9d19bc 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "phpcompatibility/php-compatibility": "9.3.5", "cyclonedx/cyclonedx-php-composer": "4.2.2", "php-http/guzzle7-adapter": "1.0.0", - "sentry/sentry": "3.22.0" + "sentry/sentry": "4.0.0" }, "config": { "platform": { @@ -47,7 +47,8 @@ "allow-plugins": { "composer/package-versions-deprecated": true, "dealerdirect/phpcodesniffer-composer-installer": true, - "cyclonedx/cyclonedx-php-composer": true + "cyclonedx/cyclonedx-php-composer": true, + "php-http/discovery": true } } } diff --git a/composer.lock b/composer.lock index 93602f65..90c9c30b 100644 --- a/composer.lock +++ b/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": "8dae8142d21e1a07dd668095dd52cf37", + "content-hash": "4c2218bc31c32f1001c467d4f9985c1a", "packages": [ { "name": "psr/log", @@ -224,72 +224,6 @@ ], "time": "2021-03-30T17:13:30+00:00" }, - { - "name": "clue/stream-filter", - "version": "v1.6.0", - "source": { - "type": "git", - "url": "https://github.com/clue/stream-filter.git", - "reference": "d6169430c7731d8509da7aecd0af756a5747b78e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/clue/stream-filter/zipball/d6169430c7731d8509da7aecd0af756a5747b78e", - "reference": "d6169430c7731d8509da7aecd0af756a5747b78e", - "shasum": "" - }, - "require": { - "php": ">=5.3" - }, - "require-dev": { - "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.36" - }, - "type": "library", - "autoload": { - "files": [ - "src/functions_include.php" - ], - "psr-4": { - "Clue\\StreamFilter\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Lück", - "email": "christian@clue.engineering" - } - ], - "description": "A simple and modern approach to stream filtering in PHP", - "homepage": "https://github.com/clue/php-stream-filter", - "keywords": [ - "bucket brigade", - "callback", - "filter", - "php_user_filter", - "stream", - "stream_filter_append", - "stream_filter_register" - ], - "support": { - "issues": "https://github.com/clue/stream-filter/issues", - "source": "https://github.com/clue/stream-filter/tree/v1.6.0" - }, - "funding": [ - { - "url": "https://clue.engineering/support", - "type": "custom" - }, - { - "url": "https://github.com/clue", - "type": "github" - } - ], - "time": "2022-02-21T13:15:14+00:00" - }, { "name": "composer/pcre", "version": "3.1.1", @@ -2056,153 +1990,6 @@ }, "time": "2022-02-21T01:04:05+00:00" }, - { - "name": "php-http/client-common", - "version": "2.7.0", - "source": { - "type": "git", - "url": "https://github.com/php-http/client-common.git", - "reference": "880509727a447474d2a71b7d7fa5d268ddd3db4b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-http/client-common/zipball/880509727a447474d2a71b7d7fa5d268ddd3db4b", - "reference": "880509727a447474d2a71b7d7fa5d268ddd3db4b", - "shasum": "" - }, - "require": { - "php": "^7.1 || ^8.0", - "php-http/httplug": "^2.0", - "php-http/message": "^1.6", - "psr/http-client": "^1.0", - "psr/http-factory": "^1.0", - "psr/http-message": "^1.0 || ^2.0", - "symfony/options-resolver": "~4.0.15 || ~4.1.9 || ^4.2.1 || ^5.0 || ^6.0", - "symfony/polyfill-php80": "^1.17" - }, - "require-dev": { - "doctrine/instantiator": "^1.1", - "guzzlehttp/psr7": "^1.4", - "nyholm/psr7": "^1.2", - "phpspec/phpspec": "^5.1 || ^6.3 || ^7.1", - "phpspec/prophecy": "^1.10.2", - "phpunit/phpunit": "^7.5.20 || ^8.5.33 || ^9.6.7" - }, - "suggest": { - "ext-json": "To detect JSON responses with the ContentTypePlugin", - "ext-libxml": "To detect XML responses with the ContentTypePlugin", - "php-http/cache-plugin": "PSR-6 Cache plugin", - "php-http/logger-plugin": "PSR-3 Logger plugin", - "php-http/stopwatch-plugin": "Symfony Stopwatch plugin" - }, - "type": "library", - "autoload": { - "psr-4": { - "Http\\Client\\Common\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com" - } - ], - "description": "Common HTTP Client implementations and tools for HTTPlug", - "homepage": "http://httplug.io", - "keywords": [ - "client", - "common", - "http", - "httplug" - ], - "support": { - "issues": "https://github.com/php-http/client-common/issues", - "source": "https://github.com/php-http/client-common/tree/2.7.0" - }, - "time": "2023-05-17T06:46:59+00:00" - }, - { - "name": "php-http/discovery", - "version": "1.19.1", - "source": { - "type": "git", - "url": "https://github.com/php-http/discovery.git", - "reference": "57f3de01d32085fea20865f9b16fb0e69347c39e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-http/discovery/zipball/57f3de01d32085fea20865f9b16fb0e69347c39e", - "reference": "57f3de01d32085fea20865f9b16fb0e69347c39e", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.0|^2.0", - "php": "^7.1 || ^8.0" - }, - "conflict": { - "nyholm/psr7": "<1.0", - "zendframework/zend-diactoros": "*" - }, - "provide": { - "php-http/async-client-implementation": "*", - "php-http/client-implementation": "*", - "psr/http-client-implementation": "*", - "psr/http-factory-implementation": "*", - "psr/http-message-implementation": "*" - }, - "require-dev": { - "composer/composer": "^1.0.2|^2.0", - "graham-campbell/phpspec-skip-example-extension": "^5.0", - "php-http/httplug": "^1.0 || ^2.0", - "php-http/message-factory": "^1.0", - "phpspec/phpspec": "^5.1 || ^6.1 || ^7.3", - "symfony/phpunit-bridge": "^6.2" - }, - "type": "composer-plugin", - "extra": { - "class": "Http\\Discovery\\Composer\\Plugin", - "plugin-optional": true - }, - "autoload": { - "psr-4": { - "Http\\Discovery\\": "src/" - }, - "exclude-from-classmap": [ - "src/Composer/Plugin.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com" - } - ], - "description": "Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations", - "homepage": "http://php-http.org", - "keywords": [ - "adapter", - "client", - "discovery", - "factory", - "http", - "message", - "psr17", - "psr7" - ], - "support": { - "issues": "https://github.com/php-http/discovery/issues", - "source": "https://github.com/php-http/discovery/tree/1.19.1" - }, - "time": "2023-07-11T07:02:26+00:00" - }, { "name": "php-http/guzzle7-adapter", "version": "1.0.0", @@ -2322,130 +2109,6 @@ }, "time": "2023-04-14T15:10:03+00:00" }, - { - "name": "php-http/message", - "version": "1.16.0", - "source": { - "type": "git", - "url": "https://github.com/php-http/message.git", - "reference": "47a14338bf4ebd67d317bf1144253d7db4ab55fd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-http/message/zipball/47a14338bf4ebd67d317bf1144253d7db4ab55fd", - "reference": "47a14338bf4ebd67d317bf1144253d7db4ab55fd", - "shasum": "" - }, - "require": { - "clue/stream-filter": "^1.5", - "php": "^7.2 || ^8.0", - "psr/http-message": "^1.1 || ^2.0" - }, - "provide": { - "php-http/message-factory-implementation": "1.0" - }, - "require-dev": { - "ergebnis/composer-normalize": "^2.6", - "ext-zlib": "*", - "guzzlehttp/psr7": "^1.0 || ^2.0", - "laminas/laminas-diactoros": "^2.0 || ^3.0", - "php-http/message-factory": "^1.0.2", - "phpspec/phpspec": "^5.1 || ^6.3 || ^7.1", - "slim/slim": "^3.0" - }, - "suggest": { - "ext-zlib": "Used with compressor/decompressor streams", - "guzzlehttp/psr7": "Used with Guzzle PSR-7 Factories", - "laminas/laminas-diactoros": "Used with Diactoros Factories", - "slim/slim": "Used with Slim Framework PSR-7 implementation" - }, - "type": "library", - "autoload": { - "files": [ - "src/filters.php" - ], - "psr-4": { - "Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com" - } - ], - "description": "HTTP Message related tools", - "homepage": "http://php-http.org", - "keywords": [ - "http", - "message", - "psr-7" - ], - "support": { - "issues": "https://github.com/php-http/message/issues", - "source": "https://github.com/php-http/message/tree/1.16.0" - }, - "time": "2023-05-17T06:43:38+00:00" - }, - { - "name": "php-http/message-factory", - "version": "1.1.0", - "source": { - "type": "git", - "url": "https://github.com/php-http/message-factory.git", - "reference": "4d8778e1c7d405cbb471574821c1ff5b68cc8f57" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-http/message-factory/zipball/4d8778e1c7d405cbb471574821c1ff5b68cc8f57", - "reference": "4d8778e1c7d405cbb471574821c1ff5b68cc8f57", - "shasum": "" - }, - "require": { - "php": ">=5.4", - "psr/http-message": "^1.0 || ^2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com" - } - ], - "description": "Factory interfaces for PSR-7 HTTP Message", - "homepage": "http://php-http.org", - "keywords": [ - "factory", - "http", - "message", - "stream", - "uri" - ], - "support": { - "issues": "https://github.com/php-http/message-factory/issues", - "source": "https://github.com/php-http/message-factory/tree/1.1.0" - }, - "abandoned": "psr/http-factory", - "time": "2023-04-14T14:16:17+00:00" - }, { "name": "php-http/promise", "version": "1.2.0", @@ -4371,51 +4034,38 @@ }, { "name": "sentry/sentry", - "version": "3.22.0", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/getsentry/sentry-php.git", - "reference": "c0e3df5a5c1d133cd9461e7672568ff07042c19d" + "reference": "7e10bf3fd0bee2f2eee6981e509522ab0c523d5e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/getsentry/sentry-php/zipball/c0e3df5a5c1d133cd9461e7672568ff07042c19d", - "reference": "c0e3df5a5c1d133cd9461e7672568ff07042c19d", + "url": "https://api.github.com/repos/getsentry/sentry-php/zipball/7e10bf3fd0bee2f2eee6981e509522ab0c523d5e", + "reference": "7e10bf3fd0bee2f2eee6981e509522ab0c523d5e", "shasum": "" }, "require": { + "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "guzzlehttp/promises": "^1.5.3|^2.0", + "guzzlehttp/psr7": "^1.8.4|^2.1.1", "jean85/pretty-package-versions": "^1.5|^2.0.4", "php": "^7.2|^8.0", - "php-http/async-client-implementation": "^1.0", - "php-http/client-common": "^1.5|^2.0", - "php-http/discovery": "^1.15", - "php-http/httplug": "^1.1|^2.0", - "php-http/message": "^1.5", - "php-http/message-factory": "^1.1", - "psr/http-factory": "^1.0", - "psr/http-factory-implementation": "^1.0", "psr/log": "^1.0|^2.0|^3.0", - "symfony/options-resolver": "^3.4.43|^4.4.30|^5.0.11|^6.0|^7.0", - "symfony/polyfill-php80": "^1.17" + "symfony/options-resolver": "^4.4.30|^5.0.11|^6.0|^7.0" }, "conflict": { - "php-http/client-common": "1.8.0", "raven/raven": "*" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.19|3.4.*", + "friendsofphp/php-cs-fixer": "^3.4", + "guzzlehttp/promises": "^1.0|^2.0", "guzzlehttp/psr7": "^1.8.4|^2.1.1", - "http-interop/http-factory-guzzle": "^1.0", "monolog/monolog": "^1.6|^2.0|^3.0", - "nikic/php-parser": "^4.10.3", - "php-http/mock-client": "^1.3", "phpbench/phpbench": "^1.0", - "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^1.3", - "phpstan/phpstan-phpunit": "^1.0", "phpunit/phpunit": "^8.5.14|^9.4", "symfony/phpunit-bridge": "^5.2|^6.0", "vimeo/psalm": "^4.17" @@ -4455,7 +4105,7 @@ ], "support": { "issues": "https://github.com/getsentry/sentry-php/issues", - "source": "https://github.com/getsentry/sentry-php/tree/3.22.0" + "source": "https://github.com/getsentry/sentry-php/tree/4.0.0" }, "funding": [ { @@ -4467,7 +4117,7 @@ "type": "custom" } ], - "time": "2023-10-23T20:34:53+00:00" + "time": "2023-11-06T10:16:08+00:00" }, { "name": "spatie/array-to-xml", @@ -5206,89 +4856,6 @@ ], "time": "2023-07-28T09:04:16+00:00" }, - { - "name": "symfony/polyfill-php80", - "version": "v1.28.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5", - "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Php80\\": "" - }, - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ion Bazan", - "email": "ion.bazan@gmail.com" - }, - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.28.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2023-01-26T09:26:14+00:00" - }, { "name": "symfony/service-contracts", "version": "v3.3.0", diff --git a/src/Factory/Writer.php b/src/Factory/Writer.php index 3a3b3cba..7c733436 100644 --- a/src/Factory/Writer.php +++ b/src/Factory/Writer.php @@ -8,14 +8,13 @@ use Kronos\Log\Formatter\Exception\TraceBuilder; use Kronos\Log\Writer\File; use Kronos\Log\Writer\LogDNA; -use Kronos\Log\Writer\Sentry; +use Kronos\Log\Writer\Sentry as SentryWriter; use Kronos\Log\Writer\Syslog; use Kronos\Log\Writer\Console; use Kronos\Log\Writer\Memory; use Kronos\Log\Writer\TriggerError; -use Sentry\ClientBuilder; +use Sentry; use Sentry\ClientInterface; -use Sentry\Options; use Sentry\SentrySdk; class Writer @@ -90,22 +89,20 @@ public function createMemoryWriter() return new Memory(); } - public function createSentryWriter(ClientInterface $client): Sentry + public function createSentryWriter(ClientInterface $client): SentryWriter { - return new Sentry($client); + return new SentryWriter($client); } public function createSentryWriterAndSentryClient( string $key, string $projectId, - array $configs = [] - ): Sentry { - $configs['dsn'] = 'https://' . $key . '@sentry.io/' . $projectId; - $options = new Options($configs); - $clientBuilder = new ClientBuilder($options); - $sentryClient = $clientBuilder->getClient(); - SentrySdk::init()->bindClient($sentryClient); - return new Sentry($sentryClient); + array $options = [] + ): SentryWriter { + $options['dsn'] = 'https://' . $key . '@sentry.io/' . $projectId; + Sentry\init($options); + $sentryClient = SentrySdk::getCurrentHub()->getClient(); + return new SentryWriter($sentryClient); } /** diff --git a/src/Writer/Sentry.php b/src/Writer/Sentry.php index 78299a7f..2b9436d7 100644 --- a/src/Writer/Sentry.php +++ b/src/Writer/Sentry.php @@ -12,17 +12,12 @@ class Sentry extends AbstractWriter { - /** - * @var ClientInterface - */ - private $sentryClient; - /** * Sentry constructor. */ - public function __construct(ClientInterface $sentryClient) - { - $this->sentryClient = $sentryClient; + public function __construct( + private readonly ?ClientInterface $sentryClient + ) { } /** @@ -48,7 +43,9 @@ private function captureMessage($level, $message, $context) $interpolatedMessage = $this->interpolate($message, $context); $sentryScope = $this->getSentryScope($level, $context); - $this->sentryClient->captureMessage($interpolatedMessage, $level, $sentryScope); + if (isset($this->sentryClient)) { + $this->sentryClient->captureMessage($interpolatedMessage, $level, $sentryScope); + } } private function captureException($level, $message, $context) @@ -61,7 +58,9 @@ private function captureException($level, $message, $context) } $sentryScope = $this->getSentryScope($level, $context); - $this->sentryClient->captureException($exception, $sentryScope); + if (isset($this->sentryClient)) { + $this->sentryClient->captureException($exception, $sentryScope); + } } protected function getSentryScope($level, $context): Scope