diff --git a/docs/platforms/java/common/tracing/instrumentation/okhttp.mdx b/docs/platforms/java/common/tracing/instrumentation/okhttp.mdx index aea6f2b70f048a..b35eaec9831bd3 100644 --- a/docs/platforms/java/common/tracing/instrumentation/okhttp.mdx +++ b/docs/platforms/java/common/tracing/instrumentation/okhttp.mdx @@ -41,7 +41,45 @@ For other dependency managers, see the [central Maven repository](https://search ## Configure -Configuration should happen once you create your `OkHttpClient` instance. + + +### Configure Spring Boot Automatically + +Sentry's Spring Boot 2, 3, and 4 integrations automatically instrument every `OkHttpClient` bean managed by Spring when you enable this option. Install `sentry-okhttp`, configure `sentry.dsn`, and enable the integration in your application configuration: + +```properties {tabTitle:application.properties} {filename:src/main/resources/application.properties} +sentry.clients.ok-http-enabled=true +``` + +```yaml {tabTitle:application.yml} {filename:src/main/resources/application.yml} +sentry: + clients: + ok-http-enabled: true +``` + +The auto-configuration preserves each client's existing configuration, interceptors, and event listeners. It adds the Sentry interceptor only once and doesn't create an `OkHttpClient` bean if your application hasn't defined one. + +Auto-configured clients use a `SentryOkHttpInterceptor` and `SentryOkHttpEventListener` with default options. To customize them (for example, with a `BeforeSpanCallback`, the `captureFailedRequests` options, or a delegate `EventListener` as described below), add your own configured `SentryOkHttpInterceptor` or `SentryOkHttpEventListener` to the bean. The auto-configuration uses your instances instead of adding its own. + +Auto-configuration doesn't instrument clients created outside Spring or `OkHttpClient` subclasses. Configure these clients manually as shown below. + + + +Sentry skips auto-configuration when its OpenTelemetry agentless integration or Java Agent is on the classpath because OpenTelemetry already instruments OkHttp. + + + +### Configure Manually + +Add the Sentry interceptor and event listener when you create an OkHttp client that Spring doesn't manage. + + + + + +Add the Sentry interceptor and event listener when you create your `OkHttpClient` instance. + + ```kotlin import okhttp3.OkHttpClient