---
title: "Apollo 2 Integration"
description: "Learn how to capture tracing information of the Apollo GraphQL client."
url: https://docs.sentry.io/platforms/java/guides/spring/tracing/instrumentation/apollo2/
---

# Apollo 2 Integration | Sentry for Spring

Capturing transactions requires that you first [set up tracing](https://docs.sentry.io/platforms/java/guides/spring/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/java/guides/spring/tracing/instrumentation/apollo3.md). For Apollo 4.x use our [Apollo 4 integration](https://docs.sentry.io/platforms/java/guides/spring/tracing/instrumentation/apollo4.md).

## [Install](https://docs.sentry.io/platforms/java/guides/spring/tracing/instrumentation/apollo2.md#install)

```xml
<dependency>
    <groupId>io.sentry</groupId>
    <artifactId>sentry-apollo</artifactId>
    <version>8.37.1</version>
</dependency>
```

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

## [Configure](https://docs.sentry.io/platforms/java/guides/spring/tracing/instrumentation/apollo2.md#configure)

Add `SentryApolloInterceptor` to Apollo builder:

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

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

Apollo Android is built with Kotlin coroutines. This means that `SentryApolloInterceptor` can be used with Java using only Global Hub Mode (single Hub used by all threads), with Kotlin using single Hub mode, or with [Sentry's coroutines support](https://docs.sentry.io/platforms/java/guides/spring/enriching-events/scopes.md#kotlin-coroutines).

## [Using With Java](https://docs.sentry.io/platforms/java/guides/spring/tracing/instrumentation/apollo2.md#using-with-java)

Configure Global Hub Mode:

```java
import io.sentry.Sentry;

Sentry.init(options -> {
  ..
}, true)
```

In Global Hub Mode, all threads use the same Hub.

## [Using With Kotlin Coroutines](https://docs.sentry.io/platforms/java/guides/spring/tracing/instrumentation/apollo2.md#using-with-kotlin-coroutines)

To make sure that a coroutine has access to the correct Sentry context, an instance of `SentryContext` must be provided when launching a coroutine.

```kotlin
import io.sentry.kotlin.SentryContext
import com.apollographql.apollo.exception.ApolloException
import kotlinx.coroutines.launch

launch(SentryContext()) {
  val response = try {
    apollo.query(..).toDeferred().await()
  } catch (e: ApolloException) {
    // handle protocol errors
    return@launch
  }
}
```

## [Modify or Drop Spans](https://docs.sentry.io/platforms/java/guides/spring/tracing/instrumentation/apollo2.md#modify-or-drop-spans)

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

```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();
```
