Skip to content

Commit 381c24b

Browse files
author
drewblin
committed
Add limit for sql length
1 parent 5ec07d5 commit 381c24b

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

src/Decorator/JaegerConnectionDecorator.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ class JaegerConnectionDecorator extends AbstractConnectionDecorator
2020
{
2121
private $tracer;
2222

23-
public function __construct(Connection $connection, TracerInterface $tracer)
23+
/**
24+
* @var int|null
25+
*/
26+
private $maxSqlLength;
27+
28+
public function __construct(Connection $connection, TracerInterface $tracer, ?int $maxSqlLength = null)
2429
{
2530
$this->tracer = $tracer;
31+
$this->maxSqlLength = $maxSqlLength;
2632
parent::__construct($connection);
2733
}
2834

@@ -215,6 +221,10 @@ public function rollBack()
215221

216222
private function cutLongSql(string $string): string
217223
{
218-
return substr($string, 0, 200);
224+
if (null === $this->maxSqlLength) {
225+
return $string;
226+
}
227+
228+
return substr($string, 0, $this->maxSqlLength);
219229
}
220230
}

src/Wrapper/JaegerConnectionWrapper.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,25 @@ class JaegerConnectionWrapper extends Connection
2323
*/
2424
private $tracer;
2525

26+
/**
27+
* @var int|null
28+
*/
29+
private $maxSqlLength;
30+
2631
public function setTracer(TracerInterface $tracer)
2732
{
2833
$this->tracer = $tracer;
2934

3035
return $this;
3136
}
3237

38+
public function setMaxSqlLength(?int $maxSqlLength)
39+
{
40+
$this->maxSqlLength = $maxSqlLength;
41+
42+
return $this;
43+
}
44+
3345
public function connect()
3446
{
3547
if ($this->isConnected()) {
@@ -85,6 +97,7 @@ private function wrappedPrepare($sql)
8597

8698
$stmt->setFetchMode($this->defaultFetchMode);
8799
$stmt->setTracer($this->tracer);
100+
$stmt->setMaxSqlLength($this->maxSqlLength);
88101

89102
return $stmt;
90103
}
@@ -235,6 +248,10 @@ public function rollBack()
235248

236249
private function cutLongSql(string $string): string
237250
{
238-
return substr($string, 0, 200);
251+
if (null === $this->maxSqlLength) {
252+
return $string;
253+
}
254+
255+
return substr($string, 0, $this->maxSqlLength);
239256
}
240257
}

src/Wrapper/JaegerStatementWrapper.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,25 @@ class JaegerStatementWrapper extends Statement
1616
*/
1717
private $tracer;
1818

19+
/**
20+
* @var int|null
21+
*/
22+
private $maxSqlLength;
23+
1924
public function setTracer(TracerInterface $tracer)
2025
{
2126
$this->tracer = $tracer;
2227

2328
return $this;
2429
}
2530

31+
public function setMaxSqlLength(?int $maxSqlLength)
32+
{
33+
$this->maxSqlLength = $maxSqlLength;
34+
35+
return $this;
36+
}
37+
2638
public function execute($params = null)
2739
{
2840
$span = $this->tracer
@@ -43,6 +55,10 @@ public function execute($params = null)
4355

4456
private function cutLongSql(string $string): string
4557
{
46-
return substr($string, 0, 200);
58+
if (null === $this->maxSqlLength) {
59+
return $string;
60+
}
61+
62+
return substr($string, 0, $this->maxSqlLength);
4763
}
4864
}

0 commit comments

Comments
 (0)