@@ -3,11 +3,13 @@ import com.datastax.driver.core.Session
3
3
import datadog.opentracing.DDSpan
4
4
import datadog.trace.agent.test.AgentTestRunner
5
5
import datadog.trace.agent.test.asserts.TraceAssert
6
+ import datadog.trace.api.Config
6
7
import datadog.trace.api.DDSpanTypes
7
8
import io.opentracing.tag.Tags
8
9
import org.cassandraunit.utils.EmbeddedCassandraServerHelper
9
10
import spock.lang.Shared
10
11
12
+ import static datadog.trace.agent.test.utils.ConfigUtils.withConfigOverride
11
13
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
12
14
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
13
15
@@ -44,68 +46,72 @@ class CassandraClientTest extends AgentTestRunner {
44
46
setup :
45
47
Session session = cluster. connect(keyspace)
46
48
47
- session. execute(statement)
49
+ withConfigOverride(Config . DB_CLIENT_HOST_SPLIT_BY_INSTANCE , " $renameService " ) {
50
+ session. execute(statement)
51
+ }
48
52
49
53
expect :
50
54
assertTraces(keyspace ? 2 : 1 ) {
51
55
if (keyspace) {
52
56
trace(0 , 1 ) {
53
- cassandraSpan(it, 0 , " USE $keyspace " , null )
57
+ cassandraSpan(it, 0 , " USE $keyspace " , null , false )
54
58
}
55
59
}
56
60
trace(keyspace ? 1 : 0 , 1 ) {
57
- cassandraSpan(it, 0 , statement, keyspace)
61
+ cassandraSpan(it, 0 , statement, keyspace, renameService )
58
62
}
59
63
}
60
64
61
65
cleanup :
62
66
session. close()
63
67
64
68
where :
65
- statement | keyspace
66
- " DROP KEYSPACE IF EXISTS sync_test" | null
67
- " CREATE KEYSPACE sync_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null
68
- " CREATE TABLE sync_test.users ( id UUID PRIMARY KEY, name text )" | " sync_test"
69
- " INSERT INTO sync_test.users (id, name) values (uuid(), 'alice')" | " sync_test"
70
- " SELECT * FROM users where name = 'alice' ALLOW FILTERING" | " sync_test"
69
+ statement | keyspace | renameService
70
+ " DROP KEYSPACE IF EXISTS sync_test" | null | false
71
+ " CREATE KEYSPACE sync_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | true
72
+ " CREATE TABLE sync_test.users ( id UUID PRIMARY KEY, name text )" | " sync_test" | false
73
+ " INSERT INTO sync_test.users (id, name) values (uuid(), 'alice')" | " sync_test" | false
74
+ " SELECT * FROM users where name = 'alice' ALLOW FILTERING" | " sync_test" | true
71
75
}
72
76
73
77
def " test async" () {
74
78
setup :
75
79
Session session = cluster. connect(keyspace)
76
80
runUnderTrace(" parent" ) {
77
- session. executeAsync(statement)
81
+ withConfigOverride(Config . DB_CLIENT_HOST_SPLIT_BY_INSTANCE , " $renameService " ) {
82
+ session. executeAsync(statement)
83
+ }
78
84
blockUntilChildSpansFinished(1 )
79
85
}
80
86
81
87
expect :
82
88
assertTraces(keyspace ? 2 : 1 ) {
83
89
if (keyspace) {
84
90
trace(0 , 1 ) {
85
- cassandraSpan(it, 0 , " USE $keyspace " , null )
91
+ cassandraSpan(it, 0 , " USE $keyspace " , null , false )
86
92
}
87
93
}
88
94
trace(keyspace ? 1 : 0 , 2 ) {
89
95
basicSpan(it, 0 , " parent" )
90
- cassandraSpan(it, 1 , statement, keyspace, span(0 ))
96
+ cassandraSpan(it, 1 , statement, keyspace, renameService, span(0 ))
91
97
}
92
98
}
93
99
94
100
cleanup :
95
101
session. close()
96
102
97
103
where :
98
- statement | keyspace
99
- " DROP KEYSPACE IF EXISTS async_test" | null
100
- " CREATE KEYSPACE async_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null
101
- " CREATE TABLE async_test.users ( id UUID PRIMARY KEY, name text )" | " async_test"
102
- " INSERT INTO async_test.users (id, name) values (uuid(), 'alice')" | " async_test"
103
- " SELECT * FROM users where name = 'alice' ALLOW FILTERING" | " async_test"
104
+ statement | keyspace | renameService
105
+ " DROP KEYSPACE IF EXISTS async_test" | null | false
106
+ " CREATE KEYSPACE async_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | true
107
+ " CREATE TABLE async_test.users ( id UUID PRIMARY KEY, name text )" | " async_test" | false
108
+ " INSERT INTO async_test.users (id, name) values (uuid(), 'alice')" | " async_test" | false
109
+ " SELECT * FROM users where name = 'alice' ALLOW FILTERING" | " async_test" | true
104
110
}
105
111
106
- def cassandraSpan (TraceAssert trace , int index , String statement , String keyspace , Object parentSpan = null , Throwable exception = null ) {
112
+ def cassandraSpan (TraceAssert trace , int index , String statement , String keyspace , boolean renameService , Object parentSpan = null , Throwable exception = null ) {
107
113
trace. span(index) {
108
- serviceName " cassandra"
114
+ serviceName renameService && keyspace ? keyspace : " cassandra"
109
115
operationName " cassandra.query"
110
116
resourceName statement
111
117
spanType DDSpanTypes . CASSANDRA
0 commit comments