---
title: "Apollo 2"
description: "Learn more about the Sentry Apollo 2 integration for the Android SDK."
url: https://docs.sentry.io/platforms/android/integrations/apollo2/
---

# Apollo 2 | Sentry for Android

Capturing transactions requires that you first [set up tracing](https://docs.sentry.io/platforms/android/tracing.md) if you haven't already.

Sentry Apollo integration provides the `SentryApolloInterceptor`, which creates a span for each outgoing HTTP request executed with an [Apollo Android](https://github.com/apollographql/apollo-android) GraphQL client.

This integration supports Apollo 2.x. For Apollo 3.x use our [Apollo 3 integration](https://docs.sentry.io/platforms/android/integrations/apollo3.md). For Apollo 4.x use our [Apollo 4 integration](https://docs.sentry.io/platforms/android/integrations/apollo4.md).

## [Install](https://docs.sentry.io/platforms/android/integrations/apollo2.md#install)

**Gradle**

```groovy
implementation 'io.sentry:sentry-apollo:8.42.0'
```

For other dependency managers, see the [central Maven repository](https://search.maven.org/artifact/io.sentry/sentry-apollo).

## [Configure](https://docs.sentry.io/platforms/android/integrations/apollo2.md#configure)

Add `SentryApolloInterceptor` to Apollo builder:

**java**

```java
import com.apollographql.apollo.ApolloClient;
import io.sentry.apollo.SentryApolloInterceptor;

ApolloClient apollo = ApolloClient.builder()
    .serverUrl("https://your-api-host/")
    .addApplicationInterceptor(new SentryApolloInterceptor())
    .build();
```

**kotlin**

```kotlin
import com.apollographql.apollo.ApolloClient
import io.sentry.apollo.SentryApolloInterceptor

val apollo = ApolloClient.builder()
    .serverUrl("https://your-api-host/")
    .addApplicationInterceptor(SentryApolloInterceptor())
    .build()
```

## [Modify or Drop Spans](https://docs.sentry.io/platforms/android/integrations/apollo2.md#modify-or-drop-spans)

Spans created around requests can be modified or dropped using `SentryApolloInterceptor.BeforeSpanCallback` passed to `SentryApolloInterceptor`:

**java**

```java
import com.apollographql.apollo.ApolloClient;
import io.sentry.apollo.SentryApolloInterceptor;

ApolloClient apollo = ApolloClient.builder()
    .serverUrl("https://your-api-host/")
    .addApplicationInterceptor(new SentryApolloInterceptor(
      (span, request, response) -> {
        if ("aQuery".equals(request.operation.name().name())) {
          span.setTag("tag-name", "tag-value");
        }
        return span;
      }
    ))
    .build();
```

**kotlin**

```kotlin
import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo.interceptor.ApolloInterceptor.InterceptorRequest
import com.apollographql.apollo.interceptor.ApolloInterceptor.InterceptorResponse
import io.sentry.ISpan
import io.sentry.apollo.SentryApolloInterceptor
import io.sentry.apollo.SentryApolloInterceptor.BeforeSpanCallback

val apollo = ApolloClient.builder()
    .serverUrl("https://your-api-host/")
    .addApplicationInterceptor(
        SentryApolloInterceptor(object : BeforeSpanCallback {
            override fun execute(span: ISpan, request: InterceptorRequest, response: InterceptorResponse?): ISpan {
                if ("aQuery" == request.operation.name().name()) {
                    span.setTag("tag-key", "tag-value")
                }
                return span
            }
        })
    )
    .build()
```
