-
-
Notifications
You must be signed in to change notification settings - Fork 461
Extend backend e2e tests #3828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend backend e2e tests #3828
Changes from all commits
efb1564
d11f50a
3c39dac
d3df3eb
628a4af
8653b01
53391cc
29626ed
d40f60c
c4bcd1a
c038019
9e30455
777173a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| # Sentry Sample Spring Boot 3.0+ | ||
|
|
||
| Sample application showing how to use Sentry with [Spring boot](http://spring.io/projects/spring-boot) from version `3.0` onwards. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be good to add the fact, that this is a sample including OTEL, something like: Also, we might want to add some guidance on how to add the otel agent in the readme wdyt?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also add some instructions on how to run the |
||
|
|
||
| ## 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"}' | ||
| ``` | ||
|
|
||
| ## GraphQL | ||
|
|
||
| The following queries can be used to test the GraphQL integration. | ||
|
|
||
| ### Greeting | ||
| ``` | ||
| { | ||
| greeting(name: "crash") | ||
| } | ||
| ``` | ||
|
|
||
| ### Greeting with variables | ||
|
|
||
| ``` | ||
| query GreetingQuery($name: String) { | ||
| greeting(name: $name) | ||
| } | ||
| ``` | ||
| variables: | ||
| ``` | ||
| { | ||
| "name": "crash" | ||
| } | ||
| ``` | ||
|
|
||
| ### Project | ||
|
|
||
| ``` | ||
| query ProjectQuery($slug: ID!) { | ||
| project(slug: $slug) { | ||
| slug | ||
| name | ||
| repositoryUrl | ||
| status | ||
| } | ||
| } | ||
| ``` | ||
| variables: | ||
| ``` | ||
| { | ||
| "slug": "statuscrash" | ||
| } | ||
| ``` | ||
|
|
||
| ### Mutation | ||
|
|
||
| ``` | ||
| mutation AddProjectMutation($slug: ID!) { | ||
| addProject(slug: $slug) | ||
| } | ||
| ``` | ||
| variables: | ||
| ``` | ||
| { | ||
| "slug": "nocrash", | ||
| "name": "nocrash" | ||
| } | ||
| ``` | ||
|
|
||
| ### Subscription | ||
|
|
||
| ``` | ||
| subscription SubscriptionNotifyNewTask($slug: ID!) { | ||
| notifyNewTask(projectSlug: $slug) { | ||
| id | ||
| name | ||
| assigneeId | ||
| assignee { | ||
| id | ||
| name | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| variables: | ||
| ``` | ||
| { | ||
| "slug": "crash" | ||
| } | ||
| ``` | ||
|
|
||
| ### Data loader | ||
|
|
||
| ``` | ||
| query TasksAndAssigneesQuery($slug: ID!) { | ||
| tasks(projectSlug: $slug) { | ||
| id | ||
| name | ||
| assigneeId | ||
| assignee { | ||
| id | ||
| name | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| variables: | ||
| ``` | ||
| { | ||
| "slug": "crash" | ||
| } | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| 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 | ||
| id("com.apollographql.apollo3") version "3.8.2" | ||
| } | ||
|
|
||
| group = "io.sentry.sample.spring-boot-jakarta" | ||
| version = "0.0.1-SNAPSHOT" | ||
| java.sourceCompatibility = JavaVersion.VERSION_17 | ||
| java.targetCompatibility = JavaVersion.VERSION_17 | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| configure<JavaPluginExtension> { | ||
| sourceCompatibility = JavaVersion.VERSION_17 | ||
| targetCompatibility = JavaVersion.VERSION_17 | ||
| } | ||
|
|
||
| tasks.withType<KotlinCompile>().configureEach { | ||
| kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString() | ||
| } | ||
|
|
||
| tasks.withType<KotlinCompile> { | ||
| kotlinOptions { | ||
| freeCompilerArgs = listOf("-Xjsr305=strict") | ||
| jvmTarget = JavaVersion.VERSION_17.toString() | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(Config.Libs.springBoot3StarterSecurity) | ||
| implementation(Config.Libs.springBoot3StarterActuator) | ||
| implementation(Config.Libs.springBoot3StarterWeb) | ||
| implementation(Config.Libs.springBoot3StarterWebsocket) | ||
| implementation(Config.Libs.springBoot3StarterGraphql) | ||
| implementation(Config.Libs.springBoot3StarterQuartz) | ||
| implementation(Config.Libs.springBoot3StarterWebflux) | ||
| implementation(Config.Libs.springBoot3StarterAop) | ||
| implementation(Config.Libs.aspectj) | ||
| implementation(Config.Libs.springBoot3Starter) | ||
| implementation(Config.Libs.kotlinReflect) | ||
| implementation(Config.Libs.springBootStarterJdbc) | ||
| implementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION)) | ||
| implementation(projects.sentrySpringBootStarterJakarta) | ||
| implementation(projects.sentryLogback) | ||
| implementation(projects.sentryGraphql22) | ||
| implementation(projects.sentryQuartz) | ||
| implementation(Config.Libs.OpenTelemetry.otelSdk) | ||
|
|
||
| // database query tracing | ||
| implementation(projects.sentryJdbc) | ||
| runtimeOnly(Config.TestLibs.hsqldb) | ||
| testImplementation(Config.Libs.springBoot3StarterTest) { | ||
| exclude(group = "org.junit.vintage", module = "junit-vintage-engine") | ||
| } | ||
| testImplementation(kotlin(Config.kotlinStdLib)) | ||
| testImplementation(Config.TestLibs.kotlinTestJunit) | ||
| testImplementation("ch.qos.logback:logback-classic:1.3.5") | ||
| testImplementation(Config.Libs.slf4jApi2) | ||
| testImplementation(Config.Libs.apolloKotlin) | ||
| } | ||
|
|
||
| configure<SourceSetContainer> { | ||
| test { | ||
| java.srcDir("src/test/java") | ||
| } | ||
| } | ||
|
|
||
| tasks.register<Test>("systemTest").configure { | ||
| group = "verification" | ||
| description = "Runs the System tests" | ||
|
|
||
| // maxParallelForks = Runtime.getRuntime().availableProcessors() / 2 | ||
| maxParallelForks = 1 | ||
|
|
||
| // Cap JVM args per test | ||
| minHeapSize = "128m" | ||
| maxHeapSize = "1g" | ||
|
|
||
| filter { | ||
| includeTestsMatching("io.sentry.systemtest*") | ||
| } | ||
| } | ||
|
|
||
| tasks.named("test").configure { | ||
| require(this is Test) | ||
|
|
||
| filter { | ||
| excludeTestsMatching("io.sentry.systemtest.*") | ||
| } | ||
| } | ||
|
|
||
| apollo { | ||
| service("service") { | ||
| srcDir("src/test/graphql") | ||
| packageName.set("io.sentry.samples.graphql") | ||
| outputDirConnection { | ||
| connectToKotlinSourceSet("test") | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package io.sentry.samples.spring.boot.jakarta; | ||
|
|
||
| import io.sentry.EventProcessor; | ||
| import io.sentry.Hint; | ||
| import io.sentry.SentryEvent; | ||
| import io.sentry.protocol.SentryRuntime; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.springframework.boot.SpringBootVersion; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** | ||
| * Custom {@link EventProcessor} implementation lets modifying {@link SentryEvent}s before they are | ||
| * sent to Sentry. | ||
| */ | ||
| @Component | ||
| public class CustomEventProcessor implements EventProcessor { | ||
| private final String springBootVersion; | ||
|
|
||
| public CustomEventProcessor(String springBootVersion) { | ||
| this.springBootVersion = springBootVersion; | ||
| } | ||
|
|
||
| public CustomEventProcessor() { | ||
| this(SpringBootVersion.getVersion()); | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) { | ||
| final SentryRuntime runtime = new SentryRuntime(); | ||
| runtime.setVersion(springBootVersion); | ||
| runtime.setName("Spring Boot"); | ||
| event.getContexts().setRuntime(runtime); | ||
| return event; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package io.sentry.samples.spring.boot.jakarta; | ||
|
|
||
| import io.sentry.spring.jakarta.checkin.SentryCheckIn; | ||
| import io.sentry.spring.jakarta.tracing.SentryTransaction; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** | ||
| * {@link SentryTransaction} added on the class level, creates transaction around each method | ||
| * execution of every method of the annotated class. | ||
| */ | ||
| @Component | ||
| @SentryTransaction(operation = "scheduled") | ||
| public class CustomJob { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(CustomJob.class); | ||
|
|
||
| @SentryCheckIn("monitor_slug_1") | ||
| @Scheduled(fixedRate = 3 * 60 * 1000L) | ||
| void execute() throws InterruptedException { | ||
| LOGGER.info("Executing scheduled job"); | ||
| Thread.sleep(2000L); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package io.sentry.samples.spring.boot.jakarta; | ||
|
|
||
| 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 + '\'' + '}'; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentry Sample Spring Boot 3.0+ and OpenTelemetry