opentelemetry-java icon indicating copy to clipboard operation
opentelemetry-java copied to clipboard

More information on how to implement in android

Open juliandavid333 opened this issue 3 years ago • 14 comments

I don't see much documentation on how to implement it in android, neither blogs nor communities, I don't find much info.

like this

juliandavid333 avatar Aug 03 '21 16:08 juliandavid333

I think nobody we know of has tried it & reported back so far. Did you try it and hit any roadblocks?

Oberon00 avatar Aug 03 '21 16:08 Oberon00

Splunk is using otel extensively in our new RUM instrumentation for Android. There isn't really much special about it. It pretty well works out of the box as it should.

Have you had any issues @juliandavid333 ?

jkwatson avatar Aug 03 '21 20:08 jkwatson

FYI: https://github.com/signalfx/splunk-otel-android

jkwatson avatar Aug 03 '21 20:08 jkwatson

FYI: https://github.com/signalfx/splunk-otel-android

thank you, let me try

juliandavid333 avatar Aug 04 '21 13:08 juliandavid333

I've been experimenting with version 1.6.0 on Android and, since our min API level is 23, it fails at runtime with this exception.

 E  java.lang.NoClassDefFoundError: io.opentelemetry.api.common.ArrayBackedAttributes$$ExternalSyntheticLambda0
 E      at io.opentelemetry.api.common.ArrayBackedAttributes.<clinit>(ArrayBackedAttributes.java:20)
 E      at io.opentelemetry.api.common.Attributes$-CC.of(Attributes.java:62)
 E      ...

The static method isn't supported on Android until API 24.

Is the min API of 24 a hard minimum? What other APIs are only on 24 that this library is depending on? Just looking to get more clarification on the minimum.

kylannjohnson avatar Oct 05 '21 19:10 kylannjohnson

@kylannjohnson You must enable core library desugaring in your app build for this to work. https://developer.android.com/studio/write/java8-support#library-desugaring

And with that enabled, anything API level 21 and above should work fine.

jkwatson avatar Oct 05 '21 19:10 jkwatson

@jkwatson thanks for the tip. Desugaring does seem to quiet the exception. I asked around on my team and we haven't desugared to date because of potential licensing issues with OpenJDK. I'll certainly investigate that on my side, but I was wondering what the scope was for adaption o Open Telemetry to api 23 or api 21. Do you think it's feasible?

kylannjohnson avatar Oct 08 '21 00:10 kylannjohnson

Licensing issues for OpenJdk? I'm not sure how that's relevant for Android's desugaring of java 8 APIs.

I'm not sure what you mean by your question. You mean...what would it take to not have to do desugaring? That ship sailed long, long ago. We made the decision to support only java 8+, and that is not going to change. It would require a radical rewrite of almost all of our public APIs which depend extensively on interfaces being able to have static methods.

jkwatson avatar Oct 08 '21 00:10 jkwatson

which depend extensively on interfaces being able to have static methods.

You don't need code lib desugaring to support the language features, like lambdas, default methods on interfaces, etc. R8 gives you all the Java 8 syntax support for all Android builds.

Core lib desugaring is only needed when you call a JDK API that was introduced in Java 8. For example: https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html#comparing-java.util.function.Function-

So as long as you don't use JDK APIs that are from Java 8+, you could still use java 8 syntax and support Android without core lib desugaring.

yogurtearl avatar Oct 08 '21 01:10 yogurtearl

I see. But, your example stack trace was specifically about static methods on interfaces. :) Are you saying that for API level 21-24, you can only target Java 8 language level in your build, and it will work, without desugaring?

jkwatson avatar Oct 08 '21 01:10 jkwatson

@yogurtearl Please let us know what your findings on potential legal issues are. We made the decision to target deaugared libs after the Gradle Android plugin was updated to support desugaring for all API versions. Our understanding was that this means there isn't any reason for users not to enable this so that OTel would work while allowing us to provide a modern experience for Java users (e.g., accept Duration in public API). It would be good for us to know about any potential non-technical issues - though I don't think we would really be able to do anything as at this point the desugaring requirement is broadly ingrained into the codebase, including public APIs.

anuraaga avatar Oct 08 '21 02:10 anuraaga

@kylannjohnson were you able to make it work for android?

@jkwatson what changes will be needed to make splunk-otel-android send data to jaeger? I see the readme mention something like below

    private final Config config = SplunkRum.newConfigBuilder()
            .realm(realm)
            .rumAccessToken(rumAccessToken)
            .applicationName("My Android App")
            .build();

ankitnayan avatar Jun 27 '22 17:06 ankitnayan

@kylannjohnson were you able to make it work for android?

@jkwatson what changes will be needed to make splunk-otel-android send data to jaeger? I see the readme mention something like below

    private final Config config = SplunkRum.newConfigBuilder()
            .realm(realm)
            .rumAccessToken(rumAccessToken)
            .applicationName("My Android App")
            .build();

I no longer work for Splunk, so you should probably create an issue in their project if you need help with that.

jkwatson avatar Jun 27 '22 17:06 jkwatson

@kylannjohnson were you able to make it work for android?

I was just experimenting with OTEL so I wasn't able to complete that project, but I'll post back here if I'm able to get something working.

kylannjohnson avatar Jun 28 '22 16:06 kylannjohnson

Closing now that there is an official opentelemetry-android project.

jack-berg avatar Nov 30 '23 22:11 jack-berg