Apollo Integration
Capturing transactions requires that you first set up performance monitoring 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.
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-apollo</artifactId>
<version>7.8.0</version>
</dependency>
For other dependency managers, see the central Maven repository.
Add SentryApolloInterceptor
to Apollo builder:
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.
Configure Global Hub Mode:
import io.sentry.Sentry;
Sentry.init(options -> {
..
}, true)
In Global Hub Mode, all threads use the same Hub.
To make sure that a coroutine has access to the correct Sentry context, an instance of SentryContext
must be provided when launching a coroutine.
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
}
}
Spans created around requests can be modified or dropped using SentryApolloInterceptor.BeforeSpanCallback
passed to SentryApolloInterceptor
:
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();
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").
- Package:
- maven:io.sentry:sentry-apollo
- Version:
- 7.8.0
- Repository:
- https://github.com/getsentry/sentry-java
- API Documentation:
- https://javadoc.io/doc/io.sentry