Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion docs/platforms/java/common/tracing/instrumentation/okhttp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
<PlatformSection supported={["java.spring-boot"]}>

### 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.

<Alert>

Sentry skips auto-configuration when its <PlatformLink to="/opentelemetry/setup/agentless/">OpenTelemetry agentless integration</PlatformLink> or <PlatformLink to="/opentelemetry/setup/agent/">Java Agent</PlatformLink> is on the classpath because OpenTelemetry already instruments OkHttp.

</Alert>

### Configure Manually

Add the Sentry interceptor and event listener when you create an OkHttp client that Spring doesn't manage.

</PlatformSection>

<PlatformSection notSupported={["java.spring-boot"]}>

Add the Sentry interceptor and event listener when you create your `OkHttpClient` instance.

</PlatformSection>

```kotlin
import okhttp3.OkHttpClient
Expand Down
Loading