pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/kosedogukan/dd-trace-java/commit/d68f8f1e3037cca57641dd3928fd2e8aeed3575b

Do not prepend DBM <> APM trace comment in SQLCommenter if there is a… · kosedogukan/dd-trace-java@d68f8f1 · GitHub
Skip to content

Commit d68f8f1

Browse files
authored
Do not prepend DBM <> APM trace comment in SQLCommenter if there is a pg plan hint (DataDog#8864)
* Append comment if there's a pg plan hint * Another test for comment placement
1 parent ea30a70 commit d68f8f1

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/SQLCommenter.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ public static String inject(
8080
if (dbType != null) {
8181
final String firstWord = getFirstWord(sql);
8282

83-
// The Postgres JDBC parser doesn't allow SQL comments anywhere in a JDBC callable statements
83+
// The Postgres JDBC parser doesn't allow SQL comments anywhere in a JDBC
84+
// callable statements
8485
// https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L1038
85-
// TODO: Could we inject the comment after the JDBC has been converted to standard SQL?
86+
// TODO: Could we inject the comment after the JDBC has been converted to
87+
// standard SQL?
8688
if (firstWord.startsWith("{") && dbType.startsWith("postgres")) {
8789
return sql;
8890
}
@@ -92,11 +94,17 @@ public static String inject(
9294
appendComment = true;
9395
}
9496

95-
// Both Postgres and MySQL are unhappy with anything before CALL in a stored procedure
97+
// Both Postgres and MySQL are unhappy with anything before CALL in a stored
98+
// procedure
9699
// invocation but they seem ok with it after so we force append mode
97100
if (firstWord.equalsIgnoreCase("call")) {
98101
appendComment = true;
99102
}
103+
104+
// Append the comment in the case of a pg_hint_plan extension
105+
if (dbType.startsWith("postgres") && containsPgHint(sql)) {
106+
appendComment = true;
107+
}
100108
}
101109

102110
AgentSpan currSpan = activeSpan();
@@ -295,4 +303,10 @@ private static int computeInitialCapacity() {
295303
+ CLOSE_COMMENT.length(); // two quotes, one equals & one comma * 5 + \* */
296304
return tagKeysLen + extraCharsLen;
297305
}
306+
307+
// pg_hint_plan extension works by checking the first block comment
308+
// we'll have to append the traced comment if there is a pghint
309+
private static boolean containsPgHint(String sql) {
310+
return sql.indexOf("/*+") > 0;
311+
}
298312
}

dd-java-agent/instrumentation/jdbc/src/test/groovy/SQLCommenterTest.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class SQLCommenterTest extends AgentTestRunner {
108108
"/*traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | false | null | "/*traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/ SELECT * FROM foo"
109109
"/*customer-comment*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | false | null | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/ /*customer-comment*/ SELECT * FROM foo"
110110
"/*traceparent" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | false | null | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/ /*traceparent"
111+
"SELECT /*+ SeqScan(foo) */ * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT /*+ SeqScan(foo) */ * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/"
112+
"/*+ SeqScan(foo) */ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "/*+ SeqScan(foo) */ SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/"
111113
}
112114

113115
def "test encode Sql Comment with peer service"() {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy