Skip to content

Commit

Permalink
Improve log integration for elasticearch
Browse files Browse the repository at this point in the history
Not all queries have 'took'. Account for that and use defaults values.

Fixes #989
  • Loading branch information
markstory committed Jan 25, 2024
1 parent cdb3138 commit 860b504
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Database/Log/DebugLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,16 @@ public function log($level, string|Stringable $message, array $context = []): vo

// This specific to Elastic Search
if (!$query instanceof LoggedQuery && isset($context['request']) && isset($context['response'])) {
$this->_totalTime += $context['response']['took'];
$took = $context['response']['took'] ?? 0;
$this->_totalTime += $took;

Check warning on line 139 in src/Database/Log/DebugLog.php

View check run for this annotation

Codecov / codecov/patch

src/Database/Log/DebugLog.php#L138-L139

Added lines #L138 - L139 were not covered by tests

$this->_queries[] = [
'query' => json_encode([
'method' => $context['request']['method'],
'path' => $context['request']['path'],
'data' => $context['request']['data'],
], JSON_PRETTY_PRINT),
'took' => $context['response']['took'] ?: 0,
'took' => $took ?: 0,

Check failure on line 147 in src/Database/Log/DebugLog.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

RiskyTruthyFalsyComparison

src/Database/Log/DebugLog.php:147:27: RiskyTruthyFalsyComparison: Operand of type 0|mixed contains type mixed, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check warning on line 147 in src/Database/Log/DebugLog.php

View check run for this annotation

Codecov / codecov/patch

src/Database/Log/DebugLog.php#L147

Added line #L147 was not covered by tests
'rows' => $context['response']['hits']['total']['value'] ?? $context['response']['hits']['total'] ?? 0,
];

Expand Down

0 comments on commit 860b504

Please sign in to comment.