Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
new test cases
  • Loading branch information
nenadnoveljic committed Nov 20, 2024
commit f2f7b8f01c0e713c36425a7ea45f71d916490e9b
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
import static datadog.trace.api.config.TraceInstrumentationConfig.DB_CLIENT_HOST_SPLIT_BY_INSTANCE
import static datadog.trace.api.config.TraceInstrumentationConfig.DB_DBM_TRACE_PREPARED_STATEMENTS

// workaround for SSLHandShakeException on J9 only with Hikari/MySQL
@Requires({ !System.getProperty("java.vendor").contains("IBM") })
Expand Down Expand Up @@ -347,9 +348,9 @@ abstract class RemoteJDBCInstrumentationTest extends VersionedNamingTestBase {
resultSet.next()
resultSet.getInt(1) == 3
def addDbmTag = dbmTraceInjected()
if (driver == POSTGRESQL || driver == MYSQL || !addDbmTag) {
if (driver == SQLSERVER && addDbmTag){
assertTraces(1) {
trace(2) {
trace(3) {
basicSpan(it, "parent")
span {
operationName this.operation(this.getDbType(driver))
Expand All @@ -364,72 +365,76 @@ abstract class RemoteJDBCInstrumentationTest extends VersionedNamingTestBase {
"$Tags.SPAN_KIND" Tags.SPAN_KIND_CLIENT
"$Tags.DB_TYPE" this.getDbType(driver)
"$Tags.DB_INSTANCE" dbName.get(driver).toLowerCase()
// only set when there is an out of proc instance (postgresql, mysql)
"$Tags.PEER_HOSTNAME" String
// currently there is a bug in the instrumentation with
// postgresql and mysql if the connection event is missed
// since Connection.getClientInfo will not provide the username
"$Tags.DB_USER" { it == null || it == jdbcUserNames.get(driver) }
"$Tags.DB_OPERATION" operation
if (usingHikari) {
"$Tags.DB_POOL_NAME" String
}
if (addDbmTag) {
"$InstrumentationTags.DBM_TRACE_INJECTED" true
}
peerServiceFrom(Tags.DB_INSTANCE)
defaultTags()
}
}
}
}
} else {
assertTraces(1) {
trace(3) {
basicSpan(it, "parent")
span {
operationName this.operation(this.getDbType(driver))
serviceName service(driver)
resourceName obfuscatedQuery
operationName this.operation(this.getDbType(driver))
resourceName "set context_info ?"
spanType DDSpanTypes.SQL
childOf span(0)
errored false
measured true
tags {
"$Tags.COMPONENT" "java-jdbc-prepared_statement"
"$Tags.COMPONENT" "java-jdbc-statement"
"$Tags.SPAN_KIND" Tags.SPAN_KIND_CLIENT
"$Tags.DB_TYPE" this.getDbType(driver)
"$Tags.DB_INSTANCE" dbName.get(driver).toLowerCase()
"$Tags.PEER_HOSTNAME" String
"$Tags.DB_USER" { it == null || it == jdbcUserNames.get(driver) }
"$Tags.DB_OPERATION" operation
"$Tags.DB_OPERATION" "set"
if (usingHikari) {
"$Tags.DB_POOL_NAME" String
}
if (addDbmTag) {
"$InstrumentationTags.DBM_TRACE_INJECTED" true
}
"dd.instrumentation" true
peerServiceFrom(Tags.DB_INSTANCE)
defaultTags()
}
}
}
}
} else {
assertTraces(1) {
trace(2) {
basicSpan(it, "parent")
span {
serviceName service(driver)
operationName this.operation(this.getDbType(driver))
resourceName "set context_info ?"
serviceName service(driver)
resourceName obfuscatedQuery
spanType DDSpanTypes.SQL
childOf span(0)
errored false
measured true
tags {
"$Tags.COMPONENT" "java-jdbc-statement"
"$Tags.COMPONENT" "java-jdbc-prepared_statement"
"$Tags.SPAN_KIND" Tags.SPAN_KIND_CLIENT
"$Tags.DB_TYPE" this.getDbType(driver)
"$Tags.DB_INSTANCE" dbName.get(driver).toLowerCase()
// only set when there is an out of proc instance (postgresql, mysql)
"$Tags.PEER_HOSTNAME" String
// currently there is a bug in the instrumentation with
// postgresql and mysql if the connection event is missed
// since Connection.getClientInfo will not provide the username
"$Tags.DB_USER" { it == null || it == jdbcUserNames.get(driver) }
"$Tags.DB_OPERATION" "set"
"$Tags.DB_OPERATION" operation
if (usingHikari) {
"$Tags.DB_POOL_NAME" String
}
"dd.instrumentation" true
if (this.dbmTracePreparedStatements(driver)){
"$InstrumentationTags.DBM_TRACE_INJECTED" true
"$InstrumentationTags.TIME_MS" Long
}
peerServiceFrom(Tags.DB_INSTANCE)
defaultTags()
}
Expand Down Expand Up @@ -470,9 +475,11 @@ abstract class RemoteJDBCInstrumentationTest extends VersionedNamingTestBase {
then:
resultSet.next()
resultSet.getInt(1) == 3
if (driver == POSTGRESQL || driver == MYSQL || !dbmTraceInjected()) {

def addDbmTag = dbmTraceInjected()
if (driver == SQLSERVER && addDbmTag){
assertTraces(1) {
trace(2) {
trace(3) {
basicSpan(it, "parent")
span {
operationName this.operation(this.getDbType(driver))
Expand All @@ -497,64 +504,68 @@ abstract class RemoteJDBCInstrumentationTest extends VersionedNamingTestBase {
if (conPoolType == "hikari") {
"$Tags.DB_POOL_NAME" String
}
"$InstrumentationTags.DBM_TRACE_INJECTED" true
peerServiceFrom(Tags.DB_INSTANCE)
defaultTags()
}
}
}
}
} else {
assertTraces(1) {
trace(3) {
basicSpan(it, "parent")
span {
operationName this.operation(this.getDbType(driver))
serviceName service(driver)
resourceName obfuscatedQuery
operationName this.operation(this.getDbType(driver))
resourceName "set context_info ?"
spanType DDSpanTypes.SQL
childOf span(0)
errored false
measured true
tags {
"$Tags.COMPONENT" "java-jdbc-prepared_statement"
"$Tags.COMPONENT" "java-jdbc-statement"
"$Tags.SPAN_KIND" Tags.SPAN_KIND_CLIENT
"$Tags.DB_TYPE" this.getDbType(driver)
"$Tags.DB_INSTANCE" dbName.get(driver).toLowerCase()
// only set when there is an out of proc instance (postgresql, mysql)
"$Tags.PEER_HOSTNAME" String
// currently there is a bug in the instrumentation with
// postgresql and mysql if the connection event is missed
// since Connection.getClientInfo will not provide the username
"$Tags.DB_USER" { it == null || it == jdbcUserNames.get(driver) }
"$Tags.DB_OPERATION" operation
"$Tags.DB_OPERATION" "set"
if (conPoolType == "hikari") {
"$Tags.DB_POOL_NAME" String
}
"$InstrumentationTags.DBM_TRACE_INJECTED" true
"dd.instrumentation" true
peerServiceFrom(Tags.DB_INSTANCE)
defaultTags()
}
}
}
}
} else {
assertTraces(1) {
trace(2) {
basicSpan(it, "parent")
span {
serviceName service(driver)
operationName this.operation(this.getDbType(driver))
resourceName "set context_info ?"
serviceName service(driver)
resourceName obfuscatedQuery
spanType DDSpanTypes.SQL
childOf span(0)
errored false
measured true
tags {
"$Tags.COMPONENT" "java-jdbc-statement"
"$Tags.COMPONENT" "java-jdbc-prepared_statement"
"$Tags.SPAN_KIND" Tags.SPAN_KIND_CLIENT
"$Tags.DB_TYPE" this.getDbType(driver)
"$Tags.DB_INSTANCE" dbName.get(driver).toLowerCase()
// only set when there is an out of proc instance (postgresql, mysql)
"$Tags.PEER_HOSTNAME" String
// currently there is a bug in the instrumentation with
// postgresql and mysql if the connection event is missed
// since Connection.getClientInfo will not provide the username
"$Tags.DB_USER" { it == null || it == jdbcUserNames.get(driver) }
"$Tags.DB_OPERATION" "set"
"$Tags.DB_OPERATION" operation
if (conPoolType == "hikari") {
"$Tags.DB_POOL_NAME" String
}
"dd.instrumentation" true
if (this.dbmTracePreparedStatements(driver)){
"$InstrumentationTags.DBM_TRACE_INJECTED" true
"$InstrumentationTags.TIME_MS" Long
}
peerServiceFrom(Tags.DB_INSTANCE)
defaultTags()
}
Expand Down Expand Up @@ -595,9 +606,10 @@ abstract class RemoteJDBCInstrumentationTest extends VersionedNamingTestBase {
then:
resultSet.next()
resultSet.getInt(1) == 3
if (driver == POSTGRESQL || driver == MYSQL || !dbmTraceInjected()) {
def addDbmTag = dbmTraceInjected()
if (driver == SQLSERVER && addDbmTag){
assertTraces(1) {
trace(2) {
trace(3) {
basicSpan(it, "parent")
span {
operationName this.operation(this.getDbType(driver))
Expand All @@ -612,69 +624,73 @@ abstract class RemoteJDBCInstrumentationTest extends VersionedNamingTestBase {
"$Tags.SPAN_KIND" Tags.SPAN_KIND_CLIENT
"$Tags.DB_TYPE" this.getDbType(driver)
"$Tags.DB_INSTANCE" dbName.get(driver).toLowerCase()
// only set when there is an out of proc instance (postgresql, mysql)
"$Tags.PEER_HOSTNAME" String
// currently there is a bug in the instrumentation with
// postgresql and mysql if the connection event is missed
// since Connection.getClientInfo will not provide the username
"$Tags.DB_USER" { it == null || it == jdbcUserNames.get(driver) }
"${Tags.DB_OPERATION}" operation
if (conPoolType == "hikari") {
"$Tags.DB_POOL_NAME" String
}
"$InstrumentationTags.DBM_TRACE_INJECTED" true
defaultTags()
}
}
}
}
} else {
assertTraces(1) {
trace(3) {
basicSpan(it, "parent")
span {
operationName this.operation(this.getDbType(driver))
serviceName service(driver)
resourceName obfuscatedQuery
operationName this.operation(this.getDbType(driver))
resourceName "set context_info ?"
spanType DDSpanTypes.SQL
childOf span(0)
errored false
measured true
tags {
"$Tags.COMPONENT" "java-jdbc-prepared_statement"
"$Tags.COMPONENT" "java-jdbc-statement"
"$Tags.SPAN_KIND" Tags.SPAN_KIND_CLIENT
"$Tags.DB_TYPE" this.getDbType(driver)
"$Tags.DB_INSTANCE" dbName.get(driver).toLowerCase()
"$Tags.PEER_HOSTNAME" String
"$Tags.DB_USER" { it == null || it == jdbcUserNames.get(driver) }
"${Tags.DB_OPERATION}" operation
"$Tags.DB_OPERATION" "set"
"dd.instrumentation" true
if (conPoolType == "hikari") {
"$Tags.DB_POOL_NAME" String
}
"$InstrumentationTags.DBM_TRACE_INJECTED" true
peerServiceFrom(Tags.DB_INSTANCE)
defaultTags()
}
}
}
}
} else {
assertTraces(1) {
trace(2) {
basicSpan(it, "parent")
span {
serviceName service(driver)
operationName this.operation(this.getDbType(driver))
resourceName "set context_info ?"
serviceName service(driver)
resourceName obfuscatedQuery
spanType DDSpanTypes.SQL
childOf span(0)
errored false
measured true
tags {
"$Tags.COMPONENT" "java-jdbc-statement"
"$Tags.COMPONENT" "java-jdbc-prepared_statement"
"$Tags.SPAN_KIND" Tags.SPAN_KIND_CLIENT
"$Tags.DB_TYPE" this.getDbType(driver)
"$Tags.DB_INSTANCE" dbName.get(driver).toLowerCase()
// only set when there is an out of proc instance (postgresql, mysql)
"$Tags.PEER_HOSTNAME" String
// currently there is a bug in the instrumentation with
// postgresql and mysql if the connection event is missed
// since Connection.getClientInfo will not provide the username
"$Tags.DB_USER" { it == null || it == jdbcUserNames.get(driver) }
"$Tags.DB_OPERATION" "set"
"dd.instrumentation" true
"${Tags.DB_OPERATION}" operation
if (conPoolType == "hikari") {
"$Tags.DB_POOL_NAME" String
}
peerServiceFrom(Tags.DB_INSTANCE)
if (this.dbmTracePreparedStatements(driver)){
"$InstrumentationTags.DBM_TRACE_INJECTED" true
"$InstrumentationTags.TIME_MS" Long
}
defaultTags()
}
}
Expand Down Expand Up @@ -979,6 +995,10 @@ abstract class RemoteJDBCInstrumentationTest extends VersionedNamingTestBase {
protected abstract String operation(String dbType)

protected abstract boolean dbmTraceInjected()

protected boolean dbmTracePreparedStatements(String dbType){
return false
}
}

class RemoteJDBCInstrumentationV0Test extends RemoteJDBCInstrumentationTest {
Expand Down Expand Up @@ -1067,3 +1087,44 @@ class RemoteDBMTraceInjectedForkedTest extends RemoteJDBCInstrumentationTest {
return databaseNaming.normalizedName(dbType)
}
}

class RemoteDBMTraceInjectedForkedTestTracePreparedStatements extends RemoteJDBCInstrumentationTest {

@Override
void configurePreAgent() {
super.configurePreAgent()
injectSysConfig("dd.dbm.propagation.mode", "full")
injectSysConfig(DB_DBM_TRACE_PREPARED_STATEMENTS, "true")
}

@Override
protected boolean dbmTraceInjected() {
return true
}

@Override
int version() {
return 1
}

@Override
protected String service(String dbType) {
return Config.get().getServiceName()
}

@Override
protected String operation(String dbType) {
return "${dbType}.query"
}

@Override
protected String getDbType(String dbType) {
final databaseNaming = new DatabaseNamingV1()
return databaseNaming.normalizedName(dbType)
}

@Override
protected boolean dbmTracePreparedStatements(String dbType){
return dbType == POSTGRESQL
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class InstrumentationTags {
public static final String TWILIO_STATUS = "twilio.status";
public static final String TWILIO_PARENT_SID = "twilio.parentSid";
public static final String DBM_TRACE_INJECTED = "_dd.dbm_trace_injected";
public static final String TIME_MS = "dd.instrumentation.time_ms";
Comment thread
vandonr marked this conversation as resolved.
Outdated
public static final UTF8BytesString DD_MEASURED = UTF8BytesString.create("_dd.measured");
public static final UTF8BytesString DD_TOP_LEVEL = UTF8BytesString.create("_dd.top_level");
public static final UTF8BytesString DD_PARTIAL_VERSION =
Expand Down