Android

Heystack accepts Android product telemetry as standard OpenTelemetry logs over OTLP/HTTP. There is no Heystack Android SDK to install: use your app's existing HTTP client and JSON serializer.

This path sends logs and product events. It does not add Android crash capture or symbol upload.

1. Mint the Android ingest key

Open Settings › App › Connection & keys in the Heystack console and mint a Mobile (Android) key. It starts with hs_android_… and the raw value is shown once.

The key is public and ingest-only. It is safe to include in a distributed app and cannot upload dSYM files or call privileged app APIs. Keep it out of source history so it remains easy to rotate: store it in the release CI secret store and inject it when building.

Do not use a server key (sk_live_…) in an Android binary.

2. Inject it into the release build

Expose a Gradle property as a generated BuildConfig field. Keep the default empty so builds without a configured key remain inert:

// app/build.gradle.kts
val heystackIngestKey = (project.findProperty("heystackIngestKey") as String?) ?: ""

android {
    defaultConfig {
        buildConfigField("String", "HEYSTACK_INGEST_KEY", "\"$heystackIngestKey\"")
    }
    buildFeatures {
        buildConfig = true
    }
}

Supply the property only from CI:

./gradlew assembleRelease -PheystackIngestKey="$HEYSTACK_INGEST_KEY_ANDROID"

CI injection prevents accidental source-control exposure. It does not make the value secret after distribution; the Android key is deliberately constrained for that threat model.

3. Send OTLP logs

POST JSON to:

https://ingest.heystack.dev/v1/logs

Set these headers:

Authorization: Bearer hs_android_…
Content-Type: application/json

The body follows the standard OTLP Logs JSON shape. This minimal event records app.started for service my-android-app:

{
  "resourceLogs": [
    {
      "resource": {
        "attributes": [
          { "key": "service.name", "value": { "stringValue": "my-android-app" } },
          { "key": "deployment.environment", "value": { "stringValue": "production" } },
          { "key": "service.version", "value": { "stringValue": "1.4.2" } }
        ]
      },
      "scopeLogs": [
        {
          "scope": { "name": "my-android-app-analytics" },
          "logRecords": [
            {
              "timeUnixNano": "1787827200000000000",
              "severityNumber": 9,
              "severityText": "INFO",
              "body": { "stringValue": "app.started" },
              "attributes": [
                { "key": "event.name", "value": { "stringValue": "app.started" } }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Use the event's real Unix time in nanoseconds. OTLP represents timeUnixNano and integer attribute values as JSON strings.

Send with the HTTP stack already used by the app. Run the request off the UI thread in an application-owned lifecycle scope. Telemetry failures must not fail or delay the user action that produced the event.

4. Apply the privacy boundary

Check analytics consent before building or sending an event. Keep the event allow-list narrow and avoid user content:

  • Do not capture email, names, auth tokens, search text, messages, podcast content, or free-form fields.
  • Use an opaque user ID only when the product's approved analytics policy allows it.
  • Put product properties under stable attributes such as usage.source; never serialize arbitrary objects or request bodies.

The mobile key protects privileged APIs. It does not replace consent, minimization, or server-side rate controls.

5. Verify the integration

From a release-like build with consent enabled, send one known event. Confirm the OTLP request succeeds, then open Explore › Logs and filter by:

  • service.name = my-android-app
  • event.name = app.started

Also build once with an empty key and confirm the telemetry backend remains inert. Never print the raw key in build or application logs.