@@ -23,13 +23,25 @@ class JaegerConnectionWrapper extends Connection
2323 */
2424 private $ tracer ;
2525
26+ /**
27+ * @var int|null
28+ */
29+ private $ maxSqlLength = null ;
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 ()) {
@@ -62,7 +74,7 @@ public function prepare($prepareString)
6274 ->addTag (new DbUser ($ this ->getUsername ()))
6375 ->addTag (new DbType ($ this ->getDatabasePlatform ()->getName ()))
6476 ->addTag (new DbalAutoCommitTag ($ this ->isAutoCommit ()))
65- ->addTag (new DbStatementTag ($ prepareString ))
77+ ->addTag (new DbStatementTag ($ this -> cutLongSql ( $ prepareString) ))
6678 ->addTag (new DbalNestingLevelTag ($ this ->getTransactionNestingLevel ()));
6779 try {
6880 return $ this ->wrappedPrepare ($ prepareString );
@@ -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 }
@@ -97,7 +110,7 @@ public function executeQuery($query, array $params = [], $types = [], QueryCache
97110 ->addTag (new DbUser ($ this ->getUsername ()))
98111 ->addTag (new DbType ($ this ->getDatabasePlatform ()->getName ()))
99112 ->addTag (new DbalAutoCommitTag ($ this ->isAutoCommit ()))
100- ->addTag (new DbStatementTag ($ query ))
113+ ->addTag (new DbStatementTag ($ this -> cutLongSql ( $ query) ))
101114 ->addTag (new DbalNestingLevelTag ($ this ->getTransactionNestingLevel ()));
102115 try {
103116 return parent ::executeQuery ($ query , $ params , $ types , $ qcp );
@@ -118,7 +131,7 @@ public function executeUpdate($query, array $params = [], array $types = [])
118131 ->addTag (new DbUser ($ this ->getUsername ()))
119132 ->addTag (new DbType ($ this ->getDatabasePlatform ()->getName ()))
120133 ->addTag (new DbalAutoCommitTag ($ this ->isAutoCommit ()))
121- ->addTag (new DbStatementTag ($ query ))
134+ ->addTag (new DbStatementTag ($ this -> cutLongSql ( $ query) ))
122135 ->addTag (new DbalNestingLevelTag ($ this ->getTransactionNestingLevel ()));
123136 try {
124137 return parent ::executeUpdate ($ query , $ params , $ types );
@@ -136,7 +149,7 @@ public function query()
136149 $ args = func_get_args ();
137150 $ span = $ this ->tracer
138151 ->start ('dbal.query ' )
139- ->addTag (new DbStatementTag ($ args [0 ]))
152+ ->addTag (new DbStatementTag ($ this -> cutLongSql ( $ args [0 ]) ))
140153 ->addTag (new DbInstanceTag ($ this ->getDatabase ()))
141154 ->addTag (new DbUser ($ this ->getUsername ()))
142155 ->addTag (new DbType ($ this ->getDatabasePlatform ()->getName ()))
@@ -232,4 +245,13 @@ public function rollBack()
232245 $ this ->tracer ->finish ($ span ->addTag (new DbalNestingLevelTag ($ this ->getTransactionNestingLevel ())));
233246 }
234247 }
248+
249+ private function cutLongSql (string $ string ): string
250+ {
251+ if (null === $ this ->maxSqlLength ) {
252+ return $ string ;
253+ }
254+
255+ return substr ($ string , 0 , $ this ->maxSqlLength );
256+ }
235257}
0 commit comments