elastic / apm-agent-android Goto Github PK
View Code? Open in Web Editor NEWElastic APM Android Agent
License: Apache License 2.0
Elastic APM Android Agent
License: Apache License 2.0
The Android gradle plugin API is currently going through big changes, one of them is related to the generation of assets files, needed to provide compile time information at runtime, such as service name, version and server parameters. The API for assets generation has changed in the latest version of the AGP (7.3.0), which makes our plugin to fail at compile time in projects that are using said version.
Most likely these kinds of issues will keep coming in future AGP releases, so ideally we should provide a flexible mechanism that would allow us to gracefully deal with them without having to discard host projects using older versions of the AGP.
For reference, this is the way it was done on version 7.2: https://github.com/android/gradle-recipes/blob/agp-7.2/Kotlin/addCustomAsset/app/build.gradle.kts
And this is the new API for version 7.3: https://github.com/android/gradle-recipes/blob/agp-7.3/Kotlin/addCustomAsset/app/build.gradle.kts
R8 removes unused method params, so it essentially changes methods' signatures, which breaks Byte Buddy's @Advice.Origin Method
reflection on the method androidx.fragment.app.Fragment#onViewCreated
(its second parameter of type Bundle
is removed since it's unused). So we need to find an alternative to using reflection on this Advice, or suggesting our customers to use ProGuard rules to avoid method signature's changes.
Use NTP for the clock to retrieve accurate timestamps.
When an NTP server is not available fall back to the device clock instead.
This checklist should be used by existing and newly-acquired products to ensure compliance with Elastic's open-source policy.
NOTICE.txt
and license information like other dependenciesNOTICE.txt
file consists of the following items concatenated together:
NOTICE.txt
fileNOTICE.txt
(if existing)Now:
co.elastic.apm.opbeans.modules.customers.CustomersFragment - View appearing
Proposing:
CustomersFragment (co.elastic.apm.opbeans.modules.customers) - View appearing
OTLP allows for data transfer to be throttled in case of server overload.
https://opentelemetry.io/docs/reference/specification/protocol/otlp/#otlphttp-throttling
If this happens for an extended period of time the Java sdk may start dropping data after a number of retries. A metric should record the count of traces dropped when this happens.
Each instrumented library should have its own tracer. And, tracer instances should be named by the library name they instrument (e.g. OkHttp
, Jetpack Compose
, Android Views
, etc.). Also, the version of the framework should mirror the version of the instrumented library (if possible).
The current name of the tracer is: ElasticApmAgent-tracer
This name is mapped by the APM server to the service.framework.name
field.
As defined in here: elastic/apm#771
Provide central config way of discarding HTTP spans
https://www.elastic.co/guide/en/apm/agent/java/current/configuration.html
When developing the Android APM Agent we want to test new features and approaches by means of a real Android app that uses popular, representative technologies. Moreover, we need an application that can be used for demo purposes of the Android APM agent.
Therefore, we need a simple demo Android application based on our opbeans demo-system.
The application should have comparable functionality as the swift-opbeans app:
We're using the following as screen lifecycle's root span name:
We should also provide a way for users to define their own name for said span, which would override anything else.
When using the OpenTelemetry API / SDK for Android, we need to have some logic that initializes OpenTelemetry with all the providers (Tracing, Resource, etc.). This initialization should be encapsulated into some agent initialization logic that would take care of also setting all the resource attributes as described in the agent spec.
Note: This issue does not cover any automatic instrumentation yet.
We need a way to tell that the current NOTICE file is aligned with the current project's dependencies. So there should be a Gradle task that verifies whether the current NOTICE file outdated or if it's fine as it is. If it's outdated, the task should yield an exception that suggests to re-run the createNoticeFile
task in order to update the project's NOTICE files.
The Open Telemetry Java SDK mentions that for Android projects, the desugaring config must be enabled.
Java language APIs/features apis are embedded in the Android OS, so when new ones are added into newer JDK versions (like what happened with version 8 where lambdas were added), a new Android OS version was needed to add support for them at runtime. However, some libraries (like OTel's), make use of "newer" JDK APIs, such as the java.time.Duration in this case, which is available from the Android OS 8 (API level 26), so in devices with OS version < 8, there will be a crash of type "NoClassDefFoundError" when running them.
The way Google came up with a solution to avoid these issues, was to add an optional compilation process where new APIs would get "desugared" in order to make them compatible for older OS versions. They have a list of supported APIs for desugaring here.
So if our customers are targeting Android OS versions < 26, they must opt in for desugaring in their app's build.gradle
file.
According to Google's guide on how to add support for desugaring, it seems like it's a 2-step process, the first one is to enable a flag, and the second one is to add a dependency. However, the dependency's version to set cannot be the latest one all the time, since it depends on the version of the Android Gradle plugin that the project is on. So we must make sure to tell our customers to check on their project's AGP version before adding said library, or we could add all the "desugaring" configuration for them through our Gradle plugin, where we'd check our customer's AGP version and apply the best config for them automatically.
Currently in order to connect the Android agent to an Elastic cloud instance, users need to pass their instance's endpoint + its auth token. Currently their auth token is passed in plain text, we need to figure ways to make it more secure.
To continuously test the agent, we need to have a load driver for the opbenas-android app that would generate real load (and though that agent data) that we can use for end-to-end testing and demoing.
This a first step towards an end-to-end POC of instrumenting an Android application.
Use the OpenTelemetry API and SDK to enrich the opbeans-android App with instrumentation code.
The goal is to see end-to-end tracing data in Kibana from view loads / user interactions in the app through http requests into the backend and correlation with the backend traces.
Closes #71
With the most recent change on Byte Buddy for Android, the previous way to delegate from the CompositeEventListener class over to the array of listeners passed to it, has gotten broken since now the Byte Buddy gradle plugin for Android cannot generate new methods inside a type, it can only decorate existing ones instead, so the option to generate the delegating methods is no longer viable.
We need to find and apply an alternative way of delegating from CompositeEventListener to all of its listeners.
Use:
event.name
= crash
event.domain
= device
to denote crashes
Allow session ID idle time to be configurable through central config
To 4 hours
Provide central config option to rename HTTP requests based on their URL format to group them with a single span name.
The way we instrument OkHttp calls is through the registration of an EventListener factory into the OkHttpClient instance. Each OkHttpClient instance can only have 1 EventListener factory, so we must wrap and existing one (if any) in order to delegate calls to it through our own factory which will override any previously set factory.
Initialize the Android Agent project (basic project structure, CI, etc.)
We need to provide ways to configure the Agent through environment variables the same way is done for the Java Agent - So we'd need to add support for the following params that would override the gradle config params (if any):
ELASTIC_APM_SERVICE_NAME
ELASTIC_APM_SERVICE_VERSION
ELASTIC_APM_SERVER_URL
ELASTIC_APM_SECRET_TOKEN
Also, as mentioned here we also need to rename the current gradle's config param serverToken
by secretToken
.
We must add logs that show the origin of the config.
Currently, the Android agent yields the following host.os.*
fields:
host.os.full
, host.os.platform
and host.os.version
are fine ✅host.os.name
needs to be Android
. Therefore, the agent needs to set the os.name
resource attribute in OpenTelemetry host.os.type
will be properly derived from host.os.name
(once this is set properly) by the APM server ✅Adding android support to the official byte buddy gradle plugin.
This issue explains the steps required to publish documentation to the Elastic documentation build powered by elastic/docs. Let me know when you're ready and I can get started on these tasks.
Create basic docs. These docs will disconnected from the doc build for this phase. Docs should (mostly) follow the slightly outdated Agent documentation template. Here's a recent example: elastic/apm-agent-php#48.
We have content! Now we can add elastic/apm-agent-android
to Elastic's doc build and publish.
elastic/docs
to add to the buildelasticsearch/ci docs
check to this repoelasticsearch/ci docs
webhook to the repoelastic/apm-contrib
elastic/apm-contrib#61elastic/apm
elastic/apm#721elastic/apm-dev
https://github.com/elastic/apm-dev/pull/898Hook the Android Reference into the rest of the Stack documentation. No list as docs change frequently, but inspiration can be taken from elastic/observability-docs#383 and elastic/observability-docs#792.
We need to come up with a way to debug our Agent so that our customers can provide us with our Agent's logs easily. It should be possible to get those manually if needed, but ideally we should be able to get those automatically, probably by sending our own logs straight to their backends if they enable "debug mode" on our agent.
Fetching config remotely and applying it on app start/at runtime.
Q. Do we need a second TCP connection?
Notes: Backend do fetch every 30 secs
We need to send the network type/subtype and the mobile carrier info on every Span
As described in the spec, the http.client_ip
is mapped to client.ip
field. For the client.ip
field the APM ingest pipeline derives the geo location for the IP. This is a valuable fallback for the geo location information in case the mobile agent cannot provide the geo information directly (e.g. due to missing permission to retrieve the geo location).
The Android agent should add the http.client_ip
field to the spans to leverage the above.
Onboarding the Android APM Agent should be as easy as possible. While runtime bytecode instrumentation (BCI) is not possible on Android, we can leverage compile time BCI using Android Buddy.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.