Skip to content

Commit c87d429

Browse files
lciancvb941
andauthored
Add GraphQL Apollo Kotlin 4 integration (#4166)
* Apollo 4 initial setup * rename some stuff, change and add a few tests * parametrize tests to run with both v3 and v4 implementations of `ApolloCall<D>::execute` * changelog * rename SentryApollo4BuilderExtensions back to SentryApolloBuilderExtensions to make it easier to migrate * make api * add README.md * update comment --------- Co-authored-by: Lukas Kusik <[email protected]>
1 parent 37b98dc commit c87d429

27 files changed

+2215
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- A list of active Spring profiles is attached to payloads sent to Sentry (errors, traces, etc.) and displayed in the UI when using our Spring or Spring Boot integrations ([#4147](https://github.com/getsentry/sentry-java/pull/4147))
99
- This consists of an empty list when only the default profile is active
1010
- Move to a single NetworkCallback listener to reduce number of IPC calls on Android ([#4164](https://github.com/getsentry/sentry-java/pull/4164))
11+
- Add GraphQL Apollo Kotlin 4 integration ([#4166](https://github.com/getsentry/sentry-java/pull/4166))
1112

1213
### Fixes
1314

buildSrc/src/main/java/Config.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ object Config {
157157
val composeCoil = "io.coil-kt:coil-compose:2.6.0"
158158

159159
val apolloKotlin = "com.apollographql.apollo3:apollo-runtime:3.8.2"
160+
val apolloKotlin4 = "com.apollographql.apollo:apollo-runtime:4.1.1"
160161

161162
val sentryNativeNdk = "io.sentry:sentry-native-ndk:0.7.20"
162163

@@ -250,6 +251,7 @@ object Config {
250251
val SENTRY_SPRING_BOOT_JAKARTA_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.spring-boot.jakarta"
251252
val SENTRY_OPENTELEMETRY_AGENT_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.opentelemetry.agent"
252253
val SENTRY_APOLLO3_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.apollo3"
254+
val SENTRY_APOLLO4_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.apollo4"
253255
val SENTRY_APOLLO_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.apollo"
254256
val SENTRY_GRAPHQL_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.graphql"
255257
val SENTRY_GRAPHQL22_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.graphql22"

sentry-apollo-4/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# sentry-apollo-4
2+
3+
This module provides an integration for [Apollo Kotlin 4](https://www.apollographql.com/docs/kotlin/v4).
4+
5+
Please consult the documentation on how to install and use this integration in the Sentry Docs for [Android](https://docs.sentry.io/platforms/android/integrations/apollo4/) or [Java](https://docs.sentry.io/platforms/java/tracing/instrumentation/apollo4/).
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
public final class io/sentry/apollo4/BuildConfig {
2+
public static final field SENTRY_APOLLO4_SDK_NAME Ljava/lang/String;
3+
public static final field VERSION_NAME Ljava/lang/String;
4+
}
5+
6+
public final class io/sentry/apollo4/SentryApollo4ClientException : java/lang/Exception {
7+
public static final field Companion Lio/sentry/apollo4/SentryApollo4ClientException$Companion;
8+
public fun <init> (Ljava/lang/String;)V
9+
}
10+
11+
public final class io/sentry/apollo4/SentryApollo4ClientException$Companion {
12+
}
13+
14+
public final class io/sentry/apollo4/SentryApollo4HttpInterceptor : com/apollographql/apollo/network/http/HttpInterceptor {
15+
public static final field Companion Lio/sentry/apollo4/SentryApollo4HttpInterceptor$Companion;
16+
public static final field DEFAULT_CAPTURE_FAILED_REQUESTS Z
17+
public fun <init> ()V
18+
public fun <init> (Lio/sentry/IScopes;)V
19+
public fun <init> (Lio/sentry/IScopes;Lio/sentry/apollo4/SentryApollo4HttpInterceptor$BeforeSpanCallback;)V
20+
public fun <init> (Lio/sentry/IScopes;Lio/sentry/apollo4/SentryApollo4HttpInterceptor$BeforeSpanCallback;Z)V
21+
public fun <init> (Lio/sentry/IScopes;Lio/sentry/apollo4/SentryApollo4HttpInterceptor$BeforeSpanCallback;ZLjava/util/List;)V
22+
public synthetic fun <init> (Lio/sentry/IScopes;Lio/sentry/apollo4/SentryApollo4HttpInterceptor$BeforeSpanCallback;ZLjava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
23+
public fun intercept (Lcom/apollographql/apollo/api/http/HttpRequest;Lcom/apollographql/apollo/network/http/HttpInterceptorChain;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
24+
}
25+
26+
public abstract interface class io/sentry/apollo4/SentryApollo4HttpInterceptor$BeforeSpanCallback {
27+
public abstract fun execute (Lio/sentry/ISpan;Lcom/apollographql/apollo/api/http/HttpRequest;Lcom/apollographql/apollo/api/http/HttpResponse;)Lio/sentry/ISpan;
28+
}
29+
30+
public final class io/sentry/apollo4/SentryApollo4HttpInterceptor$Companion {
31+
}
32+
33+
public final class io/sentry/apollo4/SentryApollo4Interceptor : com/apollographql/apollo/interceptor/ApolloInterceptor {
34+
public fun <init> ()V
35+
public fun <init> (Lio/sentry/IScopes;)V
36+
public synthetic fun <init> (Lio/sentry/IScopes;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
37+
public fun intercept (Lcom/apollographql/apollo/api/ApolloRequest;Lcom/apollographql/apollo/interceptor/ApolloInterceptorChain;)Lkotlinx/coroutines/flow/Flow;
38+
}
39+
40+
public final class io/sentry/apollo4/SentryApolloBuilderExtensionsKt {
41+
public static final fun sentryTracing (Lcom/apollographql/apollo/ApolloClient$Builder;)Lcom/apollographql/apollo/ApolloClient$Builder;
42+
public static final fun sentryTracing (Lcom/apollographql/apollo/ApolloClient$Builder;Lio/sentry/IScopes;)Lcom/apollographql/apollo/ApolloClient$Builder;
43+
public static final fun sentryTracing (Lcom/apollographql/apollo/ApolloClient$Builder;Lio/sentry/IScopes;Z)Lcom/apollographql/apollo/ApolloClient$Builder;
44+
public static final fun sentryTracing (Lcom/apollographql/apollo/ApolloClient$Builder;Lio/sentry/IScopes;ZLjava/util/List;)Lcom/apollographql/apollo/ApolloClient$Builder;
45+
public static final fun sentryTracing (Lcom/apollographql/apollo/ApolloClient$Builder;Lio/sentry/IScopes;ZLjava/util/List;Lio/sentry/apollo4/SentryApollo4HttpInterceptor$BeforeSpanCallback;)Lcom/apollographql/apollo/ApolloClient$Builder;
46+
public static final fun sentryTracing (Lcom/apollographql/apollo/ApolloClient$Builder;ZLjava/util/List;Lio/sentry/apollo4/SentryApollo4HttpInterceptor$BeforeSpanCallback;)Lcom/apollographql/apollo/ApolloClient$Builder;
47+
public static synthetic fun sentryTracing$default (Lcom/apollographql/apollo/ApolloClient$Builder;Lio/sentry/IScopes;ZLjava/util/List;Lio/sentry/apollo4/SentryApollo4HttpInterceptor$BeforeSpanCallback;ILjava/lang/Object;)Lcom/apollographql/apollo/ApolloClient$Builder;
48+
public static synthetic fun sentryTracing$default (Lcom/apollographql/apollo/ApolloClient$Builder;ZLjava/util/List;Lio/sentry/apollo4/SentryApollo4HttpInterceptor$BeforeSpanCallback;ILjava/lang/Object;)Lcom/apollographql/apollo/ApolloClient$Builder;
49+
}
50+

sentry-apollo-4/build.gradle.kts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import net.ltgt.gradle.errorprone.errorprone
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3+
4+
plugins {
5+
`java-library`
6+
kotlin("jvm")
7+
jacoco
8+
id(Config.QualityPlugins.errorProne)
9+
id(Config.QualityPlugins.gradleVersions)
10+
id(Config.BuildPlugins.buildConfig) version Config.BuildPlugins.buildConfigVersion
11+
}
12+
13+
configure<JavaPluginExtension> {
14+
sourceCompatibility = JavaVersion.VERSION_1_8
15+
targetCompatibility = JavaVersion.VERSION_1_8
16+
}
17+
18+
tasks.withType<KotlinCompile>().configureEach {
19+
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
20+
kotlinOptions.languageVersion = Config.kotlinCompatibleLanguageVersion
21+
}
22+
23+
dependencies {
24+
api(projects.sentry)
25+
api(projects.sentryKotlinExtensions)
26+
27+
compileOnly(Config.Libs.apolloKotlin4)
28+
29+
compileOnly(Config.CompileOnly.nopen)
30+
errorprone(Config.CompileOnly.nopenChecker)
31+
errorprone(Config.CompileOnly.errorprone)
32+
errorprone(Config.CompileOnly.errorProneNullAway)
33+
compileOnly(Config.CompileOnly.jetbrainsAnnotations)
34+
35+
// tests
36+
testImplementation(projects.sentryTestSupport)
37+
testImplementation(Config.Libs.coroutinesCore)
38+
testImplementation(kotlin(Config.kotlinStdLib))
39+
testImplementation(Config.TestLibs.kotlinTestJunit)
40+
testImplementation(Config.TestLibs.mockitoKotlin)
41+
testImplementation(Config.TestLibs.mockitoInline)
42+
testImplementation(Config.TestLibs.mockWebserver)
43+
testImplementation(Config.Libs.apolloKotlin4)
44+
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
45+
testImplementation("org.jetbrains.kotlin:kotlin-reflect:2.0.0")
46+
}
47+
48+
configure<SourceSetContainer> {
49+
test {
50+
java.srcDir("src/test/java")
51+
}
52+
}
53+
54+
jacoco {
55+
toolVersion = Config.QualityPlugins.Jacoco.version
56+
}
57+
58+
tasks.jacocoTestReport {
59+
reports {
60+
xml.required.set(true)
61+
html.required.set(false)
62+
}
63+
}
64+
65+
tasks {
66+
jacocoTestCoverageVerification {
67+
violationRules {
68+
rule { limit { minimum = Config.QualityPlugins.Jacoco.minimumCoverage } }
69+
}
70+
}
71+
check {
72+
dependsOn(jacocoTestCoverageVerification)
73+
dependsOn(jacocoTestReport)
74+
}
75+
}
76+
77+
tasks.withType<JavaCompile>().configureEach {
78+
options.errorprone {
79+
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
80+
option("NullAway:AnnotatedPackages", "io.sentry")
81+
}
82+
}
83+
84+
buildConfig {
85+
useJavaOutput()
86+
packageName("io.sentry.apollo4")
87+
buildConfigField("String", "SENTRY_APOLLO4_SDK_NAME", "\"${Config.Sentry.SENTRY_APOLLO4_SDK_NAME}\"")
88+
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"")
89+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.sentry.apollo4
2+
3+
/**
4+
* Common constants used across the module
5+
*/
6+
internal const val OPERATION_ID_HEADER_NAME = "SENTRY-APOLLO-4-OPERATION-ID"
7+
internal const val OPERATION_NAME_HEADER_NAME = "SENTRY-APOLLO-4-OPERATION-NAME"
8+
internal const val OPERATION_TYPE_HEADER_NAME = "SENTRY-APOLLO-4-OPERATION-TYPE"
9+
internal const val VARIABLES_HEADER_NAME = "SENTRY-APOLLO-4-VARIABLES"
10+
internal val INTERNAL_HEADER_NAMES by lazy {
11+
listOf(
12+
OPERATION_ID_HEADER_NAME,
13+
OPERATION_NAME_HEADER_NAME,
14+
OPERATION_TYPE_HEADER_NAME,
15+
VARIABLES_HEADER_NAME
16+
)
17+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.sentry.apollo4
2+
3+
/**
4+
* Used for holding an Apollo4 client error, for example. An integration that does not throw when API
5+
* returns 4xx, 5xx or the `errors` field.
6+
*/
7+
class SentryApollo4ClientException(message: String?) : Exception(message) {
8+
companion object {
9+
private const val serialVersionUID = 4312160066430858144L
10+
}
11+
}

0 commit comments

Comments
 (0)