OpenTelemetry Android
repository·main·Indexed 43 days ago
https://github.com/open-telemetry/opentelemetry-androidProvides an Android Agent and libraries for automating the initialization of the OpenTelemetry Java SDK and providing auto-instrumentation for Real User Monitoring (RUM). Includes support for Activity lifecycle tracking, Android Log transformation, ANR (Application Not Responding) detection, Compose Click and Navigation instrumentation, and Kotlin coroutine context propagation.
What's inside OpenTelemetry Android
- The OpenTelemetry OkHttp instrumentation automatically instruments client-side requests made via OkHttp (version 3.0+). It adds distributed tracing context, creates client HTTP spans, and records request/response metadata following OpenTelemetry HTTP semantic conventions.
Screen Orientation Instrumentation Overview
mainThe Screen Orientation instrumentation for Android detects changes in the device's screen orientation. It is currently in thedevelopmentstatus.Fragment Instrumentation Overview
mainFragment instrumentation tracks the lifecycle state changes of your application's Fragments. It generates spans to represent state transitions and uses span events to mark specific lifecycle milestones.What is Startup Instrumentation
mainStartup Instrumentation is a development-status feature that provides initialization log events. These events describe the specific steps taken during the Real User Monitoring (RUM) SDK initialization process, allowing you to track the progress of various SDK components.Limitations of Native Crash Snapshot Version 1
mainDevelopers using Version 1 should be aware of the following constraints:
- Unwinding: Does not interpret DWARF or compact unwind metadata. It relies on frame pointers. If optimized builds omit frame pointers, recovery may only contain the crashing frame and a link-register candidate.
- Capacity: Limited to 128 executable segments and 4 KiB of captured stack memory.
- Dynamic Loading: Modules loaded after the initial module table preparation (during handler installation) are not captured.
- Concurrency: Only one pending crash can be handled at a time. While recovery is pending, new native crashes in that process are not captured because the fixed destination files would be overwritten.
Understand the Kotlin-First Policy
mainThe OpenTelemetry Android Agent is designed with a Kotlin-First approach. The project prioritizes Kotlin language idioms and structures to provide a native experience for modern Android developers.
Key implications for users:
- The primary target use case is apps written in Kotlin.
- Both public APIs and internal code are being progressively converted to Kotlin.
- API design decisions prioritize Kotlin ergonomics over Java consistency.
OpenTelemetry API Compatibility
mainThe OpenTelemetry Android Agent is currently built on top of the OTel Java SDK and ecosystem.
It exports the OTel Java API for recording OpenTelemetry signals. This architecture will remain in place until official Kotlin versions are released and stabilized by the OpenTelemetry organization.
How Native Crash Instrumentation works
mainNative crash instrumentation records fatal native signals and replays the persisted crash as an
app.crashevent during the application's next startup.Signal Handling
The instrumentation uses a signal handler to record the following signals:
SIGILLSIGTRAPSIGABRTSIGBUSSIGFPESIGSEGVSIGSYS
When a signal is caught, the handler records the event, restores the previous action for that signal, and re-delivers it through the kernel. This ensures that the previous handler's signal mask, flags, and fault details are preserved without interfering with other signal registrations. Signals that were already ignored remain ignored.
Telemetry Data
The replayed
app.crashevent uses the original crash timestamp and includes the following attributes:exception.typeexception.messageexception.stacktrace(if a matching snapshot contains recoverable frames)session.id(when available)service.version(when available)os.nameos.version
Note that OS and app fields are read from the persisted crash-time context to ensure the event describes the process that actually crashed.
Understand OpenTelemetry Android versioning and releases
mainOpenTelemetry Android follows Semantic Versioning. All modules in the repository are released together using the same version number.
Until version 1.0.0 is reached, releases typically increment the minor version. Patch releases are rare and reserved for critical issues.
Because this library depends on
opentelemetry-java,opentelemetry-java-instrumentation, andopentelemetry-java-contrib, its release schedule is tied to theirs, typically following a monthly cycle.How ANR (Application Not Responding) instrumentation works
mainThe ANR instrumentation detects when an application becomes unresponsive by polling the UI thread once every second to verify it is still active. An ANR condition is triggered if 5 consecutive checks fail.
Note: This instrumentation is only active when the application is in the foreground.
How Power Save Mode Instrumentation works
mainThis instrumentation monitors the Android system for power management changes. Instead of polling the system state, it listens for
PowerManager.ACTION_POWER_SAVE_MODE_CHANGEDbroadcasts. When a broadcast is received, it reads the current state usingPowerManager.isPowerSaveMode()and emits adevice.power_save_mode.changeevent.Note: This instrumentation is currently in
developmentstatus and is not enabled by default.Understand coroutine instrumentation limitations and scope
mainThe coroutine instrumentation has specific boundaries regarding what it covers and how it behaves:
Supported API
CoroutineScope.launch(both default-parameter and explicit forms).
Explicit Exclusions
asyncwithContextrunBlockingFlow- All other coroutine builders.
- External dependencies and sibling library modules.
Transformation Scope
Only classes local to the module applying the ByteBuddy plugin are transformed. External library and dependency classes remain unchanged.
Context Precedence and Flow
- Precedence: If
CoroutineScope.launchis called with an explicit, non-root OpenTelemetry coroutine context element already present in the suppliedCoroutineContext, the user-supplied context takes precedence and automatic capture is skipped. - Direction: Propagation is one-directional. Context flows from the calling thread into the coroutine at launch time.
- Boundaries: Work dispatched from within a coroutine to a plain Java
Executoror thread starts with a fresh context (no automatic propagation).