44
55namespace Neo4j \Neo4jBundle \Collector ;
66
7+ use GraphAware \Bolt \Result \Result ;
78use GraphAware \Common \Cypher \StatementInterface ;
89use GraphAware \Common \Result \StatementResult as StatementResultInterface ;
910use GraphAware \Common \Result \StatementStatisticsInterface ;
11+ use GraphAware \Neo4j \Client \Exception \Neo4jExceptionInterface ;
1012
1113/**
1214 * @author Xavier Coureau <[email protected] > @@ -37,6 +39,7 @@ public function record(StatementInterface $statement)
3739 $ statementParams = json_encode ($ statement ->parameters ());
3840 $ tag = $ statement ->getTag () ?: -1 ;
3941
42+ // Make sure we do not record the same statement twice
4043 if (isset ($ this ->statementsHash [$ statementText ][$ statementParams ][$ tag ])) {
4144 return ;
4245 }
@@ -59,6 +62,11 @@ public function record(StatementInterface $statement)
5962 */
6063 public function finish (StatementResultInterface $ statementResult )
6164 {
65+ $ scheme = 'Http ' ;
66+ if ($ statementResult instanceof Result) {
67+ $ scheme = 'Bolt ' ;
68+ }
69+
6270 $ statement = $ statementResult ->statement ();
6371 $ statementText = $ statement ->text ();
6472 $ statementParams = $ statement ->parameters ();
@@ -77,6 +85,22 @@ public function finish(StatementResultInterface $statementResult)
7785 'end_time ' => microtime (true ) * 1000 ,
7886 'nb_results ' => $ statementResult ->size (),
7987 'statistics ' => $ this ->statisticsToArray ($ statementResult ->summarize ()->updateStatistics ()),
88+ 'scheme ' => $ scheme ,
89+ 'success ' => true ,
90+ ]);
91+ }
92+
93+ /**
94+ * @param Neo4jExceptionInterface $exception
95+ */
96+ public function logException (Neo4jExceptionInterface $ exception )
97+ {
98+ $ idx = $ this ->nbQueries - 1 ;
99+ $ this ->statements [$ idx ] = array_merge ($ this ->statements [$ idx ], [
100+ 'end_time ' => microtime (true ) * 1000 ,
101+ 'exceptionCode ' => method_exists ($ exception , 'classification ' ) ? $ exception ->classification () : '' ,
102+ 'exceptionMessage ' => method_exists ($ exception , 'getMessage ' ) ? $ exception ->getMessage () : '' ,
103+ 'success ' => false ,
80104 ]);
81105 }
82106
0 commit comments