Skip to content

Commit

Permalink
Document OkHttp callback for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejwalkowiak committed May 26, 2021
1 parent 581f399 commit 96bdaa8
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/platforms/android/configuration/integrations/okhttp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,61 @@ Learn more about manually capturing an error or message, in our <PlatformLink to
</Note>

To view and resolve the recorded message, log into [sentry.io](https://sentry.io) and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.

## Customize recorded Span

Captured Span can be customized or dropped with a `BeforeSpanCallback`:

```kotlin
import io.sentry.ISpan
import io.sentry.android.okhttp.SentryOkHttpInterceptor
import okhttp3.Request
import okhttp3.Response

class CustomBeforeSpanCallback : SentryOkHttpInterceptor.BeforeSpanCallback {
override fun execute(span: ISpan, request: Request, response: Response?): ISpan? {
return if (request.url.toUri().toString().contains("/admin")) {
null
} else {
span
}
}
}
```

```java
import io.sentry.ISpan;
import io.sentry.android.okhttp.SentryOkHttpInterceptor;
import okhttp3.Request;
import okhttp3.Response;

class CustomBeforeSpanCallback implements SentryOkHttpInterceptor.BeforeSpanCallback {
public ISpan execute(ISpan span, Request request, Response response) {
if (request.getUrl().toUri().toString().contains("/admin")) {
return null;
} else {
return span;
}
}
}
```

The callback instance must be set on the `SentryOkHttpInterceptor` once you create your `OkHttpClient` instance.

```kotlin
import okhttp3.OkHttpClient
import io.sentry.android.okhttp.SentryOkHttpInterceptor

private val client = OkHttpClient.Builder()
.addInterceptor(SentryOkHttpInterceptor(CustomBeforeSpanCallback()))
.build()
```

```java
import okhttp3.OkHttpClient;
import io.sentry.android.okhttp.SentryOkHttpInterceptor;

private final OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new SentryOkHttpInterceptor(new CustomBeforeSpanCallback()))
.build();
```

0 comments on commit 96bdaa8

Please sign in to comment.