diff --git a/dd-java-agent/instrumentation/jdbc/build.gradle b/dd-java-agent/instrumentation/jdbc/build.gradle index 096f227a660..9fd8e2d6d8b 100644 --- a/dd-java-agent/instrumentation/jdbc/build.gradle +++ b/dd-java-agent/instrumentation/jdbc/build.gradle @@ -22,6 +22,7 @@ addTestSuiteExtendingForDir('latestDepJava11Test', 'latestDepTest', 'test') dependencies { compileOnly group: 'com.zaxxer', name: 'HikariCP', version: '2.4.0' testImplementation(testFixtures(project(':dd-java-agent:agent-iast'))) + implementation project(':utils:container-utils') // jdbc unit testing testImplementation group: 'com.h2database', name: 'h2', version: '[1.3.168,1.3.169]'// first jdk 1.6 compatible @@ -85,8 +86,3 @@ tasks.named("latestDepJava11Test").configure { tasks.withType(Test).configureEach { usesService(testcontainersLimit) } - -jmh { - jmhVersion = libs.versions.jmh.get() - duplicateClassesStrategy = DuplicatesStrategy.EXCLUDE -} diff --git a/dd-java-agent/instrumentation/jdbc/src/jmh/java/datadog/trace/instrumentation/jdbc/SQLCommenterBenchmark.java b/dd-java-agent/instrumentation/jdbc/src/jmh/java/datadog/trace/instrumentation/jdbc/SQLCommenterBenchmark.java deleted file mode 100644 index 195b221d2bc..00000000000 --- a/dd-java-agent/instrumentation/jdbc/src/jmh/java/datadog/trace/instrumentation/jdbc/SQLCommenterBenchmark.java +++ /dev/null @@ -1,41 +0,0 @@ -package datadog.trace.instrumentation.jdbc; - -import java.util.concurrent.TimeUnit; -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.BenchmarkMode; -import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.annotations.OutputTimeUnit; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.State; - -@BenchmarkMode(Mode.AverageTime) -@OutputTimeUnit(TimeUnit.NANOSECONDS) -@State(Scope.Thread) -public class SQLCommenterBenchmark { - - private static final String traceParent = - "00-00000000000000007fffffffffffffff-000000024cb016ea-01"; - private static final String dbService = "users-db"; - private static final String hostname = "my-host"; - private static final String dbName = "credit-card-numbers"; - private static final String parentService = "parent"; - private static final String env = "env"; - private static final String version = "version"; - private static final boolean injectTrace = true; - - @Benchmark - public void testToComment() { - StringBuilder stringBuilder = new StringBuilder(); - SQLCommenter.toComment( - stringBuilder, - injectTrace, - parentService, - dbService, - hostname, - dbName, - null, - env, - version, - traceParent); - } -} diff --git a/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/DBMCompatibleConnectionInstrumentation.java b/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/DBMCompatibleConnectionInstrumentation.java index 1c628afe152..c37546832c5 100644 --- a/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/DBMCompatibleConnectionInstrumentation.java +++ b/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/DBMCompatibleConnectionInstrumentation.java @@ -116,7 +116,6 @@ public static String onEnter( if (callDepth > 0) { return null; } - final String inputSql = sql; final DBInfo dbInfo = JDBCDecorator.parseDBInfo( connection, InstrumentationContext.get(Connection.class, DBInfo.class)); @@ -125,16 +124,9 @@ public static String onEnter( dbService = traceConfig(activeSpan()).getServiceMapping().getOrDefault(dbService, dbService); } - if (dbInfo.getType().equals("sqlserver")) { - sql = - SQLCommenter.append( - sql, dbService, dbInfo.getType(), dbInfo.getHost(), dbInfo.getDb()); - } else { - sql = - SQLCommenter.prepend( - sql, dbService, dbInfo.getType(), dbInfo.getHost(), dbInfo.getDb()); - } - return inputSql; + boolean append = "sqlserver".equals(dbInfo.getType()); + return SQLCommenter.inject( + sql, dbService, dbInfo.getType(), dbInfo.getHost(), dbInfo.getDb(), null, append); } return sql; } diff --git a/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/JDBCDecorator.java b/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/JDBCDecorator.java index 6c8e3b0651c..7acbb038426 100644 --- a/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/JDBCDecorator.java +++ b/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/JDBCDecorator.java @@ -51,14 +51,14 @@ public class JDBCDecorator extends DatabaseClientDecorator { public static final String DD_INSTRUMENTATION_PREFIX = "_DD_"; - public static final String DBM_PROPAGATION_MODE = Config.get().getDBMPropagationMode(); + public static final String DBM_PROPAGATION_MODE = Config.get().getDbmPropagationMode(); public static final boolean INJECT_COMMENT = DBM_PROPAGATION_MODE.equals(DBM_PROPAGATION_MODE_FULL) || DBM_PROPAGATION_MODE.equals(DBM_PROPAGATION_MODE_STATIC); private static final boolean INJECT_TRACE_CONTEXT = DBM_PROPAGATION_MODE.equals(DBM_PROPAGATION_MODE_FULL); public static final boolean DBM_TRACE_PREPARED_STATEMENTS = - Config.get().isDBMTracePreparedStatements(); + Config.get().isDbmTracePreparedStatements(); private volatile boolean warnedAboutDBMPropagationMode = false; // to log a warning only once @@ -420,7 +420,7 @@ public boolean shouldInjectTraceContext(DBInfo dbInfo) { } public boolean shouldInjectSQLComment() { - return Config.get().getDBMPropagationMode().equals(DBM_PROPAGATION_MODE_FULL) - || Config.get().getDBMPropagationMode().equals(DBM_PROPAGATION_MODE_STATIC); + return Config.get().getDbmPropagationMode().equals(DBM_PROPAGATION_MODE_FULL) + || Config.get().getDbmPropagationMode().equals(DBM_PROPAGATION_MODE_STATIC); } } diff --git a/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/SQLCommenter.java b/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/SQLCommenter.java index 075ccbbbcc7..360155b567a 100644 --- a/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/SQLCommenter.java +++ b/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/SQLCommenter.java @@ -2,7 +2,10 @@ import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan; +import datadog.common.container.ContainerInfo; +import datadog.trace.api.BaseHash; import datadog.trace.api.Config; +import datadog.trace.api.ProcessTags; import datadog.trace.bootstrap.instrumentation.api.AgentSpan; import datadog.trace.bootstrap.instrumentation.api.Tags; import java.io.UnsupportedEncodingException; @@ -12,9 +15,19 @@ import org.slf4j.LoggerFactory; public class SQLCommenter { - private static final Logger log = LoggerFactory.getLogger(SQLCommenter.class); private static final String UTF8 = StandardCharsets.UTF_8.toString(); + + private static final char EQUALS = '='; + private static final char COMMA = ','; + private static final char QUOTE = '\''; + private static final char SPACE = ' '; + private static final String OPEN_COMMENT = "/*"; + private static final int OPEN_COMMENT_LEN = OPEN_COMMENT.length(); + private static final String CLOSE_COMMENT = "*/"; + + // Injected fields. When adding a new one, be sure to update this and the methods below. + private static final int NUMBER_OF_FIELDS = 9; private static final String PARENT_SERVICE = encode("ddps"); private static final String DATABASE_SERVICE = encode("dddbs"); private static final String DD_HOSTNAME = encode("ddh"); @@ -23,33 +36,16 @@ public class SQLCommenter { private static final String DD_ENV = encode("dde"); private static final String DD_VERSION = encode("ddpv"); private static final String TRACEPARENT = encode("traceparent"); - private static final char EQUALS = '='; - private static final char COMMA = ','; - private static final char QUOTE = '\''; - private static final char SPACE = ' '; - private static final String OPEN_COMMENT = "/*"; - private static final String CLOSE_COMMENT = "*/"; - private static final int INITIAL_CAPACITY = computeInitialCapacity(); - - public static String append( - final String sql, - final String dbService, - final String dbType, - final String hostname, - final String dbName) { - return inject(sql, dbService, dbType, hostname, dbName, null, false, true); - } + private static final String DD_SERVICE_HASH = encode("ddsh"); - public static String prepend( - final String sql, - final String dbService, - final String dbType, - final String hostname, - final String dbName) { - return inject(sql, dbService, dbType, hostname, dbName, null, false, false); - } + private static final int KEY_AND_SEPARATORS_ESTIMATED_SIZE = 10; + private static final int VALUE_ESTIMATED_SIZE = 10; + private static final int TRACE_PARENT_EXTRA_ESTIMATED_SIZE = 50; + private static final int INJECTED_COMMENT_ESTIMATED_SIZE = + NUMBER_OF_FIELDS * (KEY_AND_SEPARATORS_ESTIMATED_SIZE + VALUE_ESTIMATED_SIZE) + + TRACE_PARENT_EXTRA_ESTIMATED_SIZE; - public static String getFirstWord(String sql) { + protected static String getFirstWord(String sql) { int beginIndex = 0; while (beginIndex < sql.length() && Character.isWhitespace(sql.charAt(beginIndex))) { beginIndex++; @@ -62,21 +58,17 @@ public static String getFirstWord(String sql) { } public static String inject( - final String sql, - final String dbService, - final String dbType, - final String hostname, - final String dbName, - final String traceParent, - final boolean injectTrace, - boolean appendComment) { + String sql, + String dbService, + String dbType, + String hostname, + String dbName, + String traceParent, + boolean preferAppend) { if (sql == null || sql.isEmpty()) { return sql; } - if (hasDDComment(sql, appendComment)) { - return sql; - } - + boolean appendComment = preferAppend; if (dbType != null) { final String firstWord = getFirstWord(sql); @@ -95,117 +87,99 @@ public static String inject( } // Both Postgres and MySQL are unhappy with anything before CALL in a stored - // procedure - // invocation but they seem ok with it after so we force append mode + // procedure invocation, but they seem ok with it after so we force append mode if (firstWord.equalsIgnoreCase("call")) { appendComment = true; } // Append the comment in the case of a pg_hint_plan extension - if (dbType.startsWith("postgres") && containsPgHint(sql)) { + if (dbType.startsWith("postgres") && sql.contains("/*+")) { appendComment = true; } } - - AgentSpan currSpan = activeSpan(); - Object peerServiceObj = null; - if (currSpan != null) { - peerServiceObj = currSpan.getTag(Tags.PEER_SERVICE); + if (hasDDComment(sql, appendComment)) { + return sql; } - final Config config = Config.get(); - final String parentService = config.getServiceName(); - final String env = config.getEnv(); - final String version = config.getVersion(); - final int commentSize = capacity(traceParent, parentService, dbService, env, version); - StringBuilder sb = new StringBuilder(sql.length() + commentSize); - boolean commentAdded = false; - String peerService = peerServiceObj != null ? peerServiceObj.toString() : null; + Config config = Config.get(); + String parentService = config.getServiceName(); + String env = config.getEnv(); + String serviceHash = null; + String containerTagsHash = ContainerInfo.get().getContainerTagsHash(); + // TODO so we only inject if both container tags and process tags are available? + if (config.isDbmInjectSqlBaseHash() + && containerTagsHash != null + && ProcessTags.getTagsForSerialization() != null) { + long baseHash = BaseHash.getBaseHash(parentService, env, containerTagsHash); + serviceHash = Long.toString(baseHash); + } + StringBuilder sb = new StringBuilder(sql.length() + INJECTED_COMMENT_ESTIMATED_SIZE); if (appendComment) { sb.append(sql); sb.append(SPACE); - sb.append(OPEN_COMMENT); - commentAdded = - toComment( - sb, - injectTrace, - parentService, - dbService, - hostname, - dbName, - peerService, - env, - version, - traceParent); - sb.append(CLOSE_COMMENT); - } else { - sb.append(OPEN_COMMENT); - commentAdded = - toComment( - sb, - injectTrace, - parentService, - dbService, - hostname, - dbName, - peerService, - env, - version, - traceParent); - - sb.append(CLOSE_COMMENT); - sb.append(SPACE); - sb.append(sql); } - if (!commentAdded) { + sb.append(OPEN_COMMENT); + int initSize = sb.length(); + append(sb, PARENT_SERVICE, parentService, initSize); + append(sb, DATABASE_SERVICE, dbService, initSize); + append(sb, DD_HOSTNAME, hostname, initSize); + append(sb, DD_DB_NAME, dbName, initSize); + append(sb, DD_PEER_SERVICE, getPeerService(), initSize); + append(sb, DD_ENV, env, initSize); + append(sb, DD_VERSION, config.getVersion(), initSize); + append(sb, TRACEPARENT, traceParent, initSize); + append(sb, DD_SERVICE_HASH, serviceHash, initSize); + if (initSize == sb.length()) { + // no comment was added return sql; } + sb.append(CLOSE_COMMENT); + if (!appendComment) { + sb.append(SPACE); + sb.append(sql); + } return sb.toString(); } - private static boolean hasDDComment(String sql, final boolean appendComment) { - // first check to see if sql ends with a comment - if ((!(sql.endsWith(CLOSE_COMMENT)) && appendComment) - || ((!(sql.startsWith(OPEN_COMMENT))) && !appendComment)) { + private static String getPeerService() { + AgentSpan span = activeSpan(); + Object peerService = null; + if (span != null) { + peerService = span.getTag(Tags.PEER_SERVICE); + } + return peerService != null ? peerService.toString() : null; + } + + private static boolean hasDDComment(String sql, boolean appendComment) { + if ((!sql.endsWith(CLOSE_COMMENT) && appendComment) + || ((!sql.startsWith(OPEN_COMMENT)) && !appendComment)) { return false; } - // else check to see if it's a DBM trace sql comment - int startIdx = 2; + int startIdx = OPEN_COMMENT_LEN; if (appendComment) { - startIdx = sql.lastIndexOf(OPEN_COMMENT) + 2; - } - int startComment = appendComment ? startIdx : sql.length(); - boolean found = false; - if (startComment > 2) { - if (hasMatchingSubstring(sql, startIdx, PARENT_SERVICE)) { - found = true; - } else if (hasMatchingSubstring(sql, startIdx, DATABASE_SERVICE)) { - found = true; - } else if (hasMatchingSubstring(sql, startIdx, DD_HOSTNAME)) { - found = true; - } else if (hasMatchingSubstring(sql, startIdx, DD_DB_NAME)) { - found = true; - } else if (hasMatchingSubstring(sql, startIdx, DD_ENV)) { - found = true; - } else if (hasMatchingSubstring(sql, startIdx, DD_VERSION)) { - found = true; - } else if (hasMatchingSubstring(sql, startIdx, TRACEPARENT)) { - found = true; - } - } - return found; + startIdx += sql.lastIndexOf(OPEN_COMMENT); + } + return hasMatchingSubstring(sql, startIdx, PARENT_SERVICE) + || hasMatchingSubstring(sql, startIdx, DATABASE_SERVICE) + || hasMatchingSubstring(sql, startIdx, DD_HOSTNAME) + || hasMatchingSubstring(sql, startIdx, DD_DB_NAME) + || hasMatchingSubstring(sql, startIdx, DD_PEER_SERVICE) + || hasMatchingSubstring(sql, startIdx, DD_ENV) + || hasMatchingSubstring(sql, startIdx, DD_VERSION) + || hasMatchingSubstring(sql, startIdx, TRACEPARENT) + || hasMatchingSubstring(sql, startIdx, DD_SERVICE_HASH); } private static boolean hasMatchingSubstring(String sql, int startIndex, String substring) { - final boolean tooLong = startIndex + substring.length() >= sql.length(); + boolean tooLong = startIndex + substring.length() >= sql.length(); if (tooLong || !(sql.charAt(startIndex + substring.length()) == EQUALS)) { return false; } return sql.startsWith(substring, startIndex); } - private static String encode(final String val) { + private static String encode(String val) { try { return URLEncoder.encode(val, UTF8); } catch (UnsupportedEncodingException exe) { @@ -216,97 +190,23 @@ private static String encode(final String val) { return val; } - protected static boolean toComment( - StringBuilder sb, - final boolean injectTrace, - final String parentService, - final String dbService, - final String hostname, - final String dbName, - final String peerService, - final String env, - final String version, - final String traceparent) { - int emptySize = sb.length(); - - append(sb, PARENT_SERVICE, parentService, false); - append(sb, DATABASE_SERVICE, dbService, sb.length() > emptySize); - append(sb, DD_HOSTNAME, hostname, sb.length() > emptySize); - append(sb, DD_DB_NAME, dbName, sb.length() > emptySize); - if (peerService != null) { - append(sb, DD_PEER_SERVICE, peerService, sb.length() > emptySize); - } - append(sb, DD_ENV, env, sb.length() > emptySize); - append(sb, DD_VERSION, version, sb.length() > emptySize); - if (injectTrace) { - append(sb, TRACEPARENT, traceparent, sb.length() > emptySize); + private static void append(StringBuilder sb, String key, String value, int initSize) { + if (null == value || value.isEmpty()) { + return; } - return sb.length() > emptySize; - } - - private static void append(StringBuilder sb, String key, String value, boolean prependComma) { - if (null != value && !value.isEmpty()) { - try { - if (prependComma) { - sb.append(COMMA); - } - sb.append(key); - sb.append(EQUALS); - sb.append(QUOTE); - sb.append(URLEncoder.encode(value, UTF8)); - sb.append(QUOTE); - } catch (UnsupportedEncodingException e) { - if (log.isDebugEnabled()) { - log.debug("exception thrown while encoding sql comment %s", e); - } + String encodedValue; + try { + encodedValue = URLEncoder.encode(value, UTF8); + } catch (UnsupportedEncodingException e) { + if (log.isDebugEnabled()) { + log.debug("exception thrown while encoding sql comment %s", e); } + return; } - } - private static int capacity( - final String traceparent, - final String parentService, - final String dbService, - final String env, - final String version) { - int len = INITIAL_CAPACITY; - if (null != traceparent) { - len += traceparent.length(); - } - if (null != parentService) { - len += parentService.length(); - } - if (null != dbService) { - len += dbService.length(); + if (sb.length() > initSize) { + sb.append(COMMA); } - if (null != env) { - len += env.length(); - } - if (null != version) { - len += version.length(); - } - return len; - } - - private static int computeInitialCapacity() { - int tagKeysLen = - PARENT_SERVICE.length() - + DATABASE_SERVICE.length() - + DD_HOSTNAME.length() - + DD_DB_NAME.length() - + DD_ENV.length() - + DD_VERSION.length() - + TRACEPARENT.length(); - int extraCharsLen = - 4 * 5 - + OPEN_COMMENT.length() - + CLOSE_COMMENT.length(); // two quotes, one equals & one comma * 5 + \* */ - return tagKeysLen + extraCharsLen; - } - - // pg_hint_plan extension works by checking the first block comment - // we'll have to append the traced comment if there is a pghint - private static boolean containsPgHint(String sql) { - return sql.indexOf("/*+") > 0; + sb.append(key).append(EQUALS).append(QUOTE).append(encodedValue).append(QUOTE); } } diff --git a/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/StatementInstrumentation.java b/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/StatementInstrumentation.java index 654d98dbed4..206e700fbda 100644 --- a/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/StatementInstrumentation.java +++ b/dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/StatementInstrumentation.java @@ -134,8 +134,7 @@ public static AgentScope onEnter( dbInfo.getType(), dbInfo.getHost(), dbInfo.getDb(), - traceParent, - injectTraceInComment, + injectTraceInComment ? traceParent : null, appendComment); } DECORATE.onStatement(span, copy); diff --git a/dd-java-agent/instrumentation/jdbc/src/test/groovy/SQLCommenterTest.groovy b/dd-java-agent/instrumentation/jdbc/src/test/groovy/SQLCommenterTest.groovy index bb1119db1f1..36b9cd81b8d 100644 --- a/dd-java-agent/instrumentation/jdbc/src/test/groovy/SQLCommenterTest.groovy +++ b/dd-java-agent/instrumentation/jdbc/src/test/groovy/SQLCommenterTest.groovy @@ -1,10 +1,11 @@ +import datadog.common.container.ContainerInfo import datadog.trace.agent.test.AgentTestRunner +import datadog.trace.api.Config +import datadog.trace.api.ProcessTags import datadog.trace.bootstrap.instrumentation.api.AgentSpan import datadog.trace.bootstrap.instrumentation.api.AgentTracer import datadog.trace.bootstrap.instrumentation.api.Tags - import datadog.trace.instrumentation.jdbc.SQLCommenter - import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace class SQLCommenterTest extends AgentTestRunner { @@ -30,7 +31,6 @@ class SQLCommenterTest extends AgentTestRunner { " " | "" } - def "test encode Sql Comment"() { setup: injectSysConfig("dd.service", ddService) @@ -38,113 +38,137 @@ class SQLCommenterTest extends AgentTestRunner { injectSysConfig("dd.version", ddVersion) when: - String sqlWithComment = "" - if (injectTrace) { - sqlWithComment = SQLCommenter.inject(query, dbService, dbType, host, dbName, traceParent, true, appendComment) - } else if (appendComment) { - sqlWithComment = SQLCommenter.append(query, dbService, dbType, host, dbName) - } - else { - sqlWithComment = SQLCommenter.prepend(query, dbService, dbType, host, dbName) - } - + String sqlWithComment = SQLCommenter.inject(query, dbService, dbType, host, dbName, traceParent, append) then: sqlWithComment == expected where: - query | ddService | ddEnv | dbService | dbType | host | dbName | ddVersion | injectTrace | appendComment | traceParent | expected - "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "{call dogshelterProc(?, ?)}" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "{call dogshelterProc(?, ?)} /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "{call dogshelterProc(?, ?)}" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "{call dogshelterProc(?, ?)} /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "{call dogshelterProc(?, ?)}" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "{call dogshelterProc(?, ?)}" - "CALL dogshelterProc(?, ?)" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | true | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "CALL dogshelterProc(?, ?) /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "CALL dogshelterProc(?, ?)" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "CALL dogshelterProc(?, ?) /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "SELECT * FROM foo" | "" | "Test" | "" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "SELECT * FROM foo" | "" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "" | "" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "SELECT * FROM foo" | "" | "Test" | "" | "" | "h" | "n" | "" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*ddh='h',dddb='n',dde='Test',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "SELECT * FROM foo" | "" | "" | "" | "" | "h" | "n" | "" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*ddh='h',dddb='n',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "SELECT * FROM foo" | "" | "" | "" | "" | "" | "" | "" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "SELECT * from FOO -- test query" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | "SELECT * from FOO -- test query /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/" - "SELECT /* customer-comment */ * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | "SELECT /* customer-comment */ * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/" - "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" - "SELECT * FROM DUAL" | "SqlCommenter" | "Test" | "my-service" | "oracle" | "h" | "n" | "TestVersion" | false | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM DUAL /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" - "SELECT * FROM sys.tables" | "SqlCommenter" | "Test" | "my-service" | "sqlserver"| "h" | "n" | "TestVersion" | false | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM sys.tables /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" - "SELECT /* customer-comment */ * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "SELECT /* customer-comment */ * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" - "SELECT * from FOO -- test query" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "SELECT * from FOO -- test query /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" - "" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "" - " " | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | " /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/" - "" | "SqlCommenter" | "Test" | "postgres" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "" - " " | "SqlCommenter" | "Test" | "postgres" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | " /*ddps='SqlCommenter',dddbs='postgres',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/" - "SELECT * FROM foo /*dddbs='my-service',ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "SELECT * FROM foo /*dddbs='my-service',ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" - "SELECT * FROM foo /*ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "SELECT * FROM foo /*ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" - "SELECT * FROM foo /*dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "SELECT * FROM foo /*dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" - "SELECT * FROM foo /*dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "SELECT * FROM foo /*dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" - "SELECT * FROM foo /*ddps='SqlCommenter',ddpv='TestVersion'*/" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "SELECT * FROM foo /*ddps='SqlCommenter',ddpv='TestVersion'*/" - "SELECT * FROM foo /*ddpv='TestVersion'*/" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "SELECT * FROM foo /*ddpv='TestVersion'*/" - "/*ddjk its a customer */ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "/*ddjk its a customer */ SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" - "SELECT * FROM foo /*traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "SELECT * FROM foo /*traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/" - "/*customer-comment*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "/*customer-comment*/ SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" - "/*traceparent" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "/*traceparent /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" - "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/ SELECT * FROM foo" - "SELECT * FROM foo" | "" | "Test" | "" | "mysql" | "h" | "n" | "TestVersion" | true | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "/*ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/ SELECT * FROM foo" - "SELECT * FROM foo" | "" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "/*dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/ SELECT * FROM foo" - "SELECT * FROM foo" | "" | "Test" | "" | "" | "h" | "n" | "" | true | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "/*ddh='h',dddb='n',dde='Test',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/ SELECT * FROM foo" - "SELECT * FROM foo" | "" | "" | "" | "" | "" | "" | "" | true | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "/*traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/ SELECT * FROM foo" - "SELECT * from FOO -- test query" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/ SELECT * from FOO -- test query" - "SELECT /* customer-comment */ * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/ SELECT /* customer-comment */ * FROM foo" - "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'*/ SELECT * FROM foo" - "SELECT /* customer-comment */ * 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'*/ SELECT /* customer-comment */ * FROM foo" - "SELECT * from FOO -- test query" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | false | null | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/ SELECT * from FOO -- test query" - "" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "" - " " | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/ " - "/*dddbs='my-service',ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | false | null | "/*dddbs='my-service',ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" - "/*ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | false | null | "/*ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" - "/*dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | false | null | "/*dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" - "/*dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | false | null | "/*dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" - "/*ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | false | null | "/*ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" - "/*ddpv='TestVersion'*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | false | null | "/*ddpv='TestVersion'*/ SELECT * FROM foo" - "/*ddjk its a customer */ 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'*/ /*ddjk its a customer */ SELECT * FROM foo" - "/*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" - "/*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" - "/*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" - "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'*/" - "/*+ 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'*/" + query | ddService | ddEnv | dbService | dbType | host | dbName | ddVersion | append | traceParent | expected + "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + "{call dogshelterProc(?, ?)}" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "{call dogshelterProc(?, ?)} /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + "{call dogshelterProc(?, ?)}" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "{call dogshelterProc(?, ?)} /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + "{call dogshelterProc(?, ?)}" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "{call dogshelterProc(?, ?)}" + "CALL dogshelterProc(?, ?)" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "CALL dogshelterProc(?, ?) /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + "CALL dogshelterProc(?, ?)" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "CALL dogshelterProc(?, ?) /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + "SELECT * FROM foo" | "" | "Test" | "" | "mysql" | "h" | "n" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + "SELECT * FROM foo" | "" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "" | "" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + "SELECT * FROM foo" | "" | "Test" | "" | "" | "h" | "n" | "" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*ddh='h',dddb='n',dde='Test',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + "SELECT * FROM foo" | "" | "" | "" | "" | "h" | "n" | "" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*ddh='h',dddb='n',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + "SELECT * FROM foo" | "" | "" | "" | "" | "" | "" | "" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM foo /*traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + "SELECT * from FOO -- test query" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | "SELECT * from FOO -- test query /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/" + "SELECT /* customer-comment */ * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | "SELECT /* customer-comment */ * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/" + "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | null | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" + "SELECT * FROM DUAL" | "SqlCommenter" | "Test" | "my-service" | "oracle" | "h" | "n" | "TestVersion" | true | null | "SELECT * FROM DUAL /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" + "SELECT * FROM sys.tables" | "SqlCommenter" | "Test" | "my-service" | "sqlserver"| "h" | "n" | "TestVersion" | true | null | "SELECT * FROM sys.tables /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" + "SELECT /* customer-comment */ * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | null | "SELECT /* customer-comment */ * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" + "SELECT * from FOO -- test query" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | null | "SELECT * from FOO -- test query /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" + "" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "" + " " | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | " /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/" + "" | "SqlCommenter" | "Test" | "postgres" | "mysql" | "h" | "n" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "" + " " | "SqlCommenter" | "Test" | "postgres" | "mysql" | "h" | "n" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | " /*ddps='SqlCommenter',dddbs='postgres',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/" + "SELECT * FROM foo /*dddbs='my-service',ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | null | "SELECT * FROM foo /*dddbs='my-service',ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" + "SELECT * FROM foo /*ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | null | "SELECT * FROM foo /*ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" + "SELECT * FROM foo /*dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | null | "SELECT * FROM foo /*dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" + "SELECT * FROM foo /*dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | null | "SELECT * FROM foo /*dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/" + "SELECT * FROM foo /*ddps='SqlCommenter',ddpv='TestVersion'*/" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | null | "SELECT * FROM foo /*ddps='SqlCommenter',ddpv='TestVersion'*/" + "SELECT * FROM foo /*ddpv='TestVersion'*/" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | null | "SELECT * FROM foo /*ddpv='TestVersion'*/" + "/*ddjk its a customer */ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | null | "/*ddjk its a customer */ SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" + "SELECT * FROM foo /*traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | null | "SELECT * FROM foo /*traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/" + "/*customer-comment*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | null | "/*customer-comment*/ SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" + "/*traceparent" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | null | "/*traceparent /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/" + "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/ SELECT * FROM foo" + "SELECT * FROM foo" | "" | "Test" | "" | "mysql" | "h" | "n" | "TestVersion" | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "/*ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/ SELECT * FROM foo" + "SELECT * FROM foo" | "" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "/*dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/ SELECT * FROM foo" + "SELECT * FROM foo" | "" | "Test" | "" | "" | "h" | "n" | "" | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "/*ddh='h',dddb='n',dde='Test',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/ SELECT * FROM foo" + "SELECT * FROM foo" | "" | "" | "" | "" | "" | "" | "" | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "/*traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/ SELECT * FROM foo" + "SELECT * from FOO -- test query" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/ SELECT * from FOO -- test query" + "SELECT /* customer-comment */ * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/ SELECT /* customer-comment */ * FROM foo" + "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | null | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/ SELECT * FROM foo" + "SELECT /* customer-comment */ * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | null | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/ SELECT /* customer-comment */ * FROM foo" + "SELECT * from FOO -- test query" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | null | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/ SELECT * from FOO -- test query" + "" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "" + " " | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/ " + "/*dddbs='my-service',ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | null | "/*dddbs='my-service',ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" + "/*ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | null | "/*ddh='h',dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" + "/*dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | null | "/*dddb='n',dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" + "/*dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | null | "/*dde='Test',ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" + "/*ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | null | "/*ddps='SqlCommenter',ddpv='TestVersion'*/ SELECT * FROM foo" + "/*ddpv='TestVersion'*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | null | "/*ddpv='TestVersion'*/ SELECT * FROM foo" + "/*ddjk its a customer */ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | null | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/ /*ddjk its a customer */ SELECT * FROM foo" + "/*traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | null | "/*traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/ SELECT * FROM foo" + "/*customer-comment*/ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | null | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/ /*customer-comment*/ SELECT * FROM foo" + "/*traceparent" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | null | "/*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/ /*traceparent" + "SELECT /*+ SeqScan(foo) */ * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | 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'*/" + "/*+ SeqScan(foo) */ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | 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'*/" + "/*+ SeqScan(foo) */ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | 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'*/" + "/*+ SeqScan(foo) */ SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | false | "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'*/" + "/*+ SeqScan(foo) */ SELECT * FROM foo /*ddps=''*/" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "/*+ SeqScan(foo) */ SELECT * FROM foo /*ddps=''*/" + "/*+ SeqScan(foo) */ SELECT * FROM foo /*ddps=''*/" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "/*+ SeqScan(foo) */ SELECT * FROM foo /*ddps=''*/" + "CALL dogshelterProc(?, ?) /*ddps=''*/" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | false | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "CALL dogshelterProc(?, ?) /*ddps=''*/" + "CALL dogshelterProc(?, ?) /*ddps=''*/" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "CALL dogshelterProc(?, ?) /*ddps=''*/" + } + + def "inject base hash"() { + setup: + injectSysConfig("dd.service", srv) + injectSysConfig("dd.env", "") + injectSysConfig("dbm.inject.sql.basehash", Boolean.toString(injectHash)) + injectSysConfig("dd.experimental.propagate.process.tags.enabled", Boolean.toString(processTagsEnabled)) + ProcessTags.reset() + ContainerInfo.get().setContainerTagsHash(containerTagsHash) + + expect: + ContainerInfo.get().getContainerTagsHash() == containerTagsHash + and: + Config.get().isExperimentalPropagateProcessTagsEnabled() == processTagsEnabled + and: + SQLCommenter.inject(query, "", "", "", "", "", false) == result + + where: + query | injectHash | containerTagsHash | processTagsEnabled | srv | result + "SELECT *" | true | null | false | "" | "SELECT *" + "SELECT *" | true | null | true | "" | "SELECT *" + "SELECT *" | true | "234563" | false | "" | "SELECT *" + "SELECT *" | true | "234563" | true | "" | "/*ddsh='5036687995954831329'*/ SELECT *" + "SELECT *" | true | "345342" | false | "" | "SELECT *" + "SELECT *" | true | "345342" | true | "" | "/*ddsh='9119195684516789447'*/ SELECT *" + "SELECT *" | true | null | false | "srv" | "/*ddps='srv'*/ SELECT *" + "SELECT *" | true | null | true | "srv" | "/*ddps='srv'*/ SELECT *" + "SELECT *" | true | "234563" | false | "srv" | "/*ddps='srv'*/ SELECT *" + "SELECT *" | true | "234563" | true | "srv" | "/*ddps='srv',ddsh='-4976804795059740068'*/ SELECT *" + "SELECT *" | true | "345342" | false | "srv" | "/*ddps='srv'*/ SELECT *" + "SELECT *" | true | "345342" | true | "srv" | "/*ddps='srv',ddsh='-221156394106738098'*/ SELECT *" + "SELECT *" | false | null | true | "" | "SELECT *" + "SELECT *" | false | "234563" | true | "" | "SELECT *" + "SELECT *" | false | "234563" | true | "srv" | "/*ddps='srv'*/ SELECT *" + "SELECT *" | false | "345342" | true | "srv" | "/*ddps='srv'*/ SELECT *" + "/*ddsh='-3750763034362895579'*/ SELECT *" | true | null | false | "" | "/*ddsh='-3750763034362895579'*/ SELECT *" + "/*ddsh='-3750763034362895579'*/ SELECT *" | true | "234563" | true | "" | "/*ddsh='-3750763034362895579'*/ SELECT *" } def "test encode Sql Comment with peer service"() { setup: - injectSysConfig("dd.service", ddService) - injectSysConfig("dd.env", ddEnv) - injectSysConfig("dd.version", ddVersion) + injectSysConfig("dd.service", "SqlCommenter") + injectSysConfig("dd.env", "Test") + injectSysConfig("dd.version", "TestVersion") when: - String sqlWithComment = "" - runUnderTrace("testTrace"){ + String sqlWithComment = runUnderTrace("testTrace") { AgentSpan currSpan = AgentTracer.activeSpan() currSpan.setTag(Tags.PEER_SERVICE, peerService) - - if (injectTrace) { - sqlWithComment = SQLCommenter.inject(query, dbService, dbType, host, dbName, traceParent, true, appendComment) - } - else if (appendComment) { - sqlWithComment = SQLCommenter.append(query, dbService, dbType, host, dbName) - } - else { - sqlWithComment = SQLCommenter.prepend(query, dbService, dbType, host, dbName) - } + return SQLCommenter.inject("SELECT * FROM foo", "my-service", dbType, "h", "n", "00-00000000000000007fffffffffffffff-000000024cb016ea-00", true) } then: sqlWithComment == expected where: - query | ddService | ddEnv | dbService | dbType | host | dbName | ddVersion | injectTrace | appendComment | traceParent | peerService | expected - "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "" | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "" | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "testPeer" | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',ddprs='testPeer',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" - "SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "postgres" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "testPeer" | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',ddprs='testPeer',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + dbType | peerService | expected + "mysql" | null | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + "postgres" | "" | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" + "postgres" | "testPeer" | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',ddprs='testPeer',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/" } } diff --git a/dd-trace-api/src/main/java/datadog/trace/api/config/TraceInstrumentationConfig.java b/dd-trace-api/src/main/java/datadog/trace/api/config/TraceInstrumentationConfig.java index de625b66dbc..c2ab4e85393 100644 --- a/dd-trace-api/src/main/java/datadog/trace/api/config/TraceInstrumentationConfig.java +++ b/dd-trace-api/src/main/java/datadog/trace/api/config/TraceInstrumentationConfig.java @@ -66,8 +66,8 @@ public final class TraceInstrumentationConfig { public static final String JDBC_PREPARED_STATEMENT_CLASS_NAME = "trace.jdbc.prepared.statement.class.name"; + public static final String DB_DBM_INJECT_SQL_BASEHASH = "dbm.inject.sql.basehash"; public static final String DB_DBM_PROPAGATION_MODE_MODE = "dbm.propagation.mode"; - public static final String DB_DBM_TRACE_PREPARED_STATEMENTS = "dbm.trace_prepared_statements"; public static final String JDBC_CONNECTION_CLASS_NAME = "trace.jdbc.connection.class.name"; diff --git a/dd-trace-core/src/main/java/datadog/trace/core/datastreams/DefaultDataStreamsMonitoring.java b/dd-trace-core/src/main/java/datadog/trace/core/datastreams/DefaultDataStreamsMonitoring.java index 58093fae2d2..342d0bdc0b9 100644 --- a/dd-trace-core/src/main/java/datadog/trace/core/datastreams/DefaultDataStreamsMonitoring.java +++ b/dd-trace-core/src/main/java/datadog/trace/core/datastreams/DefaultDataStreamsMonitoring.java @@ -7,9 +7,11 @@ import static datadog.trace.util.AgentThreadFactory.THREAD_JOIN_TIMOUT_MS; import static datadog.trace.util.AgentThreadFactory.newAgentThread; +import datadog.common.container.ContainerInfo; import datadog.communication.ddagent.DDAgentFeaturesDiscovery; import datadog.communication.ddagent.SharedCommunicationObjects; import datadog.context.propagation.Propagator; +import datadog.trace.api.BaseHash; import datadog.trace.api.Config; import datadog.trace.api.TraceConfig; import datadog.trace.api.WellKnownTags; @@ -113,7 +115,11 @@ public DefaultDataStreamsMonitoring( this.features = features; this.timeSource = timeSource; this.traceConfigSupplier = traceConfigSupplier; - this.hashOfKnownTags = DefaultPathwayContext.getBaseHash(wellKnownTags); + this.hashOfKnownTags = + BaseHash.getBaseHash( + wellKnownTags.getService(), + wellKnownTags.getEnv(), + ContainerInfo.get().getContainerTagsHash()); this.payloadWriter = payloadWriter; this.bucketDurationNanos = bucketDurationNanos; diff --git a/dd-trace-core/src/main/java/datadog/trace/core/datastreams/DefaultPathwayContext.java b/dd-trace-core/src/main/java/datadog/trace/core/datastreams/DefaultPathwayContext.java index 9fe9af7e9e6..6991a26dc9e 100644 --- a/dd-trace-core/src/main/java/datadog/trace/core/datastreams/DefaultPathwayContext.java +++ b/dd-trace-core/src/main/java/datadog/trace/core/datastreams/DefaultPathwayContext.java @@ -8,9 +8,6 @@ import com.datadoghq.sketch.ddsketch.encoding.GrowingByteArrayOutput; import com.datadoghq.sketch.ddsketch.encoding.VarEncodingHelper; import datadog.context.propagation.CarrierVisitor; -import datadog.trace.api.Config; -import datadog.trace.api.ProcessTags; -import datadog.trace.api.WellKnownTags; import datadog.trace.api.datastreams.DataStreamsContext; import datadog.trace.api.datastreams.DataStreamsTags; import datadog.trace.api.datastreams.PathwayContext; @@ -268,22 +265,6 @@ private static DefaultPathwayContext decode( serviceNameOverride); } - public static long getBaseHash(WellKnownTags wellKnownTags) { - StringBuilder builder = new StringBuilder(); - builder.append(wellKnownTags.getService()); - builder.append(wellKnownTags.getEnv()); - - String primaryTag = Config.get().getPrimaryTag(); - if (primaryTag != null) { - builder.append(primaryTag); - } - CharSequence processTags = ProcessTags.getTagsForSerialization(); - if (processTags != null) { - builder.append(processTags); - } - return FNV64Hash.generateHash(builder.toString(), FNV64Hash.Version.v1); - } - private long generatePathwayHash(long nodeHash, long parentHash) { outputBuffer.clear(); outputBuffer.writeLongLE(nodeHash); diff --git a/dd-trace-core/src/test/groovy/datadog/trace/core/datastreams/DefaultPathwayContextTest.groovy b/dd-trace-core/src/test/groovy/datadog/trace/core/datastreams/DefaultPathwayContextTest.groovy index 802670b6fe5..77d4db39ea6 100644 --- a/dd-trace-core/src/test/groovy/datadog/trace/core/datastreams/DefaultPathwayContextTest.groovy +++ b/dd-trace-core/src/test/groovy/datadog/trace/core/datastreams/DefaultPathwayContextTest.groovy @@ -3,7 +3,6 @@ package datadog.trace.core.datastreams import datadog.communication.ddagent.DDAgentFeaturesDiscovery import datadog.trace.api.Config import datadog.trace.api.DDTraceId -import datadog.trace.api.ProcessTags import datadog.trace.api.TagMap import datadog.trace.api.TraceConfig import datadog.trace.api.WellKnownTags @@ -16,13 +15,9 @@ import datadog.trace.bootstrap.instrumentation.api.AgentTracer import datadog.trace.common.metrics.Sink import datadog.trace.core.propagation.ExtractedContext import datadog.trace.core.test.DDCoreSpecification - import java.util.function.Consumer - import static datadog.context.Context.root import static datadog.trace.api.TracePropagationStyle.DATADOG -import static datadog.trace.api.config.GeneralConfig.EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED -import static datadog.trace.api.config.GeneralConfig.PRIMARY_TAG import static datadog.trace.api.datastreams.DataStreamsContext.create import static datadog.trace.api.datastreams.DataStreamsContext.fromTags import static datadog.trace.api.datastreams.PathwayContext.PROPAGATION_KEY_BASE64 @@ -453,34 +448,6 @@ class DefaultPathwayContextTest extends DDCoreSpecification { } } - def "Primary tag used in hash calculation"() { - when: - def firstBaseHash = DefaultPathwayContext.getBaseHash(wellKnownTags) - - injectSysConfig(PRIMARY_TAG, "region-2") - def secondBaseHash = DefaultPathwayContext.getBaseHash(wellKnownTags) - - then: - firstBaseHash != secondBaseHash - } - - def "Process Tags used in hash calculation"() { - when: - def firstBaseHash = DefaultPathwayContext.getBaseHash(wellKnownTags) - - injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "true") - ProcessTags.reset() - ProcessTags.addTag("000", "first") - def secondBaseHash = DefaultPathwayContext.getBaseHash(wellKnownTags) - - then: - firstBaseHash != secondBaseHash - assert ProcessTags.getTagsForSerialization().startsWithAny("000:first,") - cleanup: - injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "false") - ProcessTags.reset() - } - def "Check context extractor decorator behavior"() { given: def sink = Mock(Sink) diff --git a/internal-api/src/main/java/datadog/trace/api/BaseHash.java b/internal-api/src/main/java/datadog/trace/api/BaseHash.java new file mode 100644 index 00000000000..ffb8695a253 --- /dev/null +++ b/internal-api/src/main/java/datadog/trace/api/BaseHash.java @@ -0,0 +1,38 @@ +package datadog.trace.api; + +import datadog.trace.util.FNV64Hash; + +public final class BaseHash { + + public static long getBaseHash( + CharSequence serviceName, CharSequence env, String containerTagsHash) { + return getBaseHash( + serviceName, + env, + Config.get().getPrimaryTag(), + ProcessTags.getTagsForSerialization(), + containerTagsHash); + } + + private static long getBaseHash( + CharSequence serviceName, + CharSequence env, + String primaryTag, + CharSequence processTags, + String containerTagsHash) { + StringBuilder builder = new StringBuilder(64); + builder.append(serviceName); + builder.append(env); + + if (primaryTag != null) { + builder.append(primaryTag); + } + if (processTags != null) { + builder.append(processTags); + if (containerTagsHash != null && !containerTagsHash.isEmpty()) { + builder.append(containerTagsHash); + } + } + return FNV64Hash.generateHash(builder.toString(), FNV64Hash.Version.v1); + } +} diff --git a/internal-api/src/main/java/datadog/trace/api/Config.java b/internal-api/src/main/java/datadog/trace/api/Config.java index aae53ec7e07..eee9060422f 100644 --- a/internal-api/src/main/java/datadog/trace/api/Config.java +++ b/internal-api/src/main/java/datadog/trace/api/Config.java @@ -491,6 +491,7 @@ import static datadog.trace.api.config.TraceInstrumentationConfig.DB_CLIENT_HOST_SPLIT_BY_HOST; import static datadog.trace.api.config.TraceInstrumentationConfig.DB_CLIENT_HOST_SPLIT_BY_INSTANCE; import static datadog.trace.api.config.TraceInstrumentationConfig.DB_CLIENT_HOST_SPLIT_BY_INSTANCE_TYPE_SUFFIX; +import static datadog.trace.api.config.TraceInstrumentationConfig.DB_DBM_INJECT_SQL_BASEHASH; import static datadog.trace.api.config.TraceInstrumentationConfig.DB_DBM_PROPAGATION_MODE_MODE; import static datadog.trace.api.config.TraceInstrumentationConfig.DB_DBM_TRACE_PREPARED_STATEMENTS; import static datadog.trace.api.config.TraceInstrumentationConfig.ELASTICSEARCH_BODY_AND_PARAMS_ENABLED; @@ -1040,8 +1041,9 @@ public static String getHostName() { private final int remoteConfigMaxExtraServices; - private final String DBMPropagationMode; - private final boolean DBMTracePreparedStatements; + private final boolean dbmInjectSqlBaseHash; + private final String dbmPropagationMode; + private final boolean dbmTracePreparedStatements; private final boolean dynamicInstrumentationEnabled; private final int dynamicInstrumentationUploadTimeout; @@ -1571,14 +1573,16 @@ private Config(final ConfigProvider configProvider, final InstrumenterConfig ins configProvider.getBoolean( DB_CLIENT_HOST_SPLIT_BY_HOST, DEFAULT_DB_CLIENT_HOST_SPLIT_BY_HOST); - DBMPropagationMode = + dbmPropagationMode = configProvider.getString( DB_DBM_PROPAGATION_MODE_MODE, DEFAULT_DB_DBM_PROPAGATION_MODE_MODE); - DBMTracePreparedStatements = + dbmTracePreparedStatements = configProvider.getBoolean( DB_DBM_TRACE_PREPARED_STATEMENTS, DEFAULT_DB_DBM_TRACE_PREPARED_STATEMENTS); + dbmInjectSqlBaseHash = configProvider.getBoolean(DB_DBM_INJECT_SQL_BASEHASH, false); + splitByTags = tryMakeImmutableSet(configProvider.getList(SPLIT_BY_TAGS)); jeeSplitByDeployment = @@ -4860,12 +4864,16 @@ public long getDependecyResolutionPeriodMillis() { return dependecyResolutionPeriodMillis; } - public boolean isDBMTracePreparedStatements() { - return DBMTracePreparedStatements; + public boolean isDbmInjectSqlBaseHash() { + return dbmInjectSqlBaseHash; + } + + public boolean isDbmTracePreparedStatements() { + return dbmTracePreparedStatements; } - public String getDBMPropagationMode() { - return DBMPropagationMode; + public String getDbmPropagationMode() { + return dbmPropagationMode; } private void logIgnoredSettingWarning( @@ -5370,10 +5378,12 @@ public String toString() { + dbClientSplitByInstanceTypeSuffix + ", dbClientSplitByHost=" + dbClientSplitByHost - + ", DBMPropagationMode=" - + DBMPropagationMode - + ", DBMTracePreparedStatements=" - + DBMTracePreparedStatements + + ", dbmInjectSqlBaseHash=" + + dbmInjectSqlBaseHash + + ", dbmPropagationMode=" + + dbmPropagationMode + + ", dbmTracePreparedStatements=" + + dbmTracePreparedStatements + ", splitByTags=" + splitByTags + ", jeeSplitByDeployment=" diff --git a/internal-api/src/main/java/datadog/trace/api/ProcessTags.java b/internal-api/src/main/java/datadog/trace/api/ProcessTags.java index 30d854387a1..5ea482600a1 100644 --- a/internal-api/src/main/java/datadog/trace/api/ProcessTags.java +++ b/internal-api/src/main/java/datadog/trace/api/ProcessTags.java @@ -158,6 +158,10 @@ static void calculate() { private ProcessTags() {} + public static boolean isEnabled() { + return enabled; + } + // need to be synchronized on writing. As optimization, it does not need to be sync on read. public static void addTag(String key, String value) { if (enabled) { diff --git a/internal-api/src/test/groovy/datadog/trace/api/BaseHashTest.groovy b/internal-api/src/test/groovy/datadog/trace/api/BaseHashTest.groovy new file mode 100644 index 00000000000..6177e00ca7c --- /dev/null +++ b/internal-api/src/test/groovy/datadog/trace/api/BaseHashTest.groovy @@ -0,0 +1,62 @@ +package datadog.trace.api + +import datadog.trace.test.util.DDSpecification + +import static datadog.trace.api.config.GeneralConfig.EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED +import static datadog.trace.api.config.GeneralConfig.PRIMARY_TAG + +class BaseHashTest extends DDSpecification { + + def "Primary tag used in hash calculation"() { + when: + def firstBaseHash = BaseHash.getBaseHash("service", "env", null) + + injectSysConfig(PRIMARY_TAG, "region-2") + def secondBaseHash = BaseHash.getBaseHash("service", "env", null) + + then: + firstBaseHash != secondBaseHash + } + + def "Process Tags used in hash calculation"() { + when: + def firstBaseHash = BaseHash.getBaseHash("service", "env", null) + + injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "true") + ProcessTags.reset() + ProcessTags.addTag("000", "first") + def secondBaseHash = BaseHash.getBaseHash("service", "env", null) + + then: + firstBaseHash != secondBaseHash + assert ProcessTags.getTagsForSerialization().startsWithAny("000:first,") + cleanup: + injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "false") + ProcessTags.reset() + } + + def "ContainerTagsHash used in hash calculation when provided"() { + when: + injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, propagateTagsEnabled.toString()) + ProcessTags.reset() + ProcessTags.addTag("000", "first") + def firstBaseHash = BaseHash.getBaseHash("service", "env", null) + + then: + def secondBaseHash = BaseHash.getBaseHash("service", "env", "") + + expect: + if (propagateTagsEnabled) { + assert secondBaseHash != firstBaseHash + } else { + assert secondBaseHash == firstBaseHash + } + + cleanup: + injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "false") + ProcessTags.reset() + + where: + propagateTagsEnabled << [true, false] + } +}