diff --git a/src/Logger/Adapter/AppSignal.php b/src/Logger/Adapter/AppSignal.php index dcb3632..94704b4 100644 --- a/src/Logger/Adapter/AppSignal.php +++ b/src/Logger/Adapter/AppSignal.php @@ -11,19 +11,37 @@ class AppSignal extends Adapter { + private const DEFAULT_TIMEOUT = 5; + + private const DEFAULT_CONNECT_TIMEOUT = 1; + /** * @var string (required, can be found in Appsignal -> Project -> App Settings -> Push & deploy -> Push Key) */ protected string $apiKey; + /** + * Timeout (seconds) for the complete request. + */ + protected int $timeout; + + /** + * Timeout (seconds) for establishing the connection. + */ + protected int $connectTimeout; + /** * AppSignal constructor. * * @param string $key + * @param int $timeout + * @param int $connectTimeout */ - public function __construct(string $key) + public function __construct(string $key, int $timeout = self::DEFAULT_TIMEOUT, int $connectTimeout = self::DEFAULT_CONNECT_TIMEOUT) { $this->apiKey = $key; + $this->timeout = $timeout > 0 ? $timeout : self::DEFAULT_TIMEOUT; + $this->connectTimeout = $connectTimeout > 0 ? $connectTimeout : self::DEFAULT_CONNECT_TIMEOUT; } /** @@ -114,6 +132,8 @@ public function push(Log $log): int CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => \json_encode($requestBody), + CURLOPT_TIMEOUT => $this->timeout, + CURLOPT_CONNECTTIMEOUT => $this->connectTimeout, CURLOPT_HEADEROPT => \CURLHEADER_UNIFIED, CURLOPT_HTTPHEADER => ['Content-Type: application/json'], ]; diff --git a/src/Logger/Adapter/LogOwl.php b/src/Logger/Adapter/LogOwl.php index ef84be1..7036cd3 100644 --- a/src/Logger/Adapter/LogOwl.php +++ b/src/Logger/Adapter/LogOwl.php @@ -12,6 +12,10 @@ class LogOwl extends Adapter { + private const DEFAULT_TIMEOUT = 5; + + private const DEFAULT_CONNECT_TIMEOUT = 1; + /** * @var string (required, can be found in LogOwl -> All Services -> Project -> Ticket -> Service Ticket) */ @@ -23,13 +27,25 @@ class LogOwl extends Adapter */ protected string $logOwlHost; + /** + * Timeout (seconds) for the complete request. + */ + protected int $timeout; + + /** + * Timeout (seconds) for establishing the connection. + */ + protected int $connectTimeout; + /** * LogOwl constructor. * * @param string $ticket * @param string $host + * @param int $timeout + * @param int $connectTimeout */ - public function __construct(string $ticket, string $host = '') + public function __construct(string $ticket, string $host = '', int $timeout = self::DEFAULT_TIMEOUT, int $connectTimeout = self::DEFAULT_CONNECT_TIMEOUT) { if (empty($host)) { $host = 'https://api.logowl.io/logging/'; @@ -37,6 +53,8 @@ public function __construct(string $ticket, string $host = '') $this->ticket = $ticket; $this->logOwlHost = $host; + $this->timeout = $timeout > 0 ? $timeout : self::DEFAULT_TIMEOUT; + $this->connectTimeout = $connectTimeout > 0 ? $connectTimeout : self::DEFAULT_CONNECT_TIMEOUT; } /** diff --git a/src/Logger/Adapter/Raygun.php b/src/Logger/Adapter/Raygun.php index 311da6d..e51e22d 100644 --- a/src/Logger/Adapter/Raygun.php +++ b/src/Logger/Adapter/Raygun.php @@ -11,19 +11,37 @@ class Raygun extends Adapter { + private const DEFAULT_TIMEOUT = 5; + + private const DEFAULT_CONNECT_TIMEOUT = 1; + /** * @var string (required, can be found in Appsignal -> Project -> App Settings -> Push & deploy -> Push Key) */ protected string $apiKey; + /** + * Timeout (seconds) for the complete request. + */ + protected int $timeout; + + /** + * Timeout (seconds) for establishing the connection. + */ + protected int $connectTimeout; + /** * Raygun constructor. * * @param string $key + * @param int $timeout + * @param int $connectTimeout */ - public function __construct(string $key) + public function __construct(string $key, int $timeout = self::DEFAULT_TIMEOUT, int $connectTimeout = self::DEFAULT_CONNECT_TIMEOUT) { $this->apiKey = $key; + $this->timeout = $timeout > 0 ? $timeout : self::DEFAULT_TIMEOUT; + $this->connectTimeout = $connectTimeout > 0 ? $connectTimeout : self::DEFAULT_CONNECT_TIMEOUT; } /** @@ -99,6 +117,8 @@ public function push(Log $log): int CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => \json_encode($requestBody), + CURLOPT_TIMEOUT => $this->timeout, + CURLOPT_CONNECTTIMEOUT => $this->connectTimeout, CURLOPT_HEADEROPT => \CURLHEADER_UNIFIED, CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'X-ApiKey: '.$this->apiKey], ]; diff --git a/src/Logger/Adapter/Sentry.php b/src/Logger/Adapter/Sentry.php index e61b73e..fa95a00 100644 --- a/src/Logger/Adapter/Sentry.php +++ b/src/Logger/Adapter/Sentry.php @@ -12,6 +12,10 @@ class Sentry extends Adapter { + private const DEFAULT_TIMEOUT = 5; + + private const DEFAULT_CONNECT_TIMEOUT = 1; + /** * @var string (required, this part of Sentry DSN: 'https://{{THIS_PART}}@blabla.ingest.sentry.io/blabla') */ @@ -28,14 +32,26 @@ class Sentry extends Adapter */ protected string $sentryHost; + /** + * Timeout (seconds) for the complete request. + */ + protected int $timeout; + + /** + * Timeout (seconds) for establishing the connection. + */ + protected int $connectTimeout; + /** * Sentry constructor. * * @param string $projectId * @param string $key * @param string $host + * @param int $timeout + * @param int $connectTimeout */ - public function __construct(string $projectId, string $key, string $host = '') + public function __construct(string $projectId, string $key, string $host = '', int $timeout = self::DEFAULT_TIMEOUT, int $connectTimeout = self::DEFAULT_CONNECT_TIMEOUT) { if (empty($host)) { $host = 'https://sentry.io'; @@ -44,6 +60,8 @@ public function __construct(string $projectId, string $key, string $host = '') $this->sentryHost = $host; $this->sentryKey = $key; $this->projectId = $projectId; + $this->timeout = $timeout > 0 ? $timeout : self::DEFAULT_TIMEOUT; + $this->connectTimeout = $connectTimeout > 0 ? $connectTimeout : self::DEFAULT_CONNECT_TIMEOUT; } /** @@ -141,6 +159,8 @@ public function push(Log $log): int CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => \json_encode($requestBody), + CURLOPT_TIMEOUT => $this->timeout, + CURLOPT_CONNECTTIMEOUT => $this->connectTimeout, CURLOPT_HEADEROPT => \CURLHEADER_UNIFIED, CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'X-Sentry-Auth: Sentry sentry_version=7, sentry_key='.$this->sentryKey.', sentry_client=utopia-logger/'.Logger::LIBRARY_VERSION], ];