-
-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sample for Spring Boot 3 / Jakarta WebFlux (#2564)
- Loading branch information
Showing
9 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
sentry-samples/sentry-samples-spring-boot-webflux-jakarta/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Sentry Sample Spring Boot 3 Webflux | ||
|
||
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). | ||
|
||
## How to run? | ||
|
||
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. | ||
|
||
Then, execute a command from the module directory: | ||
|
||
``` | ||
../../gradlew bootRun | ||
``` | ||
|
||
Make an HTTP request that will trigger events: | ||
|
||
``` | ||
curl -XPOST --user user:password http://localhost:8080/person/ -H "Content-Type:application/json" -d '{"firstName":"John","lastName":"Smith"}' | ||
``` |
40 changes: 40 additions & 0 deletions
40
sentry-samples/sentry-samples-spring-boot-webflux-jakarta/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import org.jetbrains.kotlin.config.KotlinCompilerVersion | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
id(Config.BuildPlugins.springBoot) version Config.springBoot3Version | ||
id(Config.BuildPlugins.springDependencyManagement) version Config.BuildPlugins.springDependencyManagementVersion | ||
kotlin("jvm") | ||
kotlin("plugin.spring") version Config.kotlinVersion | ||
} | ||
|
||
group = "io.sentry.sample.spring-boot-webflux-jakarta" | ||
version = "0.0.1-SNAPSHOT" | ||
java.sourceCompatibility = JavaVersion.VERSION_17 | ||
java.targetCompatibility = JavaVersion.VERSION_17 | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation(Config.Libs.springBoot3StarterWebflux) | ||
implementation(Config.Libs.kotlinReflect) | ||
implementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION)) | ||
implementation(projects.sentrySpringBootStarterJakarta) | ||
implementation(projects.sentryLogback) | ||
testImplementation(Config.Libs.springBoot3StarterTest) { | ||
exclude(group = "org.junit.vintage", module = "junit-vintage-engine") | ||
} | ||
} | ||
|
||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} | ||
|
||
tasks.withType<KotlinCompile> { | ||
kotlinOptions { | ||
freeCompilerArgs = listOf("-Xjsr305=strict") | ||
jvmTarget = JavaVersion.VERSION_17.toString() | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...mples-spring-boot-webflux-jakarta/src/main/java/io/sentry/samples/spring/boot/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.sentry.samples.spring.boot; | ||
|
||
public class Person { | ||
private final String firstName; | ||
private final String lastName; | ||
|
||
public Person(String firstName, String lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Person{" + "firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + '}'; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ng-boot-webflux-jakarta/src/main/java/io/sentry/samples/spring/boot/PersonController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.sentry.samples.spring.boot; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RestController | ||
@RequestMapping("/person/") | ||
public class PersonController { | ||
private final PersonService personService; | ||
private static final Logger LOGGER = LoggerFactory.getLogger(PersonController.class); | ||
|
||
public PersonController(PersonService personService) { | ||
this.personService = personService; | ||
} | ||
|
||
@GetMapping("{id}") | ||
Person person(@PathVariable Long id) { | ||
LOGGER.info("Loading person with id={}", id); | ||
throw new IllegalArgumentException("Something went wrong [id=" + id + "]"); | ||
} | ||
|
||
@PostMapping | ||
Mono<Person> create(@RequestBody Person person) { | ||
return personService.create(person); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...pring-boot-webflux-jakarta/src/main/java/io/sentry/samples/spring/boot/PersonService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.sentry.samples.spring.boot; | ||
|
||
import io.sentry.Sentry; | ||
import java.time.Duration; | ||
import org.springframework.stereotype.Service; | ||
import reactor.core.publisher.Mono; | ||
import reactor.core.scheduler.Schedulers; | ||
|
||
@Service | ||
public class PersonService { | ||
|
||
Mono<Person> create(Person person) { | ||
return Mono.delay(Duration.ofMillis(100)) | ||
.publishOn(Schedulers.boundedElastic()) | ||
.doOnNext(__ -> Sentry.captureMessage("Creating person")) | ||
.map(__ -> person); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ot-webflux-jakarta/src/main/java/io/sentry/samples/spring/boot/SentryDemoApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.sentry.samples.spring.boot; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class SentryDemoApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(SentryDemoApplication.class, args); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ples/sentry-samples-spring-boot-webflux-jakarta/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard | ||
sentry.dsn=https://[email protected]/5428563 | ||
sentry.send-default-pii=true | ||
sentry.debug=true | ||
# Sentry Spring Boot integration allows more fine-grained SentryOptions configuration | ||
sentry.max-breadcrumbs=150 | ||
# Logback integration configuration options | ||
sentry.logging.minimum-event-level=info | ||
sentry.logging.minimum-breadcrumb-level=debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters