Skip to content

Commit 184d40a

Browse files
authored
Add sample for Spring Boot 3 / Jakarta WebFlux (#2564)
1 parent db5bd4e commit 184d40a

File tree

9 files changed

+156
-0
lines changed

9 files changed

+156
-0
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ apiValidation {
6161
"sentry-samples-spring-boot",
6262
"sentry-samples-spring-boot-jakarta",
6363
"sentry-samples-spring-boot-webflux",
64+
"sentry-samples-spring-boot-webflux-jakarta",
6465
"sentry-samples-netflix-dgs",
6566
"sentry-uitest-android",
6667
"sentry-uitest-android-benchmark",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Sentry Sample Spring Boot 3 Webflux
2+
3+
Sample application showing how to use Sentry with [Spring Webflux](https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html) and [Spring boot](http://spring.io/projects/spring-boot).
4+
5+
## How to run?
6+
7+
To see events triggered in this sample application in your Sentry dashboard, go to `src/main/resources/application.properties` and replace the test DSN with your own DSN.
8+
9+
Then, execute a command from the module directory:
10+
11+
```
12+
../../gradlew bootRun
13+
```
14+
15+
Make an HTTP request that will trigger events:
16+
17+
```
18+
curl -XPOST --user user:password http://localhost:8080/person/ -H "Content-Type:application/json" -d '{"firstName":"John","lastName":"Smith"}'
19+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import org.jetbrains.kotlin.config.KotlinCompilerVersion
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3+
4+
plugins {
5+
id(Config.BuildPlugins.springBoot) version Config.springBoot3Version
6+
id(Config.BuildPlugins.springDependencyManagement) version Config.BuildPlugins.springDependencyManagementVersion
7+
kotlin("jvm")
8+
kotlin("plugin.spring") version Config.kotlinVersion
9+
}
10+
11+
group = "io.sentry.sample.spring-boot-webflux-jakarta"
12+
version = "0.0.1-SNAPSHOT"
13+
java.sourceCompatibility = JavaVersion.VERSION_17
14+
java.targetCompatibility = JavaVersion.VERSION_17
15+
16+
repositories {
17+
mavenCentral()
18+
}
19+
20+
dependencies {
21+
implementation(Config.Libs.springBoot3StarterWebflux)
22+
implementation(Config.Libs.kotlinReflect)
23+
implementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION))
24+
implementation(projects.sentrySpringBootStarterJakarta)
25+
implementation(projects.sentryLogback)
26+
testImplementation(Config.Libs.springBoot3StarterTest) {
27+
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
28+
}
29+
}
30+
31+
tasks.withType<Test> {
32+
useJUnitPlatform()
33+
}
34+
35+
tasks.withType<KotlinCompile> {
36+
kotlinOptions {
37+
freeCompilerArgs = listOf("-Xjsr305=strict")
38+
jvmTarget = JavaVersion.VERSION_17.toString()
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.sentry.samples.spring.boot;
2+
3+
public class Person {
4+
private final String firstName;
5+
private final String lastName;
6+
7+
public Person(String firstName, String lastName) {
8+
this.firstName = firstName;
9+
this.lastName = lastName;
10+
}
11+
12+
public String getFirstName() {
13+
return firstName;
14+
}
15+
16+
public String getLastName() {
17+
return lastName;
18+
}
19+
20+
@Override
21+
public String toString() {
22+
return "Person{" + "firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + '}';
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.sentry.samples.spring.boot;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.PathVariable;
7+
import org.springframework.web.bind.annotation.PostMapping;
8+
import org.springframework.web.bind.annotation.RequestBody;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RestController;
11+
import reactor.core.publisher.Mono;
12+
13+
@RestController
14+
@RequestMapping("/person/")
15+
public class PersonController {
16+
private final PersonService personService;
17+
private static final Logger LOGGER = LoggerFactory.getLogger(PersonController.class);
18+
19+
public PersonController(PersonService personService) {
20+
this.personService = personService;
21+
}
22+
23+
@GetMapping("{id}")
24+
Person person(@PathVariable Long id) {
25+
LOGGER.info("Loading person with id={}", id);
26+
throw new IllegalArgumentException("Something went wrong [id=" + id + "]");
27+
}
28+
29+
@PostMapping
30+
Mono<Person> create(@RequestBody Person person) {
31+
return personService.create(person);
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.sentry.samples.spring.boot;
2+
3+
import io.sentry.Sentry;
4+
import java.time.Duration;
5+
import org.springframework.stereotype.Service;
6+
import reactor.core.publisher.Mono;
7+
import reactor.core.scheduler.Schedulers;
8+
9+
@Service
10+
public class PersonService {
11+
12+
Mono<Person> create(Person person) {
13+
return Mono.delay(Duration.ofMillis(100))
14+
.publishOn(Schedulers.boundedElastic())
15+
.doOnNext(__ -> Sentry.captureMessage("Creating person"))
16+
.map(__ -> person);
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.sentry.samples.spring.boot;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class SentryDemoApplication {
8+
public static void main(String[] args) {
9+
SpringApplication.run(SentryDemoApplication.class, args);
10+
}
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard
2+
sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563
3+
sentry.send-default-pii=true
4+
sentry.debug=true
5+
# Sentry Spring Boot integration allows more fine-grained SentryOptions configuration
6+
sentry.max-breadcrumbs=150
7+
# Logback integration configuration options
8+
sentry.logging.minimum-event-level=info
9+
sentry.logging.minimum-breadcrumb-level=debug

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ include(
5454
"sentry-samples:sentry-samples-spring-boot",
5555
"sentry-samples:sentry-samples-spring-boot-jakarta",
5656
"sentry-samples:sentry-samples-spring-boot-webflux",
57+
"sentry-samples:sentry-samples-spring-boot-webflux-jakarta",
5758
"sentry-samples:sentry-samples-netflix-dgs",
5859
"sentry-android-integration-tests:sentry-uitest-android-benchmark",
5960
"sentry-android-integration-tests:sentry-uitest-android",

0 commit comments

Comments
 (0)