Skip to content

Commit 6afef54

Browse files
committed
fix: Add statements to failed events if available
1 parent 00972bd commit 6afef54

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

src/Collector/Neo4jDataCollector.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
5050
'status' => 'failure',
5151
'time' => $x['time'],
5252
'timestamp' => $x['timestamp'],
53+
'result' => [
54+
'statement' => $x['statement']?->toArray(),
55+
],
5356
'exception' => [
5457
'code' => $x['exception']->getErrors()[0]->getCode(),
5558
'message' => $x['exception']->getErrors()[0]->getMessage(),

src/Event/FailureEvent.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Neo4j\Neo4jBundle\Event;
66

7+
use Laudis\Neo4j\Databags\Statement;
78
use Laudis\Neo4j\Exception\Neo4jException;
89
use Symfony\Contracts\EventDispatcher\Event;
910

@@ -15,13 +16,19 @@ class FailureEvent extends Event
1516

1617
public function __construct(
1718
private readonly ?string $alias,
19+
private readonly ?Statement $statement,
1820
private readonly Neo4jException $exception,
1921
private readonly \DateTimeInterface $time,
2022
private readonly ?string $scheme,
2123
private readonly ?string $transactionId,
2224
) {
2325
}
2426

27+
public function getStatement(): ?Statement
28+
{
29+
return $this->statement;
30+
}
31+
2532
public function getException(): Neo4jException
2633
{
2734
return $this->exception;

src/EventHandler.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ public function handleQuery(callable $runHandler, Statement $statement, string $
5252

5353
$runHandler = static fn (): mixed => $runHandler($statement);
5454
$result = $this->handleAction(
55-
$runHandler,
56-
$alias,
57-
$scheme,
58-
$stopwatchName,
59-
$transactionId
55+
runHandler: $runHandler,
56+
alias: $alias,
57+
scheme: $scheme,
58+
stopwatchName: $stopwatchName,
59+
transactionId: $transactionId,
60+
statement: $statement
6061
);
6162

6263
$event = new PostRunEvent(
@@ -95,7 +96,7 @@ public function handleTransactionAction(
9596
$this->dispatchTransactionEvent($alias, $scheme, $transactionId);
9697
}
9798

98-
$result = $this->handleAction($runHandler, $alias, $scheme, $stopWatchName, $transactionId);
99+
$result = $this->handleAction(runHandler: $runHandler, alias: $alias, scheme: $scheme, stopwatchName: $stopWatchName, transactionId: $transactionId, statement: null);
99100

100101
if (TransactionState::COMMITTED === $nextTransactionState
101102
|| TransactionState::ROLLED_BACK === $nextTransactionState) {
@@ -112,7 +113,7 @@ public function handleTransactionAction(
112113
*
113114
* @return T
114115
*/
115-
private function handleAction(callable $runHandler, string $alias, string $scheme, string $stopwatchName, ?string $transactionId): mixed
116+
private function handleAction(callable $runHandler, string $alias, string $scheme, string $stopwatchName, ?string $transactionId, ?Statement $statement): mixed
116117
{
117118
try {
118119
$this->stopwatch?->start($stopwatchName, 'database');
@@ -124,6 +125,7 @@ private function handleAction(callable $runHandler, string $alias, string $schem
124125
$this->stopwatch?->stop($stopwatchName);
125126
$event = new FailureEvent(
126127
alias: $alias,
128+
statement: $statement,
127129
exception: $e,
128130
time: new \DateTimeImmutable('now'),
129131
scheme: $scheme,

src/EventListener/Neo4jProfileListener.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Neo4j\Neo4jBundle\EventListener;
66

77
use Laudis\Neo4j\Databags\ResultSummary;
8+
use Laudis\Neo4j\Databags\Statement;
89
use Laudis\Neo4j\Exception\Neo4jException;
910
use Neo4j\Neo4jBundle\Event\FailureEvent;
1011
use Neo4j\Neo4jBundle\Event\PostRunEvent;
@@ -27,6 +28,7 @@ final class Neo4jProfileListener implements EventSubscriberInterface, ResetInter
2728
/**
2829
* @var list<array{
2930
* exception: Neo4jException,
31+
* statement: ?Statement,
3032
* alias: string|null,
3133
* time: string,
3234
* timestamp: int
@@ -71,6 +73,7 @@ public function onFailure(FailureEvent $event): void
7173
$time = $event->getTime();
7274
$this->profiledFailures[] = [
7375
'exception' => $event->getException(),
76+
'statement' => $event->getStatement(),
7477
'alias' => $event->getAlias(),
7578
'time' => $time->format('Y-m-d H:i:s'),
7679
'timestamp' => $time->getTimestamp(),
@@ -86,6 +89,7 @@ public function getProfiledSummaries(): array
8689
/**
8790
* @return list<array{
8891
* exception: Neo4jException,
92+
* statement: ?Statement,
8993
* alias: string|null,
9094
* time: string,
9195
* timestamp: int

0 commit comments

Comments
 (0)