Skip to content

Commit be877be

Browse files
runningcodeclaude
andauthored
test(spring-boot): [Sample Tests 7] Move the Boot 3 tracing and HTTP client tests (#6293)
* test(spring-boot): Move the Boot 3 tracing and HTTP client tests into the module Ports the jakarta sample's DistributedTracingSystemTest and TodoSystemTest to the integrationTest suite. The app calls itself on its random port instead of a hardcoded localhost:8080, and serves the todo the sample fetched from jsonplaceholder.typicode.com, so the tests no longer need the internet. Adds MockSentryServer.assertNoEnvelope for the unsampled case. A flush can't prove an absence because the server may finish its transaction after the client already has the response, so it watches for a short window instead of the old 10s sleep. The suite declares context-propagation explicitly: without it Reactor can't carry the Sentry scope to the WebClient's thread. The sample only had it because Spring GraphQL pulls it in. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(spring-boot): Tighten the Boot 3 tracing checks and use a plain test client The unsampled-trace test now sends a request with an id of its own and rejects any transaction for it, whatever its trace, so a mishandled header that starts a new trace fails it. The sampled test checks that transactions carry their request, which that relies on. The sample_rand and deferred-sampling tests also check the envelope header's trace ID, as the sample's tests did. That check showed that the context's TestRestTemplate, built from the RestTemplateBuilder Sentry customizes, added trace headers of its own to the requests the tests sent. The suite now uses one built outside the context. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent aa51872 commit be877be

11 files changed

Lines changed: 363 additions & 277 deletions

File tree

‎sentry-samples/sentry-samples-spring-boot-jakarta/src/test/kotlin/io/sentry/systemtest/DistributedTracingSystemTest.kt‎

Lines changed: 0 additions & 197 deletions
This file was deleted.

‎sentry-samples/sentry-samples-spring-boot-jakarta/src/test/kotlin/io/sentry/systemtest/TodoSystemTest.kt‎

Lines changed: 0 additions & 77 deletions
This file was deleted.

‎sentry-spring-boot-jakarta/build.gradle.kts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,20 @@ testing {
180180
implementation(projects.sentryAsyncProfiler)
181181
implementation(projects.sentryJdbc)
182182
implementation(projects.sentryLogback)
183+
implementation(projects.sentryOkhttp)
183184
implementation(projects.sentryTestSupport)
185+
// Reactor's automatic context propagation needs it to carry the Sentry scope across
186+
// threads.
187+
// The sample only had it because Spring GraphQL pulls it in.
188+
implementation(libs.context.propagation)
184189
implementation(libs.kotlin.test.junit)
185190
implementation(libs.google.truth)
191+
implementation(libs.okhttp)
186192
implementation(libs.springboot3.starter.aop)
187193
implementation(libs.springboot3.starter.jdbc)
188194
implementation(libs.springboot3.starter.test)
189195
implementation(libs.springboot3.starter.web)
196+
implementation(libs.springboot3.starter.webflux)
190197
runtimeOnly(libs.hsqldb)
191198
}
192199
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.sentry.spring.boot.jakarta.integrationtest
2+
3+
import org.springframework.web.bind.annotation.GetMapping
4+
import org.springframework.web.bind.annotation.PathVariable
5+
import org.springframework.web.bind.annotation.PostMapping
6+
import org.springframework.web.bind.annotation.RequestBody
7+
import org.springframework.web.bind.annotation.RequestMapping
8+
import org.springframework.web.bind.annotation.RestController
9+
import org.springframework.web.client.RestClient
10+
11+
/** Forwards to this app's own Person endpoints, so a trace continues through outgoing requests. */
12+
@RestController
13+
@RequestMapping("/tracing/")
14+
open class DistributedTracingController(private val restClient: RestClient) {
15+
@GetMapping("{id}")
16+
open fun person(@PathVariable("id") id: Long): Person? =
17+
restClient.get().uri(selfUrl("/person/$id")).retrieve().body(Person::class.java)
18+
19+
@PostMapping
20+
open fun create(@RequestBody person: Person): Person? =
21+
restClient.post().uri(selfUrl("/person/")).body(person).retrieve().body(Person::class.java)
22+
}

0 commit comments

Comments
 (0)