Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Android API-friendliness checks #4505

Merged
merged 6 commits into from
Nov 24, 2021

Conversation

mateuszrzeszutek
Copy link
Member

Resolves #3913

I added animalsniffer checks to instrumentation-api, OkHttp, gRPC and Apache HTTP client library instrumentations. instrumentation-api needed a lot of additional ignores, mostly because of shaded caffeine2 - but they all currently seem to be desugared properly so it's all good, probably.


// these standard Java classes seem to be desugared properly
"java.lang.ClassValue",
"java.util.concurrent.CompletableFuture",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware of this working on API21 still (how are you verifying it desugars properly?).

I think it's ok because we don't call any caffeine API using it though so that's the comment we should add I guess?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how are you verifying it desugars properly?

I'm basing it on a very simple (probably too simple 😅 ) assumption -- if splunk-otel-android compiles correctly with instrumentation-api that uses those they're probably fine.
But it may as well be that those classes are just being referenced in those parts of caffeine that we don't call and it' the reason the whole thing works - I'll check that and update the comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying - indeed that looks like API level 21

https://github.com/signalfx/splunk-otel-android/blob/main/splunk-otel-android/build.gradle

And if it's working it seems likely that it's because we don't call it indeed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I looked through all the ignored classes and it does seem that most of them come from not used code paths.
There are still several points to consider:

  • Unsafe is used in lots of places in caffeine - whether we're not really using it or it works properly on Android, it's hard to say. It seems to be okay though, so I left the ignore.
  • LongAdder in caffeine2 is only present in unused paths; we're using it in our SupportabilityMetrics though. Not used unless somebody sets the otel.javaagent.debug property, which seems rather unlikely in Android.
  • ClassValue is used in SpanNames and ClassNames - we're not using any of these in our Android repo, but it's not failing the compilation on desugaring problems so I decided to keep it in the ignores. I have no idea whether this actually works on Android though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's quite dangerous to put this here, since you might use it, and if it is actually used, it will break Android compatibility. Same with any of these overrides.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can quite easily remove the ClassValue and LongAdder usage - for example, we could replace ClassValue with our own Cache (we should better compare these 2 in a benchmark first though).

I don't have any good idea about what to do with the caffeine classes though.

}

dependencies {
add("signature", "com.toasttab.android:gummy-bears-api-21:0.3.0:coreLib@signature")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this conventions something like android or android-compatible?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I don't mind - I used otel.animalsniffer-conventions because the SDK file is named the same way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

android-compatibility? (and we can update in SDK repo too)

@trask
Copy link
Member

trask commented Oct 26, 2021

I added to tomorrow's SIG agenda to discuss if Caffeine is worth it for us given our particular constraints/issues around mrjars in the bootstrap class loader and android compatibility detection.

@trask
Copy link
Member

trask commented Nov 24, 2021

I removed all of the ignores, and added reflective handling for CompletionException which is unfortunately not in Android 21. This should pass once #4667 is merged.

@trask trask merged commit 9a4a68d into open-telemetry:main Nov 24, 2021
@mateuszrzeszutek mateuszrzeszutek deleted the animalsniffer branch November 29, 2021 12:05
Comment on lines 71 to 95
withType<AnimalSniffer>().configureEach {
// we catch NoClassDefFoundError when use caffeine3 is not available on classpath and fall back to caffeine2
exclude("**/internal/shaded/caffeine3/**")

ignoreClasses = listOf(
// ignore shaded caffeine3 references
"io.opentelemetry.instrumentation.api.internal.shaded.caffeine3.cache.Caffeine",
"io.opentelemetry.instrumentation.api.internal.shaded.caffeine3.cache.Cache",

// these are being referenced by some caffeine2 classes, but we don't use them
"java.util.concurrent.CompletableFuture",
"java.util.concurrent.CompletionException",
"java.util.concurrent.CompletionStage",
"java.util.concurrent.ForkJoinPool",
"java.util.concurrent.ConcurrentHashMap",
// LongAdder is also referenced by our own SupportabilityMetrics; only if agent debug is enabled though
"java.util.concurrent.atomic.LongAdder",

// these standard Java classes seem to be desugared properly
"java.lang.ClassValue",
"sun.misc.Unsafe",
)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

RashmiRam pushed a commit to RashmiRam/opentelemetry-auto-instr-java that referenced this pull request May 23, 2022
* Add Android API-friendliness checks

* Improve comments

* Remove ignores

* Handle CompletionException

* Spotless

Co-authored-by: Trask Stalnaker <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Android API-friendliness checks to library instrumentation
5 participants