sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

Auto configure OkHttp in Spring Boot

Open adinauer opened this issue 2 months ago • 2 comments

Problem Statement

Currently using Sentry with OkHttp on Spring Boot requires manual config.

Solution Brainstorm

We should check whether we can auto configure sentry-okhttp in case it's present on the classpath.

adinauer avatar Nov 12 '25 15:11 adinauer

JAVA-236

linear[bot] avatar Nov 12 '25 15:11 linear[bot]

Looks like this needs to be added (automatically):

  @Bean
  OkHttpClient okHttpClient() {
    return new OkHttpClient.Builder()
        .addInterceptor(new SentryOkHttpInterceptor())
        .eventListener(new SentryOkHttpEventListener())
        .build();
  }

We need to check if there's usually a bean already being created by Spring Boot and if there's a hook that allows us to configure that instance vs. creating a new instance as shown above.

adinauer avatar Nov 12 '25 15:11 adinauer