11import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
22import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
3+ import static datadog.trace.api.config.TraceInstrumentationConfig.CASSANDRA_KEYSPACE_STATEMENT_EXTRACTION_ENABLED
34import static datadog.trace.api.config.TraceInstrumentationConfig.DB_CLIENT_HOST_SPLIT_BY_INSTANCE
45
56import com.datastax.driver.core.Cluster
@@ -57,8 +58,11 @@ abstract class CassandraClientTest extends VersionedNamingTestBase {
5758 def " test sync" () {
5859 setup :
5960
60- Session session = cluster. connect(keyspace)
61+ Session session = keyspace ? cluster. connect(keyspace) : cluster . connect( )
6162 injectSysConfig(DB_CLIENT_HOST_SPLIT_BY_INSTANCE , " $renameService " )
63+ if (extractFromStatement) {
64+ injectSysConfig(CASSANDRA_KEYSPACE_STATEMENT_EXTRACTION_ENABLED , " true" )
65+ }
6266
6367 when :
6468 session. execute(statement)
@@ -71,27 +75,37 @@ abstract class CassandraClientTest extends VersionedNamingTestBase {
7175 }
7276 }
7377 trace(1 ) {
74- cassandraSpan(it, statement, keyspace , renameService)
78+ cassandraSpan(it, statement, expectedKeySpace , renameService)
7579 }
7680 }
7781
7882 cleanup :
7983 session. close()
8084
8185 where :
82- statement | keyspace | renameService
83- " DROP KEYSPACE IF EXISTS sync_test" | null | false
84- " CREATE KEYSPACE sync_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | true
85- " CREATE TABLE sync_test.users ( id UUID PRIMARY KEY, name text )" | " sync_test" | false
86- " INSERT INTO sync_test.users (id, name) values (uuid(), 'alice')" | " sync_test" | false
87- " SELECT * FROM users where name = 'alice' ALLOW FILTERING" | " sync_test" | true
86+ statement | keyspace | expectedKeySpace | renameService | extractFromStatement
87+ " DROP KEYSPACE IF EXISTS sync_test" | null | null | false | true
88+ " DROP KEYSPACE IF EXISTS a_ks" | null | null | false | true
89+ " CREATE KEYSPACE sync_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | null | true | true
90+ " CREATE KEYSPACE a_ks WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | null | false | true
91+ " CREATE TABLE sync_test.users ( id UUID PRIMARY KEY, name text )" | " sync_test" | " sync_test" | false | true
92+ " INSERT INTO sync_test.users (id, name) values (uuid(), 'alice')" | " sync_test" | " sync_test" | false | true
93+ " SELECT * FROM users where name = 'alice' ALLOW FILTERING" | " sync_test" | " sync_test" | true | true
94+ " SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING" | " a_ks" | " sync_test" | false | true
95+ " SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING" | " a_ks" | " sync_test" | true | true
96+ " SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING" | null | " sync_test" | false | true
97+ " SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING" | null | " sync_test" | true | true
98+ " SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING" | null | null | false | false
8899 }
89100
90101 def " test async" () {
91102 setup :
92103
93104 def callbackExecuted = new CountDownLatch (1 )
94105 injectSysConfig(DB_CLIENT_HOST_SPLIT_BY_INSTANCE , " $renameService " )
106+ if (extractFromStatement) {
107+ injectSysConfig(CASSANDRA_KEYSPACE_STATEMENT_EXTRACTION_ENABLED , " true" )
108+ }
95109
96110 when :
97111 Session session = cluster. connect(keyspace)
@@ -117,7 +131,7 @@ abstract class CassandraClientTest extends VersionedNamingTestBase {
117131 trace(3 ) {
118132 sortSpansByStart()
119133 basicSpan(it, " parent" )
120- cassandraSpan(it, statement, keyspace , renameService, span(0 ))
134+ cassandraSpan(it, statement, expectedKeySpace , renameService, span(0 ))
121135 basicSpan(it, " callbackListener" , span(0 ))
122136 }
123137 }
@@ -126,12 +140,17 @@ abstract class CassandraClientTest extends VersionedNamingTestBase {
126140 session. close()
127141
128142 where :
129- statement | keyspace | renameService
130- " DROP KEYSPACE IF EXISTS async_test" | null | false
131- " CREATE KEYSPACE async_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | true
132- " CREATE TABLE async_test.users ( id UUID PRIMARY KEY, name text )" | " async_test" | false
133- " INSERT INTO async_test.users (id, name) values (uuid(), 'alice')" | " async_test" | false
134- " SELECT * FROM users where name = 'alice' ALLOW FILTERING" | " async_test" | true
143+ statement | keyspace | expectedKeySpace | renameService | extractFromStatement
144+ " DROP KEYSPACE IF EXISTS async_test" | null | null | false | false
145+ " DROP KEYSPACE IF EXISTS a_ks" | null | null | false | false
146+ " CREATE KEYSPACE async_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | null | true | false
147+ " CREATE KEYSPACE a_ks WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | null | true | false
148+ " CREATE TABLE async_test.users ( id UUID PRIMARY KEY, name text )" | " async_test" | " async_test" | false | false
149+ " INSERT INTO async_test.users (id, name) values (uuid(), 'alice')" | " async_test" | " async_test" | false | false
150+ " SELECT * FROM users where name = 'alice' ALLOW FILTERING" | " async_test" | " async_test" | false | false
151+ " SELECT * FROM async_test.users where name = 'alice' ALLOW FILTERING" | null | null | false | false
152+ " SELECT * FROM async_test.users where name = 'alice' ALLOW FILTERING" | " a_ks" | " a_ks" | false | false
153+ " SELECT * FROM async_test.users where name = 'alice' ALLOW FILTERING" | null | " async_test" | true | true
135154 }
136155
137156 String normalize (String statement ){
0 commit comments