Android - Disabling SentryOkHttp doesn't seem to work
Integration
sentry-android
Build System
Gradle
AGP Version
8.5.1
Proguard
Enabled
Version
7.12.0
Steps to Reproduce
I'm using the Sentry plugin (4.10.0) and I've noticed that it's automatically adding SentryOkHttp interceptors to my Coil OkHttp client which means that if the user is offline I'm getting lots of 504 errors on Sentry. I tried to disable just the Coil requests but this never worked. I therefore decided to not add the SentryPlugin for Coil. However, the plugin seems to be adding it anyway. How can I disable it so that the SentryOkHttpClient is only added to the OkHttpClients that I specify?
I tried doing this as per your instructions but I can see a Sentry Interceptor being added still.
sentry {
tracingInstrumentation {
enabled.set(true)
features.set(EnumSet.allOf(InstrumentationFeature::class.java) - InstrumentationFeature.OKHTTP)
}
}
This is the hilt configuration that I use to choose which interceptors to add
@Provides
@NoSentryHttp
@Singleton
fun provideNoSentryHttp(
httpLoggingInterceptor: HttpLoggingInterceptor,
userAgentInterceptor: UserAgentInterceptor,
): OkHttpClient =
OkHttpClient.Builder()
.addInterceptor(httpLoggingInterceptor)
.addInterceptor(userAgentInterceptor)
.build()
@Provides
@CommonOkHttp
@Singleton
fun provideCommonOkHttpClient(@NoSentryHttp okHttpClient: OkHttpClient): OkHttpClient =
okHttpClient.newBuilder().addInterceptor(SentryOkHttpInterceptor()).build()
Expected Result
Adding the gradle configuration should disable the auto installation of okhttp tracing.
Actual Result
I could still see SentryOkHttpInterceptor in the stacktrace of an OkHttpClient where I'd specified NoSentry.
@barry-irvine thanks for reporting, we'll take a look into this!
Hi @barry-irvine, Sorry for the wait. We have investigated the issue and have been able to reproduce. This seems to be related to gradle caching our instrumentations. We are working on a proper fix.
In the meantime, there is a flag you can set in your tracingInstrumentation section disable caching for library instrumentaions. But, be aware, this might lead to increased build times, as the instrumentations are run at every build. If build times get too slow you can set it once after changing the instrumentation features, build and then disable the flag again. The flag is called forceInstrumentDependencies.
Here's an example based on the sentry section you provided:
sentry {
tracingInstrumentation {
forceInstrumentDependencies.set(true)
enabled.set(true)
features.set(EnumSet.allOf(InstrumentationFeature::class.java) - InstrumentationFeature.OKHTTP)
}
}
Please let us know if that fixed your issue. We'll let you know once the proper fix is ready.