Skip to main content
The Honeycomb OpenTelemetry Android SDK is Honeycomb’s OpenTelemetry Android distribution. It simplifies adding instrumentation to your Android applications and sending telemetry to Honeycomb. This page briefly covers usage of the SDK. If you just want to see some code, check out the examples on GitHub.

Before You Begin

Before you can add instrumentation to your Android application, you will need to do a few things.

Get Your Honeycomb API Key

To send data to Honeycomb, you need to:
  1. Sign up for a Honeycomb account. To sign up, decide whether you would like Honeycomb to store your data in a US-based or EU-based location, then create a Honeycomb account in the US or create a Honeycomb account in the EU.
  2. Create a Honeycomb Ingest API Key. To get started, you can create a key that you expect to swap out when you deploy to production. Name it something helpful, perhaps noting that it’s a Getting Started key. Make note of your API key; for security reasons, you will not be able to see the key again, and you will need it later!
For setup, make sure you select the “Can create datasets” checkbox so that your data will show up in Honeycomb. Later, when you replace this key with a permanent one, you can uncheck that box.

Install the Honeycomb Android SDK

Add the Honeycomb and OpenTelemetry Android SDKs to your application’s build.gradle.kts. When adding OpenTelemetry dependencies, make sure the library is compatible with the Honeycomb Android SDK.
If your application’s minSDK is lower than 26, enable corelib desugaring:
If your application’s minSdk is lower than 24, running instrumentation tests or debug application builds requires that you:

Configuration

Sending to OpenTelemetry Collector

In production, we recommend running an OpenTelemetry Collector. Your application sends telemetry to your Collector instead of directly to Honeycomb. Your Collector then forwards the telemetry data to Honeycomb, keeping your API key stored securely in the Collector’s configuration. Call setApiEndpoint() with your Collector’s URL when initializing the SDK:

Sending to Honeycomb

To send telemetry data directly to Honeycomb, call setApiKey() with your Ingest API Key value.

Add Resource Attributes

Resource attributes are available on every span your instrumentation emits. Adding custom, application-specific attributes makes it easier to correlate your data to important business information. You can add extra resource attributes during SDK configuration with the .setResourceAttributes() method.

Enable Sampling

The Honeycomb Android SDK includes optional deterministic head sampling. To enable sampling, call .setSampleRate() with your desired sample rate as an Int value. The sample rate is 1 by default, meaning every trace is exported. The example below sets a sampleRate of 40, meaning 1 in 40 traces will be exported.

Add Automatic Instrumentation

Enable all OpenTelemetry auto-instrumentations by including the OpenTelemetry android-agent:
If you don’t need all of them, you can instead add dependencies for each instrumentation you want to include:

Custom Instrumentation

Automatic instrumentation is a fast way to instrument your code, but you get more insight into your application by adding custom, or manual, instrumentation. To add your own custom instrumentation, import the OpenTelemetry API in to your application.

Add Attributes to an Active Span

You can retrieve the currently active span in a trace and add attributes to it. This lets you add more context to traces and gives you more ways to group or filter traces in your queries:
In the above example, we add an app.cart.discount_code attribute to the current span. This lets us use the app.cart.discount_code field in WHERE or GROUP BY clauses in the Honeycomb query builder.

Acquire a Tracer

To create custom spans, you need to acquire a tracer:

Create Spans

Create custom spans to get a clear view of the critical parts in your application.

Custom Span Processing

Span processors provide hooks for when a span starts and when it ends. This lets you mutate spans after they have been created by automatic or manual instrumentation. Here’s a basic example of a span processor that adds an attribute to spans when they start:
Add the span processor as part of your SDK configuration to use it:

Manual Context Propagation

Kotlin Coroutines may operate across multiple threads, and do not automatically inherit the correct OpenTelemetry context. Instead, context must be propagated manually with the OpenTelemetry Kotlin Extensions.
Once these are installed, replace any launch calls with

Troubleshooting

To explore common issues when sending data, visit Common Issues with Sending Data in Honeycomb.