Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package datadog.trace.instrumentation.jdbc;

import static datadog.trace.api.Config.DBM_PROPAGATION_MODE_DYNAMIC_SERVICE;
import static datadog.trace.api.Config.DBM_PROPAGATION_MODE_FULL;
import static datadog.trace.api.Config.DBM_PROPAGATION_MODE_STATIC;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
Expand Down Expand Up @@ -60,7 +61,8 @@ public class JDBCDecorator extends DatabaseClientDecorator<DBInfo> {
Config.get().isExperimentalPropagateProcessTagsEnabled();
public static final boolean INJECT_COMMENT =
DBM_PROPAGATION_MODE.equals(DBM_PROPAGATION_MODE_FULL)
|| DBM_PROPAGATION_MODE.equals(DBM_PROPAGATION_MODE_STATIC);
|| DBM_PROPAGATION_MODE.equals(DBM_PROPAGATION_MODE_STATIC)
|| DBM_PROPAGATION_MODE.equals(DBM_PROPAGATION_MODE_DYNAMIC_SERVICE);
private static final boolean INJECT_TRACE_CONTEXT =
DBM_PROPAGATION_MODE.equals(DBM_PROPAGATION_MODE_FULL);
public static final boolean DBM_TRACE_PREPARED_STATEMENTS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import datadog.trace.agent.test.InstrumentationSpecification
import datadog.trace.api.BaseHash
import datadog.trace.api.DDSpanTypes
import datadog.trace.api.ProcessTags
import datadog.trace.api.config.GeneralConfig
import datadog.trace.api.config.TraceInstrumentationConfig
import datadog.trace.api.config.TracerConfig
import datadog.trace.bootstrap.instrumentation.api.Tags
Expand Down Expand Up @@ -83,13 +82,49 @@ class DBMAppendInjectionForkedTest extends InjectionTest {
}
}

class DBMDynamicServiceInjectionForkedTest extends InjectionTest {
Comment thread
amarziali marked this conversation as resolved.

@Override
void configurePreAgent() {
super.configurePreAgent()
// override to dynamic_service (InjectionTest sets full)
injectSysConfig(TraceInstrumentationConfig.DB_DBM_PROPAGATION_MODE_MODE, "dynamic_service")
}

def "dynamic_service injects comment with base hash but no traceparent"() {
setup:
ProcessTags.reset()
BaseHash.updateBaseHash(123456789L)
def connection = new TestConnection(false)

when:
def statement = connection.createStatement() as TestStatement
statement.executeQuery(query)

then:
assert statement.sql.contains("ddps='my_service_name'")
assert statement.sql.contains("dddbs='remapped_testdb'")
assert statement.sql.contains("ddsh='123456789'")
assert !statement.sql.contains("traceparent=")
assertTraces(1) {
trace(1) {
span {
spanType DDSpanTypes.SQL
tags(false) {
"$Tags.BASE_HASH" "123456789"
}
}
}
}
}
}

class DBMBaseHashInjectionForkedTest extends InjectionTest {

@Override
void configurePreAgent() {
super.configurePreAgent()
injectSysConfig(TraceInstrumentationConfig.DB_DBM_INJECT_SQL_BASEHASH, "true")
injectSysConfig(GeneralConfig.EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "true")
}

def "base hash tag is set on span and matches the one in the SQL comment"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,16 @@ class JDBCDecoratorNoPropagationForkedTest extends JDBCDecoratorTest {
return false
}
}
class JDBCDecoratorDynamicServicePropagationForkedTest extends JDBCDecoratorTest {
@Override
protected void setupPropagationMode() {
injectSysConfig(DB_DBM_PROPAGATION_MODE_MODE, "dynamic_service")
}
@Override
protected boolean expectedFromConfig() {
// dynamic_service behaves like service mode: no trace context injection
return false
}
}
6 changes: 4 additions & 2 deletions internal-api/src/main/java/datadog/trace/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -5638,7 +5638,7 @@ public long getDependecyResolutionPeriodMillis() {
}

public boolean isDbmInjectSqlBaseHash() {
return dbmInjectSqlBaseHash;
return dbmInjectSqlBaseHash || DBM_PROPAGATION_MODE_DYNAMIC_SERVICE.equals(dbmPropagationMode);
}

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

// Helper method to check if comment injection is enabled
public boolean isDbmCommentInjectionEnabled() {
if (dbmPropagationMode == null) {
return false;
}
return dbmPropagationMode.equals(DBM_PROPAGATION_MODE_FULL)
|| dbmPropagationMode.equals(DBM_PROPAGATION_MODE_STATIC);
|| dbmPropagationMode.equals(DBM_PROPAGATION_MODE_STATIC)
|| dbmPropagationMode.equals(DBM_PROPAGATION_MODE_DYNAMIC_SERVICE);
}

private void logIgnoredSettingWarning(
Expand Down
Loading