Skip to content

Commit c5c9d7c

Browse files
committed
Addd tags, jaeger connection decorator
1 parent 5187538 commit c5c9d7c

File tree

3 files changed

+476
-8
lines changed

3 files changed

+476
-8
lines changed

src/Decorator/AbstractConnectionDecorator.php

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
namespace Doctrine\DBAL\Jaeger\Decorator;
55

6+
use Closure;
7+
use Doctrine\DBAL\Cache\QueryCacheProfile;
68
use Doctrine\DBAL\Connection;
79
use Doctrine\DBAL\ParameterType;
10+
use Doctrine\DBAL\Query\QueryBuilder;
811

912
abstract class AbstractConnectionDecorator extends Connection
1013
{
@@ -64,4 +67,244 @@ public function errorInfo()
6467
{
6568
return $this->connection->errorInfo();
6669
}
70+
71+
public function getParams()
72+
{
73+
return $this->connection->getParams();
74+
}
75+
76+
public function getDatabase()
77+
{
78+
return $this->connection->getDatabase();
79+
}
80+
81+
public function getHost()
82+
{
83+
return $this->connection->getHost();
84+
}
85+
86+
public function getPort()
87+
{
88+
return $this->connection->getPort();
89+
}
90+
91+
public function getUsername()
92+
{
93+
return $this->connection->getUsername();
94+
}
95+
96+
public function getPassword()
97+
{
98+
return $this->connection->getPassword();
99+
}
100+
101+
public function getDriver()
102+
{
103+
return $this->connection->getDriver();
104+
}
105+
106+
public function getConfiguration()
107+
{
108+
return $this->connection->getConfiguration();
109+
}
110+
111+
public function getEventManager()
112+
{
113+
return $this->connection->getEventManager();
114+
}
115+
116+
public function getDatabasePlatform()
117+
{
118+
return $this->connection->getDatabasePlatform();
119+
}
120+
121+
public function getExpressionBuilder()
122+
{
123+
return $this->connection->getExpressionBuilder();
124+
}
125+
126+
public function connect()
127+
{
128+
return $this->connection->connect();
129+
}
130+
131+
public function isAutoCommit()
132+
{
133+
return $this->connection->isAutoCommit();
134+
}
135+
136+
public function setAutoCommit($autoCommit)
137+
{
138+
$this->connection->setAutoCommit($autoCommit);
139+
}
140+
141+
public function setFetchMode($fetchMode)
142+
{
143+
$this->connection->setFetchMode($fetchMode);
144+
}
145+
146+
public function fetchAssoc($statement, array $params = [], array $types = [])
147+
{
148+
return $this->connection->fetchAssoc($statement, $params, $types);
149+
}
150+
151+
public function fetchArray($statement, array $params = [], array $types = [])
152+
{
153+
return $this->connection->fetchArray($statement, $params, $types);
154+
}
155+
156+
public function fetchColumn($statement, array $params = [], $column = 0, array $types = [])
157+
{
158+
return $this->connection->fetchColumn($statement, $params, $column, $types);
159+
}
160+
161+
public function isConnected()
162+
{
163+
return $this->connection->isConnected();
164+
}
165+
166+
public function isTransactionActive()
167+
{
168+
return $this->connection->isTransactionActive();
169+
}
170+
171+
public function delete($tableExpression, array $identifier, array $types = [])
172+
{
173+
return $this->connection->delete($tableExpression, $identifier, $types);
174+
}
175+
176+
public function close()
177+
{
178+
$this->connection->close();
179+
}
180+
181+
public function setTransactionIsolation($level)
182+
{
183+
$this->connection->setTransactionIsolation($level);
184+
}
185+
186+
public function getTransactionIsolation()
187+
{
188+
return $this->connection->getTransactionIsolation();
189+
}
190+
191+
public function update($tableExpression, array $data, array $identifier, array $types = [])
192+
{
193+
return $this->connection->update($tableExpression, $data, $identifier, $types);
194+
}
195+
196+
public function insert($tableExpression, array $data, array $types = [])
197+
{
198+
return $this->connection->insert($tableExpression, $data, $types);
199+
}
200+
201+
public function quoteIdentifier($str)
202+
{
203+
return $this->connection->quoteIdentifier($str);
204+
}
205+
206+
public function fetchAll($sql, array $params = [], $types = [])
207+
{
208+
return $this->connection->fetchAll($sql, $params, $types);
209+
}
210+
211+
public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null)
212+
{
213+
return $this->connection->executeQuery($query, $params, $types, $qcp);
214+
}
215+
216+
public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qcp)
217+
{
218+
return $this->connection->executeCacheQuery($query, $params, $types, $qcp);
219+
}
220+
221+
public function project($query, array $params, Closure $function)
222+
{
223+
return $this->connection->project($query, $params, $function);
224+
}
225+
226+
public function executeUpdate($query, array $params = [], array $types = [])
227+
{
228+
return $this->connection->executeUpdate($query, $params, $types);
229+
}
230+
231+
public function getTransactionNestingLevel()
232+
{
233+
return $this->connection->getTransactionNestingLevel();
234+
}
235+
236+
public function transactional(Closure $func)
237+
{
238+
return $this->connection->transactional($func);
239+
}
240+
241+
public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints)
242+
{
243+
$this->connection->setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints);
244+
}
245+
246+
public function getNestTransactionsWithSavepoints()
247+
{
248+
return $this->connection->getNestTransactionsWithSavepoints();
249+
}
250+
251+
public function createSavepoint($savepoint)
252+
{
253+
$this->connection->createSavepoint($savepoint);
254+
}
255+
256+
public function releaseSavepoint($savepoint)
257+
{
258+
$this->connection->releaseSavepoint($savepoint);
259+
}
260+
261+
public function rollbackSavepoint($savepoint)
262+
{
263+
$this->connection->rollbackSavepoint($savepoint);
264+
}
265+
266+
public function getWrappedConnection()
267+
{
268+
return $this->connection->getWrappedConnection();
269+
}
270+
271+
public function getSchemaManager()
272+
{
273+
return $this->connection->getSchemaManager();
274+
}
275+
276+
public function setRollbackOnly()
277+
{
278+
$this->connection->setRollbackOnly();
279+
}
280+
281+
public function isRollbackOnly()
282+
{
283+
return $this->connection->isRollbackOnly();
284+
}
285+
286+
public function convertToDatabaseValue($value, $type)
287+
{
288+
return $this->connection->convertToDatabaseValue($value, $type);
289+
}
290+
291+
public function convertToPHPValue($value, $type)
292+
{
293+
return $this->connection->convertToPHPValue($value, $type);
294+
}
295+
296+
public function resolveParams(array $params, array $types)
297+
{
298+
return $this->connection->resolveParams($params, $types);
299+
}
300+
301+
public function createQueryBuilder()
302+
{
303+
return new QueryBuilder($this);
304+
}
305+
306+
public function ping()
307+
{
308+
return $this->connection->ping();
309+
}
67310
}

src/Decorator/JaegerConnectionDecorator.php

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Doctrine\DBAL\Jaeger\Decorator;
55

6+
use Doctrine\DBAL\Cache\QueryCacheProfile;
67
use Doctrine\DBAL\Connection;
78
use Doctrine\DBAL\Jaeger\Tag\DbalErrorCodeTag;
89
use Doctrine\DBAL\Jaeger\Tag\DbalRowNumberTag;
@@ -15,16 +16,13 @@
1516

1617
class JaegerConnectionDecorator extends AbstractConnectionDecorator
1718
{
18-
/**
19-
* @var TracerInterface
20-
*/
2119
private $tracer;
2220

23-
public function __construct(Connection $connection, TracerInterface $tracer)
24-
{
25-
$this->tracer = $tracer;
26-
parent::__construct($connection);
27-
}
21+
public function __construct(Connection $connection, TracerInterface $tracer)
22+
{
23+
$this->tracer = $tracer;
24+
parent::__construct($connection);
25+
}
2826

2927
public function prepare($prepareString)
3028
{
@@ -45,6 +43,46 @@ public function prepare($prepareString)
4543
}
4644
}
4745

46+
public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null)
47+
{
48+
$span = $this->tracer
49+
->start('dbal.execute')
50+
->addTag(new DbInstanceTag($this->getDatabase()))
51+
->addTag(new DbUser($this->getUsername()))
52+
->addTag(new DbType('sql'))
53+
->addTag(new DbStatementTag($query));
54+
try {
55+
return parent::executeQuery($query, $params, $types, $qcp);
56+
} catch (\Exception $e) {
57+
$span->addTag(new DbalErrorCodeTag($e->getCode()))
58+
->addTag(new ErrorTag());
59+
throw $e;
60+
} finally {
61+
$this->tracer->finish($span);
62+
}
63+
}
64+
65+
public function executeUpdate($query, array $params = [], array $types = [])
66+
{
67+
$span = $this->tracer
68+
->start('dbal.execute')
69+
->addTag(new DbInstanceTag($this->getDatabase()))
70+
->addTag(new DbUser($this->getUsername()))
71+
->addTag(new DbType('sql'))
72+
->addTag(new DbStatementTag($query));
73+
try {
74+
return parent::executeUpdate($query, $params, $types);
75+
} catch (\Exception $e) {
76+
$span->addTag(new DbalErrorCodeTag($e->getCode()))
77+
->addTag(new ErrorTag());
78+
throw $e;
79+
} finally {
80+
$this->tracer->finish($span);
81+
}
82+
}
83+
84+
85+
4886
public function query()
4987
{
5088
$span = $this->tracer

0 commit comments

Comments
 (0)