Skip to content

Commit

Permalink
Update Spring Boot Jakarta to Spring Boot 3.0.0-RC2 (#2347)
Browse files Browse the repository at this point in the history
Co-authored-by: Maciej Walkowiak <walkowiak.maciej@yahoo.com>
Co-authored-by: Lukas Bloder <lukas.bloder@gmail.com>
Co-authored-by: Alexander Dinauer <alexander.dinauer@sentry.io>
Co-authored-by: Alexander Dinauer <adinauer@users.noreply.github.com>
Co-authored-by: getsentry-bot <bot@sentry.io>
Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
  • Loading branch information
6 people authored Nov 11, 2022
1 parent 51e7326 commit 38e4f11
Show file tree
Hide file tree
Showing 24 changed files with 125 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ jobs:
config: sentry-android-integration-tests/metrics-test.yml
sauce-user: ${{ secrets.SAUCE_USERNAME }}
sauce-key: ${{ secrets.SAUCE_ACCESS_KEY }}
if: env.SAUCE_USERNAME != null
if: env.SAUCE_USERNAME != null
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Fix `Gpu.vendorId` should be a String ([#2343](https://github.com/getsentry/sentry-java/pull/2343))

### Features

- Update Spring Boot Jakarta to Spring Boot 3.0.0-RC2 ([#2347](https://github.com/getsentry/sentry-java/pull/2347))

## 6.7.0

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object Config {
val kotlinStdLib = "stdlib-jdk8"

val springBootVersion = "2.7.4"
val springBoot3Version = "3.0.0-M5"
val springBoot3Version = "3.0.0-RC2"
val kotlinCompatibleLanguageVersion = "1.4"

val composeVersion = "1.1.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ tasks.withType<KotlinCompile> {
}
}

tasks.withType<JavaCompile> {
options.compilerArgs.add("-Xlint:-deprecation")
}

task("jakartaTransformation", JavaExec::class) {
main = "org.eclipse.transformer.cli.JakartaTransformerCLI"
classpath = configurations.getByName("jakartaTransform") // sourceSets["main"].compileClasspath
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.sentry.samples.spring.boot.jakarta;

import io.sentry.ISpan;
import io.sentry.Sentry;
import io.sentry.spring.jakarta.tracing.SentrySpan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -16,12 +18,19 @@ public class PersonService {
private static final Logger LOGGER = LoggerFactory.getLogger(PersonService.class);

private final JdbcTemplate jdbcTemplate;
private int createCount = 0;

public PersonService(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}

Person create(Person person) {
createCount++;
final ISpan span = Sentry.getSpan();
if (span != null) {
span.setMeasurement("create_count", createCount);
}

jdbcTemplate.update(
"insert into person (firstName, lastName) values (?, ?)",
person.getFirstName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
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.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
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
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
public class SecurityConfiguration {

// this API is meant to be consumed by non-browser clients thus the CSRF protection is not needed.
@Override
@SuppressWarnings("lgtm[java/spring-disabled-csrf-protection]")
protected void configure(final @NotNull HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests().anyRequest().authenticated().and().httpBasic();
@Bean
public SecurityFilterChain filterChain(final @NotNull HttpSecurity http) throws Exception {
http.csrf().disable().authorizeHttpRequests().anyRequest().authenticated().and().httpBasic();

return http.build();
}

@Bean
@Override
public @NotNull UserDetailsService userDetailsService() {
public @NotNull InMemoryUserDetailsManager userDetailsService() {
final PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();

final UserDetails user =
Expand Down
4 changes: 0 additions & 4 deletions sentry-samples/sentry-samples-spring-jakarta/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,3 @@ task("jakartaTransformation", JavaExec::class) {
classpath = configurations.getByName("jakartaTransform") // sourceSets["main"].compileClasspath
args = listOf("../sentry-samples-spring/src/main/java/io/sentry/samples/spring", "src/main/java/io/sentry/samples/spring/jakarta", "-o", "-tf", "sentry-jakarta-text-master.properties")
}

tasks.withType<JavaCompile> {
options.compilerArgs.add("-Xlint:-deprecation")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,27 @@
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.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
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 extends WebSecurityConfigurerAdapter {
public class SecurityConfiguration {

// this API is meant to be consumed by non-browser clients thus the CSRF protection is not needed.
@Override
@SuppressWarnings("lgtm[java/spring-disabled-csrf-protection]")
protected void configure(final @NotNull HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests().anyRequest().authenticated().and().httpBasic();
@Bean
public SecurityFilterChain filterChain(final @NotNull HttpSecurity http) throws Exception {
http.csrf().disable().authorizeHttpRequests().anyRequest().authenticated().and().httpBasic();

return http.build();
}

@Bean
@Override
public @NotNull UserDetailsService userDetailsService() {
public @NotNull InMemoryUserDetailsManager userDetailsService() {
final PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();

final UserDetails user =
Expand Down
3 changes: 1 addition & 2 deletions sentry-spring-boot-starter-jakarta/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import com.android.build.gradle.internal.tasks.factory.dependsOn
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
import net.ltgt.gradle.errorprone.errorprone
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand Down Expand Up @@ -128,7 +127,7 @@ task("jakartaMainClassTransformation", JavaExec::class) {
args = listOf("../sentry-spring-boot-starter/src/test/kotlin/com/acme", "src/test/kotlin/com/acme", "-o", "-tf", "sentry-jakarta-text-master.properties")
}

tasks.named("build").dependsOn("jakartaTransformation")
// tasks.named("build").dependsOn("jakartaTransformation")

buildConfig {
useJavaOutput()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.sentry.checkTransaction
import io.sentry.spring.jakarta.tracing.SentrySpan
import io.sentry.transport.ITransport
import org.assertj.core.api.Assertions.assertThat
import org.junit.Ignore
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.anyOrNull
Expand All @@ -32,21 +33,19 @@ import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
import org.springframework.security.core.userdetails.User
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.security.core.userdetails.UserDetailsService
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
import org.springframework.stereotype.Service
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RestController
import java.lang.RuntimeException
import kotlin.test.BeforeTest
import kotlin.test.Test

Expand Down Expand Up @@ -270,17 +269,10 @@ open class HelloService {
}

@Configuration
open class SecurityConfiguration : WebSecurityConfigurerAdapter() {

override fun configure(http: HttpSecurity) {
http.csrf().disable()
.authorizeRequests().anyRequest().authenticated()
.and()
.httpBasic()
}
open class SecurityConfiguration {

@Bean
override fun userDetailsService(): UserDetailsService {
open fun userDetailsService(): InMemoryUserDetailsManager {
val encoder: PasswordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder()
val user: UserDetails = User
.builder()
Expand All @@ -291,6 +283,17 @@ open class SecurityConfiguration : WebSecurityConfigurerAdapter() {
.build()
return InMemoryUserDetailsManager(user)
}

@Bean
@Throws(Exception::class)
open fun filterChain(http: HttpSecurity): SecurityFilterChain {
http.csrf().disable()
.authorizeRequests().anyRequest().authenticated()
.and()
.httpBasic()

return http.build()
}
}

class CustomException(message: String) : RuntimeException(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,19 @@ import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
import org.springframework.security.core.userdetails.User
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.security.core.userdetails.UserDetailsService
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
import org.springframework.stereotype.Service
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RestController
import java.lang.RuntimeException
import kotlin.test.BeforeTest
import kotlin.test.Test

Expand Down Expand Up @@ -270,17 +268,10 @@ open class HelloService {
}

@Configuration
open class SecurityConfiguration : WebSecurityConfigurerAdapter() {

override fun configure(http: HttpSecurity) {
http.csrf().disable()
.authorizeRequests().anyRequest().authenticated()
.and()
.httpBasic()
}
open class SecurityConfiguration {

@Bean
override fun userDetailsService(): UserDetailsService {
open fun userDetailsService(): InMemoryUserDetailsManager {
val encoder: PasswordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder()
val user: UserDetails = User
.builder()
Expand All @@ -291,6 +282,17 @@ open class SecurityConfiguration : WebSecurityConfigurerAdapter() {
.build()
return InMemoryUserDetailsManager(user)
}

@Bean
@Throws(Exception::class)
open fun filterChain(http: HttpSecurity): SecurityFilterChain {
http.csrf().disable()
.authorizeRequests().anyRequest().authenticated()
.and()
.httpBasic()

return http.build()
}
}

class CustomException(message: String) : RuntimeException(message)
Expand Down
13 changes: 5 additions & 8 deletions sentry-spring-jakarta/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import com.android.build.gradle.internal.tasks.factory.dependsOn
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
import net.ltgt.gradle.errorprone.errorprone
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.springframework.boot.gradle.plugin.SpringBootPlugin


plugins {
Expand All @@ -19,9 +20,9 @@ repositories {
maven { url = uri("https://repo.spring.io/milestone") }
}

the<io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension>().apply {
the<DependencyManagementExtension>().apply {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:${Config.springBoot3Version}")
mavenBom(SpringBootPlugin.BOM_COORDINATES)
}
}

Expand Down Expand Up @@ -108,10 +109,6 @@ tasks {
}
}

tasks.withType<JavaCompile> {
options.compilerArgs.add("-Xlint:-deprecation")
}

task("jakartaTransformation", JavaExec::class) {
main = "org.eclipse.transformer.cli.JakartaTransformerCLI"
classpath = configurations.getByName("jakartaTransform") // sourceSets["main"].compileClasspath
Expand All @@ -124,7 +121,7 @@ task("jakartaTestTransformation", JavaExec::class) {
args = listOf("../sentry-spring/src/test/kotlin/io/sentry/spring", "src/test/kotlin/io/sentry/spring/jakarta", "-o", "-tf", "sentry-jakarta-text-master.properties")
}

tasks.named("build").dependsOn("jakartaTransformation")
// tasks.named("build").dependsOn("jakartaTransformation")

buildConfig {
useJavaOutput()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public SentrySpanClientHttpRequestInterceptor(final @NotNull IHub hub) {
}

final ISpan span = activeSpan.startChild("http.client");
span.setDescription(request.getMethodValue() + " " + request.getURI());
final String methodName =
request.getMethod() != null ? request.getMethod().name() : "unknown";
span.setDescription(methodName + " " + request.getURI());

final SentryTraceHeader sentryTraceHeader = span.toSentryTrace();

Expand All @@ -63,8 +65,8 @@ public SentrySpanClientHttpRequestInterceptor(final @NotNull IHub hub) {
try {
response = execution.execute(request, body);
// handles both success and error responses
span.setStatus(SpanStatus.fromHttpStatusCode(response.getRawStatusCode()));
responseStatusCode = response.getRawStatusCode();
span.setStatus(SpanStatus.fromHttpStatusCode(response.getStatusCode().value()));
responseStatusCode = response.getStatusCode().value();
return response;
} catch (Throwable e) {
// handles cases like connection errors
Expand All @@ -84,8 +86,10 @@ private void addBreadcrumb(
final @NotNull byte[] body,
final @Nullable Integer responseStatusCode,
final @Nullable ClientHttpResponse response) {
final String methodName = request.getMethod() != null ? request.getMethod().name() : "unknown";

final Breadcrumb breadcrumb =
Breadcrumb.http(request.getURI().toString(), request.getMethodValue(), responseStatusCode);
Breadcrumb.http(request.getURI().toString(), methodName, responseStatusCode);
breadcrumb.setData("request_body_size", body.length);

final Hint hint = new Hint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public SentrySpanClientWebRequestFilter(final @NotNull IHub hub) {
return next.exchange(clientRequestWithSentryTraceHeader)
.flatMap(
response -> {
span.setStatus(SpanStatus.fromHttpStatusCode(response.rawStatusCode()));
span.setStatus(SpanStatus.fromHttpStatusCode(response.statusCode().value()));
addBreadcrumb(request, response);
span.finish();
return Mono.just(response);
Expand All @@ -87,7 +87,7 @@ private void addBreadcrumb(
Breadcrumb.http(
request.url().toString(),
request.method().name(),
response != null ? response.rawStatusCode() : null);
response != null ? response.statusCode().value() : null);

final Hint hint = new Hint();
hint.set(SPRING_EXCHANGE_FILTER_REQUEST, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public SentryRequestResolver(final @NotNull IHub hub) {

public @NotNull Request resolveSentryRequest(final @NotNull ServerHttpRequest httpRequest) {
final Request sentryRequest = new Request();
sentryRequest.setMethod(httpRequest.getMethodValue());
final String methodName =
httpRequest.getMethod() != null ? httpRequest.getMethod().name() : "unknown";
sentryRequest.setMethod(methodName);
sentryRequest.setQueryString(httpRequest.getURI().getQuery());
sentryRequest.setUrl(httpRequest.getURI().toString());
sentryRequest.setHeaders(resolveHeadersMap(httpRequest.getHeaders()));
Expand Down
Loading

0 comments on commit 38e4f11

Please sign in to comment.