Skip to content

Commit 77e2e56

Browse files
committed
Merge the audit fixes from the branches below, and port them to the Boot 2 agent
Ports the tracing and GraphQL checks to the Boot 2 agent suite, and gives the app three minutes to start, as for Boot 3 and 4. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent efed788 commit 77e2e56

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

‎sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/AgentApp.kt‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ class AgentApp(args: List<String> = emptyList()) : Closeable {
4040
args = listOf("--server.port=0") + args,
4141
)
4242

43+
// The agent instruments classes as they load, which on a busy CI runner has taken over a minute.
4344
val restTemplate =
44-
TestRestTemplate(RestTemplateBuilder().rootUri("http://localhost:${app.awaitPort()}"))
45+
TestRestTemplate(
46+
RestTemplateBuilder().rootUri("http://localhost:${app.awaitPort(timeoutSeconds = 180)}")
47+
)
4548

4649
override fun close() {
4750
app.close()

‎sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/DistributedTracingIntegrationTest.kt‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.google.common.truth.Truth.assertThat
44
import io.sentry.SentryEnvelope
55
import io.sentry.protocol.SentryId
66
import io.sentry.test.transaction
7+
import kotlin.random.Random
78
import kotlin.test.Test
89
import org.springframework.http.HttpEntity
910
import org.springframework.http.HttpHeaders
@@ -27,27 +28,27 @@ class DistributedTracingIntegrationTest : IntegrationTest() {
2728
)
2829
assertThat(status).isEqualTo(500)
2930

30-
awaitTransaction("GET /tracing/{id}", traceId)
31+
val incoming = awaitTransaction("GET /tracing/{id}", traceId).transaction()!!
32+
assertThat(incoming.request?.url).endsWith("/tracing/1")
3133
awaitTransaction("GET /person/{id}", traceId)
3234
}
3335

3436
@Test
3537
fun `unsampled trace sends no transactions`() {
3638
val traceId = SentryId()
39+
// An id only this request uses, because a mishandled header could start a trace of its own.
40+
val id = Random.nextLong(2, Long.MAX_VALUE)
3741
val status =
3842
get(
39-
"/tracing/1",
43+
"/tracing/$id",
4044
sentryTrace = "$traceId-424cffc8f94feeee-0",
4145
baggage =
4246
"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",
4347
)
4448
assertThat(status).isEqualTo(500)
4549

4650
// Longer than the 5 seconds the app's spans can wait for their batch to be exported.
47-
server.assertNoEnvelope(millis = 6_000) {
48-
isTransaction(it, "GET /tracing/{id}", traceId) ||
49-
isTransaction(it, "GET /person/{id}", traceId)
50-
}
51+
server.assertNoEnvelope(millis = 6_000) { isForRequest(it, id) }
5152
}
5253

5354
@Test
@@ -64,6 +65,8 @@ class DistributedTracingIntegrationTest : IntegrationTest() {
6465

6566
val incoming = awaitTransaction("GET /tracing/{id}", traceId).header.traceContext!!
6667
val outgoing = awaitTransaction("GET /person/{id}", traceId).header.traceContext!!
68+
assertThat(incoming.traceId).isEqualTo(traceId)
69+
assertThat(outgoing.traceId).isEqualTo(traceId)
6770
assertThat(incoming.sampleRand).isNotNull()
6871
assertThat(outgoing.sampleRand).isEqualTo(incoming.sampleRand)
6972
}
@@ -82,6 +85,8 @@ class DistributedTracingIntegrationTest : IntegrationTest() {
8285

8386
val incoming = awaitTransaction("GET /tracing/{id}", traceId).header.traceContext!!
8487
val outgoing = awaitTransaction("GET /person/{id}", traceId).header.traceContext!!
88+
assertThat(incoming.traceId).isEqualTo(traceId)
89+
assertThat(outgoing.traceId).isEqualTo(traceId)
8590
assertThat(incoming.sampleRate).isNotEqualTo("0.5")
8691
assertThat(outgoing.sampleRate).isEqualTo(incoming.sampleRate)
8792
}
@@ -131,6 +136,12 @@ class DistributedTracingIntegrationTest : IntegrationTest() {
131136
isTransaction(it, name, traceId)
132137
}
133138

139+
/** Whether [envelope] is a transaction for `/tracing/[id]` or the `/person/[id]` it calls. */
140+
private fun isForRequest(envelope: SentryEnvelope, id: Long): Boolean {
141+
val url = envelope.transaction()?.request?.url ?: return false
142+
return url.endsWith("/tracing/$id") || url.endsWith("/person/$id")
143+
}
144+
134145
private fun isTransaction(envelope: SentryEnvelope, name: String, traceId: SentryId): Boolean {
135146
val transaction = envelope.transaction() ?: return false
136147
return transaction.transaction == name && transaction.contexts.trace?.traceId == traceId

‎sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/GraphqlIntegrationTest.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class GraphqlIntegrationTest : IntegrationTest() {
7272
val tasks = response["data"]["tasks"]
7373
assertThat(tasks.size()).isEqualTo(5)
7474
assertThat(tasks[0]["id"].asText()).isEqualTo("T1")
75+
assertThat(tasks[0]["assigneeId"].asText()).isEqualTo("A3")
76+
assertThat(tasks[0]["creatorId"].asText()).isEqualTo("C3")
7577
assertThat(tasks[0]["assignee"]["id"].asText()).isEqualTo("A3")
7678
assertThat(tasks[0]["creator"]["id"].asText()).isEqualTo("C3")
7779

0 commit comments

Comments
 (0)