New Relic Android OkHttp instrumentation is incompatible with ExoPlayer

Hello,

We have noticed a critical regression in our Android app caused by New Relic Android SDK instrumentation, which forced us to disable instrumentation (with excludeVariantInstrumentation(...)), which in turn unfortunately disables most of New Relic’s functionality.

The issue stems from the Gradle plugin’s instrumentation that transforms the app’s bytecode. The plugin hooks into the existing HTTP calls to monitor them via New Relic SDK classes, in order to report the requests’ performance.

A side-effect of this instrumentation is that the body of HTTP responses is pre-buffered by the NR SDK (see com.newrelic.agent.android.instrumentation.okhttp3.ResponseBuilderExtension.body()).

On our side, we use the very popular ExoPlayer library for our app’s player. This library provides an OkHttp adapter (OkHttpDataSource), as well as a bandwidth measurement feature that automatically adapts the bitrate of downloaded video segments. This is core functionality to our app.

To measure the bandwidth, ExoPlayer measures the time it takes to read the HTTP response’s body. However, since this body was already read into memory by the New Relic SDK, the body is read almost instantly; ExoPlayer therefore systematically considers the bandwidth to be extremely large, which causes very excessive buffering when loading high-bitrate segments on a bad-quality network.

In our point of view, despite occurring in an apparent edge-case, the New Relic SDK caused an unnecessary breaking change to our app’s core functionality.

Several actions could be taken on your side to fix this issue:

  • Disable HTTP response pre-buffering (see com.newrelic.agent.android.instrumentation.okhttp3.ResponseBuilderExtension.body()), if possible

  • Offer a way to disable instrumentation for a given package, which would allow us to exclude OkHttp packages from being instrumented (in our case, removing the instrumentation from okhttp3.internal.http.CallServerInterceptor fixes the issue.

Note: this functionality seems to be already exposed by the Gradle plugin, but it’s not documented and doesn’t have any effect: excludePackageInstrumentation(…)

  • Allow disabling some or all kinds of instrumentation (HTTP, SQLite, JSON) without affecting the use of the rest of the SDK, which would allow us to disable instrumentation and monitor HTTP requests manually using noticeHttpTransaction(...)/noticeNetworkFailure(...).

If we have to do this on our own, the least expensive fix would be to rewrite and maintain a custom OkHttp adapter for ExoPlayer. This, however, wouldn’t solve the root cause of the problem, and we fear that there might be other undiscovered side effects caused by the New Relic HTTP instrumentation.

We stand at your disposal if you need any additional feedback.
Thank you in advance.

2 Likes

Hi @bcandellier, firstly thanks for providing such detailed information! I’ve flagged this post with the Product Manager who looks after our mobile instrumentation.

Hi again @bcandellier, I’ve heard from the Product Manager and one of the developers who works on our Android agent. They advised that this issue should be resolved by the most recent release (v6.4.0), can you please test with this version and let us know if you still see an issue?

Hello @nlidbury, thank you for your reactivity. Unfortunately the latest release of the SDK seems to make the app hang on some (all?) HTTP calls. I’m trying to investigate the issue and will report back.

I forgot to mention this in the initial post, but version 6.2.1 wasn’t affected by the original issue. It seems to have been introduced by version 6.3.1 (or 6.3.0).

Everything seems to work fine when I apply version 6.3.1 of the New Relic agent-gradle-plugin combined with version 6.4.0 of the New Relic android-agent. This suggests a regression (unrelated?) of the Gradle plugin is causing HTTP requests to hang, but our initial issue seems to be fixed.

1 Like

Thanks for the update @bcandellier and I’m glad to hear that the OkHttp issue is resolved by the latest agent version!

I see that your account has support entitlements - if you are still having issues with agent-gradle-plugin can you please raise a support ticket (via the Documentation and Support button near the top-right corner of the New Relic One UI) with the details?

1 Like