-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add milliseconds via microtime to the LogEvent class for latency calc…
…ulations
- Loading branch information
1 parent
658b118
commit cd9603f
Showing
2 changed files
with
16 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,16 @@ class LogEvent | |
/** | ||
* Timestamp in format RFC3339 representing when this event ocurred | ||
* | ||
* @var null|string | ||
* @var string | ||
*/ | ||
public readonly string $timestamp; | ||
|
||
/** | ||
* The time in milliseconds at time on creation for calculating latency | ||
* | ||
* @var float | ||
*/ | ||
public null|string $timestamp = null; | ||
public readonly float $milliseconds; | ||
|
||
/** | ||
* Rest method type | ||
|
@@ -90,14 +97,14 @@ class LogEvent | |
public null|string $serviceName = null; | ||
|
||
/** | ||
* The Client Id for easy trace | ||
* The Client Id for tracing | ||
* | ||
* @var null|int $clientId | ||
*/ | ||
public null|int $clientId = null; | ||
|
||
/** | ||
* The Request id for easy trace | ||
* The Request id for tracing | ||
* | ||
* @var null|int $requestId; | ||
*/ | ||
|
@@ -110,12 +117,13 @@ class LogEvent | |
* | ||
* @param null|string $startTime (Optional) Parameter to calculate the latency | ||
*/ | ||
public function __construct(null|string $startTime = null) | ||
public function __construct(null|float $startTime = null) | ||
Check failure on line 120 in src/Logging/LogEvent.php GitHub Actions / PHPStan Static Analysis / PHPStan Static Analysis
|
||
{ | ||
$this->timestamp = date(DATE_RFC3339); | ||
$this->milliseconds = round(microtime(true) * 1000); | ||
|
||
if ($startTime) { | ||
$this->latency = (int) strtotime($this->timestamp) - strtotime($startTime); | ||
$this->latency = (int) $this->milliseconds - $startTime; | ||
} | ||
} | ||
} |