Apollo3 Integration
To be able to capture transactions, you'll need to first set up performance monitoring.
Sentry's Apollo3 integration provides both the SentryApollo3Interceptor
and the SentryApollo3HttpInterceptor
, which create a span for each outgoing HTTP request executed with an Apollo Kotlin GraphQL client. The integration also provides extension functions on the ApolloClient.Builder
.
Install
To install Apollo3:
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-apollo-3</artifactId>
<version>6.32.0</version>
</dependency>
For other dependency managers, see the central Maven repository.
Configure With Extension
Add Interceptors
to ApolloClient.Builder
using SentryApolloBuilderExtensions
:
import com.apollographql.apollo3.ApolloClient;
import io.sentry.apollo3.SentryApolloBuilderExtensionsKt;
ApolloClient apollo = SentryApolloBuilderExtensionsKt.sentryTracing(new ApolloClient.Builder())
.serverUrl("https://your-api-host/")
.build();
Manual Configuration
Because HttpInterceptors
need to be added to the NetworkTransport
, the SentryInterceptors
have to be added manually if you're using a custom NetworkTransport
:
import com.apollographql.apollo3.ApolloClient;
import com.apollographql.apollo3.network.http.HttpNetworkTransport;
import io.sentry.apollo3.SentryApollo3HttpInterceptor;
import io.sentry.apollo3.SentryApollo3Interceptor;
ApolloClient apollo = new ApolloClient.Builder()
.networkTransport(
new HttpNetworkTransport.Builder()
.serverUrl("https://your-api-host/")
.addInterceptor(new SentryApollo3HttpInterceptor())
.build())
.addInterceptor(new SentryApollo3Interceptor())
.build();
Important
Apollo Kotlin 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)
In Global Hub Mode, all threads use the same Hub.
Using With Kotlin Coroutines
Make sure that your coroutine has access to the correct Sentry context when launching, by providing an instance of SentryContext
:
import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.exception.ApolloException
import io.sentry.kotlin.SentryContext
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 SentryApollo3HttpInterceptor.BeforeSpanCallback
passed to SentryApollo3HttpInterceptor
or the sentryTracing
extension function:
import com.apollographql.apollo3.ApolloClient;
import io.sentry.apollo3.SentryApolloBuilderExtensionsKt;
ApolloClient apollo = SentryApolloBuilderExtensionsKt.sentryTracing(
new ApolloClient.Builder(),
(span, request, response) -> {
if ("LaunchDetails".equals(span.getOperation())) {
span.setTag("tag-name", "tag-value");
}
return span;
})
.serverUrl("https://your-api-host/")
.build();
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").
- Package:
- maven:io.sentry:sentry-spring
- Version:
- 6.32.0
- Repository:
- https://github.com/getsentry/sentry-java