Skip to content

Commit

Permalink
Switch from seconds to milliseconds for timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrHeinz committed Mar 20, 2024
1 parent 0d28cb0 commit 4d16dc5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
24 changes: 12 additions & 12 deletions src/Monolog/LogtailClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
class LogtailClient {
const URL = "https://in.logtail.com";

const DEFAULT_CONNECTION_TIMEOUT_SECONDS = 5;
const DEFAULT_TIMEOUT_SECONDS = 5;
const DEFAULT_CONNECTION_TIMEOUT_MILLISECONDS = 5000;
const DEFAULT_TIMEOUT_MILLISECONDS = 5000;

/**
* @var string $sourceToken
Expand All @@ -36,30 +36,30 @@ class LogtailClient {
private $handle = NULL;

/**
* @var int $connectionTimeout
* @var int $connectionTimeoutMs
*/
private $connectionTimeout;
private $connectionTimeoutMs;

/**
* @var int $timeout
* @var int $timeoutMs
*/
private $timeout;
private $timeoutMs;


public function __construct(
$sourceToken,
$endpoint = self::URL,
$connectionTimeout = self::DEFAULT_CONNECTION_TIMEOUT_SECONDS,
$timeout = self::DEFAULT_TIMEOUT_SECONDS
$connectionTimeoutMs = self::DEFAULT_CONNECTION_TIMEOUT_MILLISECONDS,
$timeoutMs = self::DEFAULT_TIMEOUT_MILLISECONDS
) {
if (!\extension_loaded('curl')) {
throw new \LogicException('The curl extension is needed to use the LogtailHandler');
}

$this->sourceToken = $sourceToken;
$this->endpoint = $endpoint;
$this->connectionTimeout = $connectionTimeout;
$this->timeout = $timeout;
$this->connectionTimeoutMs = $connectionTimeoutMs;
$this->timeoutMs = $timeoutMs;
}

public function send($data) {
Expand Down Expand Up @@ -87,8 +87,8 @@ private function initCurlHandle() {
\curl_setopt($this->handle, CURLOPT_URL, $this->endpoint);
\curl_setopt($this->handle, CURLOPT_POST, true);
\curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers);
\curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT, $this->connectionTimeout);
\curl_setopt($this->handle, CURLOPT_TIMEOUT, $this->timeout);
\curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT_MS, $this->connectionTimeoutMs);
\curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, $this->timeoutMs);

}
}
22 changes: 11 additions & 11 deletions src/Monolog/LogtailHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
class LogtailHandler extends BufferHandler
{
/**
* @param string $sourceToken Logtail source token
* @param int|string $level The minimum logging level at which this handler will be triggered
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
* @param $endpoint Logtail ingesting endpoint
* @param int $bufferLimit How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
* @param bool $flushOnOverflow If true, the buffer is flushed when the max size has been reached, by default oldest entries are discarded
* @param int $connectionTimeout The maximum time in seconds that you allow the connection phase to the server to take
* @param int $timeout The maximum time in seconds that you allow a transfer operation to take
* @param string $sourceToken Logtail source token
* @param int|string $level The minimum logging level at which this handler will be triggered
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
* @param $endpoint Logtail ingesting endpoint
* @param int $bufferLimit How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
* @param bool $flushOnOverflow If true, the buffer is flushed when the max size has been reached, by default oldest entries are discarded
* @param int $connectionTimeoutMs The maximum time in milliseconds that you allow the connection phase to the server to take
* @param int $timeoutMs The maximum time in milliseconds that you allow a transfer operation to take
*/
public function __construct(
$sourceToken,
Expand All @@ -36,10 +36,10 @@ public function __construct(
$endpoint = LogtailClient::URL,
$bufferLimit = 0,
$flushOnOverflow = false,
$connectionTimeout = LogtailClient::DEFAULT_CONNECTION_TIMEOUT_SECONDS,
$timeout = LogtailClient::DEFAULT_TIMEOUT_SECONDS
$connectionTimeoutMs = LogtailClient::DEFAULT_CONNECTION_TIMEOUT_MILLISECONDS,
$timeoutMs = LogtailClient::DEFAULT_TIMEOUT_MILLISECONDS
) {
parent::__construct(new SynchronousLogtailHandler($sourceToken, $level, $bubble, $endpoint, $connectionTimeout, $timeout), $bufferLimit, $level, $bubble, $flushOnOverflow);
parent::__construct(new SynchronousLogtailHandler($sourceToken, $level, $bubble, $endpoint, $connectionTimeoutMs, $timeoutMs), $bufferLimit, $level, $bubble, $flushOnOverflow);
}

}
10 changes: 5 additions & 5 deletions src/Monolog/SynchronousLogtailHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ class SynchronousLogtailHandler extends \Monolog\Handler\AbstractProcessingHandl
* @param int $level
* @param bool $bubble
* @param string $endpoint
* @param int $connectionTimeout
* @param int $timeout
* @param int $connectionTimeoutMs
* @param int $timeoutMs
*/
public function __construct(
$sourceToken,
$level = \Monolog\Logger::DEBUG,
$bubble = true,
$endpoint = LogtailClient::URL,
$connectionTimeout = LogtailClient::DEFAULT_CONNECTION_TIMEOUT_SECONDS,
$timeout = LogtailClient::DEFAULT_TIMEOUT_SECONDS
$connectionTimeoutMs = LogtailClient::DEFAULT_CONNECTION_TIMEOUT_MILLISECONDS,
$timeoutMs = LogtailClient::DEFAULT_TIMEOUT_MILLISECONDS
) {
parent::__construct($level, $bubble);

$this->client = new LogtailClient($sourceToken, $endpoint, $connectionTimeout, $timeout);
$this->client = new LogtailClient($sourceToken, $endpoint, $connectionTimeoutMs, $timeoutMs);

$this->pushProcessor(new \Monolog\Processor\IntrospectionProcessor($level, ['Logtail\\']));
$this->pushProcessor(new \Monolog\Processor\WebProcessor);
Expand Down

0 comments on commit 4d16dc5

Please sign in to comment.