Skip to content

Commit 73656ad

Browse files
committed
Add a new dynamic_service DBM propagation mode
1 parent df1784e commit 73656ad

4 files changed

Lines changed: 57 additions & 5 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.trace.instrumentation.jdbc;
22

3+
import static datadog.trace.api.Config.DBM_PROPAGATION_MODE_DYNAMIC_SERVICE;
34
import static datadog.trace.api.Config.DBM_PROPAGATION_MODE_FULL;
45
import static datadog.trace.api.Config.DBM_PROPAGATION_MODE_STATIC;
56
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
@@ -60,7 +61,8 @@ public class JDBCDecorator extends DatabaseClientDecorator<DBInfo> {
6061
Config.get().isExperimentalPropagateProcessTagsEnabled();
6162
public static final boolean INJECT_COMMENT =
6263
DBM_PROPAGATION_MODE.equals(DBM_PROPAGATION_MODE_FULL)
63-
|| DBM_PROPAGATION_MODE.equals(DBM_PROPAGATION_MODE_STATIC);
64+
|| DBM_PROPAGATION_MODE.equals(DBM_PROPAGATION_MODE_STATIC)
65+
|| DBM_PROPAGATION_MODE.equals(DBM_PROPAGATION_MODE_DYNAMIC_SERVICE);
6466
private static final boolean INJECT_TRACE_CONTEXT =
6567
DBM_PROPAGATION_MODE.equals(DBM_PROPAGATION_MODE_FULL);
6668
public static final boolean DBM_TRACE_PREPARED_STATEMENTS =

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import datadog.trace.agent.test.InstrumentationSpecification
22
import datadog.trace.api.BaseHash
33
import datadog.trace.api.DDSpanTypes
44
import datadog.trace.api.ProcessTags
5-
import datadog.trace.api.config.GeneralConfig
65
import datadog.trace.api.config.TraceInstrumentationConfig
76
import datadog.trace.api.config.TracerConfig
87
import datadog.trace.bootstrap.instrumentation.api.Tags
@@ -83,13 +82,49 @@ class DBMAppendInjectionForkedTest extends InjectionTest {
8382
}
8483
}
8584

85+
class DBMDynamicServiceInjectionForkedTest extends InjectionTest {
86+
87+
@Override
88+
void configurePreAgent() {
89+
super.configurePreAgent()
90+
// override to dynamic_service (InjectionTest sets full)
91+
injectSysConfig(TraceInstrumentationConfig.DB_DBM_PROPAGATION_MODE_MODE, "dynamic_service")
92+
}
93+
94+
def "dynamic_service injects comment with base hash but no traceparent"() {
95+
setup:
96+
ProcessTags.reset()
97+
BaseHash.updateBaseHash(123456789L)
98+
def connection = new TestConnection(false)
99+
100+
when:
101+
def statement = connection.createStatement() as TestStatement
102+
statement.executeQuery(query)
103+
104+
then:
105+
assert statement.sql.contains("ddps='my_service_name'")
106+
assert statement.sql.contains("dddbs='remapped_testdb'")
107+
assert statement.sql.contains("ddsh='123456789'")
108+
assert !statement.sql.contains("traceparent=")
109+
assertTraces(1) {
110+
trace(1) {
111+
span {
112+
spanType DDSpanTypes.SQL
113+
tags(false) {
114+
"$Tags.BASE_HASH" "123456789"
115+
}
116+
}
117+
}
118+
}
119+
}
120+
}
121+
86122
class DBMBaseHashInjectionForkedTest extends InjectionTest {
87123

88124
@Override
89125
void configurePreAgent() {
90126
super.configurePreAgent()
91127
injectSysConfig(TraceInstrumentationConfig.DB_DBM_INJECT_SQL_BASEHASH, "true")
92-
injectSysConfig(GeneralConfig.EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "true")
93128
}
94129

95130
def "base hash tag is set on span and matches the one in the SQL comment"() {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,16 @@ class JDBCDecoratorNoPropagationForkedTest extends JDBCDecoratorTest {
6868
return false
6969
}
7070
}
71+
72+
class JDBCDecoratorDynamicServicePropagationForkedTest extends JDBCDecoratorTest {
73+
@Override
74+
protected void setupPropagationMode() {
75+
injectSysConfig(DB_DBM_PROPAGATION_MODE_MODE, "dynamic_service")
76+
}
77+
78+
@Override
79+
protected boolean expectedFromConfig() {
80+
// dynamic_service behaves like service mode: no trace context injection
81+
return false
82+
}
83+
}

internal-api/src/main/java/datadog/trace/api/Config.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5638,7 +5638,7 @@ public long getDependecyResolutionPeriodMillis() {
56385638
}
56395639

56405640
public boolean isDbmInjectSqlBaseHash() {
5641-
return dbmInjectSqlBaseHash;
5641+
return dbmInjectSqlBaseHash || DBM_PROPAGATION_MODE_DYNAMIC_SERVICE.equals(dbmPropagationMode);
56425642
}
56435643

56445644
public boolean isDbmTracePreparedStatements() {
@@ -5656,14 +5656,16 @@ public String getDbmPropagationMode() {
56565656
// Database monitoring propagation mode constants
56575657
public static final String DBM_PROPAGATION_MODE_STATIC = "service";
56585658
public static final String DBM_PROPAGATION_MODE_FULL = "full";
5659+
public static final String DBM_PROPAGATION_MODE_DYNAMIC_SERVICE = "dynamic_service";
56595660

56605661
// Helper method to check if comment injection is enabled
56615662
public boolean isDbmCommentInjectionEnabled() {
56625663
if (dbmPropagationMode == null) {
56635664
return false;
56645665
}
56655666
return dbmPropagationMode.equals(DBM_PROPAGATION_MODE_FULL)
5666-
|| dbmPropagationMode.equals(DBM_PROPAGATION_MODE_STATIC);
5667+
|| dbmPropagationMode.equals(DBM_PROPAGATION_MODE_STATIC)
5668+
|| dbmPropagationMode.equals(DBM_PROPAGATION_MODE_DYNAMIC_SERVICE);
56675669
}
56685670

56695671
private void logIgnoredSettingWarning(

0 commit comments

Comments
 (0)