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.
Install
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-apollo</artifactId>
<version>7.13.0</version>
</dependency>
For other dependency managers, see the central Maven repository.
Configure
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.
Using With Java
Configure Global Hub Mode:
import io.sentry.Sentry;
Sentry.init(options -> {
..
}, true)
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.
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
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();
- Package:
- maven:io.sentry:sentry-spring
- Version:
- 7.13.0
- Repository:
- https://github.com/getsentry/sentry-java