-
-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathDistributedTracingSystemTest.kt
More file actions
182 lines (148 loc) · 7 KB
/
DistributedTracingSystemTest.kt
File metadata and controls
182 lines (148 loc) · 7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package io.sentry.systemtest
import io.sentry.protocol.SentryId
import io.sentry.samples.spring.boot.jakarta.Person
import io.sentry.systemtest.util.TestHelper
import org.junit.Before
import org.springframework.http.HttpStatus
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
class DistributedTracingSystemTest {
lateinit var testHelper: TestHelper
@Before
fun setup() {
testHelper = TestHelper("http://localhost:8080")
testHelper.reset()
}
@Test
fun `get person distributed tracing`() {
val traceId = SentryId()
val restClient = testHelper.restClient
restClient.getPersonDistributedTracing(
1L,
"$traceId-424cffc8f94feeee-1",
"sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rand=0.456789,sentry-sample_rate=0.5,sentry-sampled=true,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
)
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, restClient.lastKnownStatusCode)
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
transaction.transaction == "GET /tracing/{id}" &&
testHelper.doesTransactionHaveTraceId(transaction, traceId.toString())
}
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
transaction.transaction == "GET /person/{id}" &&
testHelper.doesTransactionHaveTraceId(transaction, traceId.toString())
}
}
@Test
fun `get person distributed tracing with sampled false`() {
val traceId = SentryId()
val restClient = testHelper.restClient
restClient.getPersonDistributedTracing(
1L,
"$traceId-424cffc8f94feeee-0",
"sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rand=0.456789,sentry-sample_rate=0.5,sentry-sampled=false,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
)
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, restClient.lastKnownStatusCode)
testHelper.ensureNoTransactionReceived { transaction, envelopeHeader ->
transaction.transaction == "GET /tracing/{id}"
}
testHelper.ensureNoTransactionReceived { transaction, envelopeHeader ->
transaction.transaction == "GET /person/{id}"
}
}
@Test
fun `get person distributed tracing without sample_rand`() {
val traceId = SentryId()
val restClient = testHelper.restClient
restClient.getPersonDistributedTracing(
1L,
"$traceId-424cffc8f94feeee-1",
"sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rate=0.5,sentry-sampled=true,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
)
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, restClient.lastKnownStatusCode)
var sampleRand1: String? = null
var sampleRand2: String? = null
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
val matches = transaction.transaction == "GET /tracing/{id}" &&
envelopeHeader.traceContext!!.traceId == traceId &&
testHelper.doesTransactionHaveTraceId(transaction, traceId.toString())
if (matches) {
testHelper.logObject(envelopeHeader)
testHelper.logObject(transaction)
sampleRand1 = envelopeHeader.traceContext?.sampleRand
}
matches
}
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
val matches = transaction.transaction == "GET /person/{id}" &&
envelopeHeader.traceContext!!.traceId == traceId &&
testHelper.doesTransactionHaveTraceId(transaction, traceId.toString())
if (matches) {
testHelper.logObject(envelopeHeader)
testHelper.logObject(transaction)
sampleRand2 = envelopeHeader.traceContext?.sampleRand
}
matches
}
assertEquals(sampleRand1, sampleRand2)
}
@Test
fun `get person distributed tracing updates sample_rate on deferred decision`() {
val traceId = SentryId()
val restClient = testHelper.restClient
restClient.getPersonDistributedTracing(
1L,
"$traceId-424cffc8f94feeee",
"sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rate=0.5,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
)
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, restClient.lastKnownStatusCode)
var sampleRate1: String? = null
var sampleRate2: String? = null
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
val matches = transaction.transaction == "GET /tracing/{id}" &&
envelopeHeader.traceContext!!.traceId == traceId &&
testHelper.doesTransactionHaveTraceId(transaction, traceId.toString())
if (matches) {
testHelper.logObject(envelopeHeader)
testHelper.logObject(transaction)
sampleRate1 = envelopeHeader.traceContext?.sampleRate
}
matches
}
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
val matches = transaction.transaction == "GET /person/{id}" &&
envelopeHeader.traceContext!!.traceId == traceId &&
testHelper.doesTransactionHaveTraceId(transaction, traceId.toString())
if (matches) {
testHelper.logObject(envelopeHeader)
testHelper.logObject(transaction)
sampleRate2 = envelopeHeader.traceContext?.sampleRate
}
matches
}
assertEquals(sampleRate1, sampleRate2)
assertNotEquals(sampleRate1, "0.5")
}
@Test
fun `create person distributed tracing`() {
val traceId = SentryId()
val restClient = testHelper.restClient
val person = Person("firstA", "lastB")
val returnedPerson = restClient.createPersonDistributedTracing(
person,
"$traceId-424cffc8f94feeee-1",
"sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rand=0.456789,sentry-sample_rate=0.5,sentry-sampled=true,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
)
assertEquals(HttpStatus.OK, restClient.lastKnownStatusCode)
assertEquals(person.firstName, returnedPerson!!.firstName)
assertEquals(person.lastName, returnedPerson!!.lastName)
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
transaction.transaction == "POST /tracing/" &&
testHelper.doesTransactionHaveTraceId(transaction, traceId.toString())
}
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
transaction.transaction == "POST /person/" &&
testHelper.doesTransactionHaveTraceId(transaction, traceId.toString())
}
}
}