-
-
Notifications
You must be signed in to change notification settings - Fork 459
Add new modules for Spring 7 and Spring Boot 4 #4601
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
Merged
adinauer
merged 18 commits into
main
from
08-04-add_new_modules_for_spring_7_and_spring_boot_4
Aug 26, 2025
Merged
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3ec789b
Add new modules for Spring 7 and Spring Boot 4
adinauer ddeada2
Fix Spring 7 and Spring Boot 4 modules (#4602)
adinauer 1b6c6e0
Merge branch 'main' into 08-04-add_new_modules_for_spring_7_and_sprin…
adinauer 59cb440
Attempt to fix kotlin 2.2 issue (#4603)
adinauer a18e719
Merge branch 'main' into 08-04-add_new_modules_for_spring_7_and_sprin…
adinauer 975f6c7
changelog
adinauer 47b3629
Merge branch 'main' into 08-04-add_new_modules_for_spring_7_and_sprin…
adinauer 36e68d4
Merge branch 'main' into 08-04-add_new_modules_for_spring_7_and_sprin…
adinauer 1ae3d92
fix ci
adinauer fe36a4e
add ignored span origins for Spring 7 and Spring Boot 4
adinauer d3164a3
move changelog
adinauer ff7c269
Merge branch 'main' into 08-04-add_new_modules_for_spring_7_and_sprin…
adinauer 9634d01
Merge branch 'main' into 08-04-add_new_modules_for_spring_7_and_sprin…
adinauer 65ed9c6
Example how to fix version mismatch (#4642)
alexander-alderman-webb a1438d0
Fix ignored span origin
adinauer ac1b238
Merge branch 'main' into 08-04-add_new_modules_for_spring_7_and_sprin…
adinauer 41946bf
Merge branch 'main' into 08-04-add_new_modules_for_spring_7_and_sprin…
adinauer 5535263
move changelog
adinauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 6.0+ | ||
|
||
Sample application showing how to use Sentry with [Spring](http://spring.io/) from version `6.0` onwards. | ||
|
||
## How to run? | ||
|
||
To see events triggered in this sample application in your Sentry dashboard, go to `src/main/java/io/sentry/samples/spring/jakarta/SentryConfig.java` and replace the test DSN with your own DSN. | ||
|
||
Then, execute a command from the module directory: | ||
|
||
``` | ||
../../gradlew appRun | ||
``` | ||
|
||
Make an HTTP request that will trigger events: | ||
|
||
``` | ||
curl -XPOST --user user:password http://localhost:8080/sentry-samples-spring-jakarta/person/ -H "Content-Type:application/json" -d '{"firstName":"John","lastName":"Smith"}' | ||
``` |
This file contains hidden or 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,52 @@ | ||
import org.jetbrains.kotlin.config.KotlinCompilerVersion | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
import org.springframework.boot.gradle.plugin.SpringBootPlugin | ||
|
||
plugins { | ||
alias(libs.plugins.springboot4) apply false | ||
alias(libs.plugins.spring.dependency.management) | ||
kotlin("jvm") | ||
alias(libs.plugins.kotlin.spring) | ||
id("war") | ||
alias(libs.plugins.gretty) | ||
} | ||
|
||
group = "io.sentry.sample.spring-7" | ||
|
||
version = "0.0.1-SNAPSHOT" | ||
|
||
java.sourceCompatibility = JavaVersion.VERSION_17 | ||
|
||
java.targetCompatibility = JavaVersion.VERSION_17 | ||
|
||
repositories { mavenCentral() } | ||
|
||
dependencyManagement { imports { mavenBom(SpringBootPlugin.BOM_COORDINATES) } } | ||
|
||
dependencies { | ||
implementation(Config.Libs.springWeb) | ||
implementation(Config.Libs.springAop) | ||
implementation(Config.Libs.aspectj) | ||
implementation(Config.Libs.springSecurityWeb) | ||
implementation(Config.Libs.springSecurityConfig) | ||
implementation(Config.Libs.kotlinReflect) | ||
implementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION)) | ||
implementation(projects.sentrySpring7) | ||
implementation(projects.sentryLogback) | ||
implementation(libs.jackson.databind) | ||
implementation(libs.logback.classic) | ||
implementation(libs.servlet.jakarta.api) | ||
implementation(libs.slf4j2.api) | ||
testImplementation(libs.springboot.starter.test) { | ||
exclude(group = "org.junit.vintage", module = "junit-vintage-engine") | ||
} | ||
} | ||
|
||
tasks.withType<Test>().configureEach { useJUnitPlatform() } | ||
|
||
tasks.withType<KotlinCompile>().configureEach { | ||
kotlinOptions { | ||
freeCompilerArgs = listOf("-Xjsr305=strict") | ||
jvmTarget = JavaVersion.VERSION_17.toString() | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...les/sentry-samples-spring-7/src/main/java/io/sentry/samples/spring/jakarta/AppConfig.java
This file contains hidden or 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,20 @@ | ||
package io.sentry.samples.spring.jakarta; | ||
|
||
import io.sentry.IScopes; | ||
import io.sentry.spring.jakarta.SentryUserFilter; | ||
import io.sentry.spring.jakarta.SentryUserProvider; | ||
import java.util.List; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@Configuration | ||
@Import(SentryConfig.class) | ||
public class AppConfig { | ||
|
||
@Bean | ||
SentryUserFilter sentryUserFilter( | ||
final IScopes scopes, final List<SentryUserProvider> sentryUserProviders) { | ||
return new SentryUserFilter(scopes, sentryUserProviders); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...entry-samples-spring-7/src/main/java/io/sentry/samples/spring/jakarta/AppInitializer.java
This file contains hidden or 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,45 @@ | ||
package io.sentry.samples.spring.jakarta; | ||
|
||
import io.sentry.spring.jakarta.tracing.SentryTracingFilter; | ||
import jakarta.servlet.Filter; | ||
import org.springframework.web.filter.DelegatingFilterProxy; | ||
import org.springframework.web.filter.RequestContextFilter; | ||
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; | ||
|
||
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { | ||
|
||
@Override | ||
protected String[] getServletMappings() { | ||
return new String[] {"/*"}; | ||
} | ||
|
||
@Override | ||
protected Class<?>[] getRootConfigClasses() { | ||
return new Class<?>[] {AppConfig.class, SecurityConfiguration.class}; | ||
} | ||
|
||
@Override | ||
protected Class<?>[] getServletConfigClasses() { | ||
return new Class<?>[] {WebConfig.class}; | ||
} | ||
|
||
@Override | ||
protected Filter[] getServletFilters() { | ||
// creates Sentry transactions around incoming HTTP requests | ||
SentryTracingFilter sentryTracingFilter = new SentryTracingFilter(); | ||
|
||
// filter required by Spring Security | ||
DelegatingFilterProxy springSecurityFilterChain = new DelegatingFilterProxy(); | ||
springSecurityFilterChain.setTargetBeanName("springSecurityFilterChain"); | ||
// sets request on RequestContextHolder | ||
RequestContextFilter requestContextFilter = new RequestContextFilter(); | ||
|
||
// sets Sentry user on the scope | ||
DelegatingFilterProxy sentryUserFilterProxy = new DelegatingFilterProxy(); | ||
sentryUserFilterProxy.setTargetBeanName("sentryUserFilter"); | ||
|
||
return new Filter[] { | ||
sentryTracingFilter, springSecurityFilterChain, requestContextFilter, sentryUserFilterProxy | ||
}; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...amples-spring-7/src/main/java/io/sentry/samples/spring/jakarta/SecurityConfiguration.java
This file contains hidden or 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,42 @@ | ||
package io.sentry.samples.spring.jakarta; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.core.userdetails.User; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.security.crypto.factory.PasswordEncoderFactories; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.security.provisioning.InMemoryUserDetailsManager; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
public class SecurityConfiguration { | ||
|
||
// this API is meant to be consumed by non-browser clients thus the CSRF protection is not needed. | ||
@SuppressWarnings({"lgtm[java/spring-disabled-csrf-protection]", "removal"}) | ||
@Bean | ||
public SecurityFilterChain filterChain(final @NotNull HttpSecurity http) throws Exception { | ||
http.csrf().disable().authorizeHttpRequests().anyRequest().authenticated().and().httpBasic(); | ||
|
||
return http.build(); | ||
} | ||
|
||
@Bean | ||
public @NotNull InMemoryUserDetailsManager userDetailsService() { | ||
final PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder(); | ||
|
||
final UserDetails user = | ||
User.builder() | ||
.passwordEncoder(encoder::encode) | ||
.username("user") | ||
.password("password") | ||
.roles("USER") | ||
.build(); | ||
|
||
return new InMemoryUserDetailsManager(user); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
.../sentry-samples-spring-7/src/main/java/io/sentry/samples/spring/jakarta/SentryConfig.java
This file contains hidden or 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,37 @@ | ||
package io.sentry.samples.spring.jakarta; | ||
|
||
import io.sentry.SentryOptions; | ||
import io.sentry.SentryOptions.TracesSamplerCallback; | ||
import io.sentry.spring.jakarta.EnableSentry; | ||
import io.sentry.spring.jakarta.tracing.SentryTracingConfiguration; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Import; | ||
|
||
// NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry | ||
// project/dashboard | ||
@EnableSentry( | ||
dsn = "https://[email protected]/5428563", | ||
sendDefaultPii = true, | ||
maxRequestBodySize = SentryOptions.RequestSize.MEDIUM) | ||
@Import(SentryTracingConfiguration.class) | ||
public class SentryConfig { | ||
|
||
/** | ||
* Configures callback used to determine if transaction should be sampled. | ||
* | ||
* @return traces sampler callback | ||
*/ | ||
@Bean | ||
TracesSamplerCallback tracesSamplerCallback() { | ||
return samplingContext -> { | ||
HttpServletRequest request = | ||
(HttpServletRequest) samplingContext.getCustomSamplingContext().get("request"); | ||
if ("/error".equals(request.getRequestURI())) { | ||
return 0.5d; | ||
} else { | ||
return 1.0d; | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is there a reason this sample was not added before to the
system-tests-backend
(since the sample is not added by this PR)?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.
Good catch, this shouldn't be here. It's a duplicate since it's already there: