Apollo

Learn more about the Sentry Apollo integration for the Android SDK.

Capturing transactions requires that you first set up tracing 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 GraphQL client.

This integration supports Apollo 2.x. For Apollo 3.x use our Apollo3 integration.

Copied
implementation 'io.sentry:sentry-apollo:7.17.0'

For other dependency managers, see the central Maven repository.

Add SentryApolloInterceptor to Apollo builder:

Copied
import com.apollographql.apollo.ApolloClient;
import io.sentry.apollo.SentryApolloInterceptor;

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

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

Copied
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();
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").