Tracing
Trace Android requests from the device into your backend with the LogDrop Android SDK.
The Android SDK adds a W3C traceparent header to every OkHttp request it tracks and sends each request as one client span, so the request and the backend spans it causes form one trace in LogDrop. Nothing changes in your init code.
Rules that all LogDrop mobile SDKs share (authentication, which requests are traced, delivery and limits) are on End-to-end Tracing.
1. Use SDK 2.1.11 or later with the LogDrop Gradle plugin
Tracing is part of the Android SDK from version 2.1.11. Earlier versions do not trace requests. On Android, tracing also needs the LogDrop Gradle plugin, described below.
plugins {
id "io.logdrop.gradle.plugin"
}
dependencies {
implementation "io.logdrop:sdk:2.1.16"
}Tracing needs the LogDrop Gradle plugin (io.logdrop.gradle:plugin:1.1.3). The plugin adds LogDrop's interceptor to every OkHttpClient your app builds, including those inside Retrofit, image loaders and other libraries; without it, no OkHttp client is traced. Its setup, including the repository and logdrop-services.json, is in Crash Tracking (mapping upload). Apps that already upload mappings have it.
2. Initialize as usual
Tracing needs no extra code. The usual initialization below is enough.
class App : Application() {
override fun onCreate() {
super.onCreate()
LogDrop.registerActivityLifecycleCallback(this) // on the main thread
val config = LogDropConfig.Builder()
.appId("YOUR_APP_ID")
.baseUrl("YOUR_BASE_URL") // optional: self-hosted LogDrop
.build()
LogDrop.init(this, config)
}
}The App ID is all the SDK needs: it sends spans to <baseUrl>/v1/traces (by default https://server.logdrop.io/v1/traces) with the header x-logdrop-app-id. Turn on HTTP Logging for the project in the panel; tracing starts as soon as the SDK has LogDrop's confirmed settings. service.name is your package name, and the service version is your app's version.
Your backend must send its traces to the same LogDrop project as this app, with an ingest key created in the app's project (why).
What is traced
The SDK traces only OkHttp requests that pass through LogDrop's interceptor. This section lists which Android requests get a traceparent header and a span.
- Requests made with OkHttp, directly or through a library that builds an
OkHttpClient(for example Retrofit).HttpURLConnection, Cronet, other HTTP engines and WebViews are not traced. - Each attempt OkHttp makes is its own span in the same trace: redirects and OkHttp's own retries get a new span ID each and keep the trace ID.
- The app configuration's Ignored domains stop tracing. On Android an entry matches when it appears anywhere in the request URL. Ignored host and path rules do not stop tracing: they only skip the HTTP records of requests that are not traced.
- A redirect keeps the first request's decision.
- The SDK sees a request once OkHttp has a connection. Requests that fail before that (DNS, connection or TLS errors) and responses served from OkHttp's cache get no span and no HTTP record.
The other rules are in Which requests are traced.
Delivery
The SDK does not send a span the moment a request ends. It queues spans on the device and sends them in batches, so spans recorded offline are sent later. You do not need to do anything; this section explains the timing and limits on Android.
Spans are kept in the SDK's encrypted database queue (AES-GCM with an Android Keystore key, at most 1,000 spans). The first queued span schedules a one-time WorkManager job that waits for the network and about 15 seconds, then sends batches of at most 50 spans and about 48 KiB, split so that one request never holds spans that start in more than 32 different minutes.
A 400 answer drops the request. 408, 425, 429, 5xx and no answer are retried by WorkManager with exponential backoff from 10 seconds, at most 3 attempts per span in all, always with the identical request. Spans older than about 7 days or more than 5 minutes ahead of the device clock are dropped before their first send.
Send queued spans now (optional)
The SDK sends spans on its own. Call flushOtlpTracing only where you need the queued spans sent right away, for example at the end of an integration test or before the user signs out.
// Blocks the calling thread for at most the timeout (1 to 5,000 ms, default 2,000): call it off the main thread.
val delivered: Boolean = LogDrop.flushOtlpTracing(timeoutMillis = 2_000)truemeans the queue is empty and no span was lost since the previous flush. It is alsotruewhen HTTP Logging is off and the queue was cleared, so it does not tell you whether tracing is on.- A flush sends only spans that were never attempted. While a batch waits for its retry, WorkManager resends it on its own schedule and the flush answers
false. - A timeout outside 1 to 5,000 ms throws
IllegalArgumentException.
Changing the App ID
This applies only if your app switches to another LogDrop project at runtime. The SDK makes sure no span is sent with the wrong project's App ID.
LogDrop.setAppId(newAppId) drops the spans queued for the previous App ID; a request already on its way finishes. The SDK adds no traceparent until it has the new project's settings, then sends later spans with the new App ID only.
Upgrading from 2.1.10
Read this if you update an app from SDK 2.1.10. Besides adding tracing, 2.1.11 changes which HTTP records the SDK makes.
- No code change is needed: the SDK migrates its database and starts exporting once HTTP Logging is on. The first launch after the upgrade behaves like a first launch: requests sent before the SDK has the project's settings carry no header.
- HTTP records are now made once per network attempt, so redirects and OkHttp's own retries appear as separate requests. Requests that fail before a connection is made, and responses served from OkHttp's cache, are no longer recorded.
- Disabling the SDK or HTTP Logging stops the export and clears the queued spans.
Check it
After setup, make one test request to confirm that the device span and the backend spans show up in the same trace.
Follow Check it. To see the header itself, use a proxy such as Charles, Proxyman or mitmproxy: the request carries traceparent: 00-<trace ID>-<span ID>-01, and the same trace ID is in Trace Explorer under your package name. In-app HTTP inspectors that run as OkHttp interceptors, such as Chucker, run before LogDrop's interceptor and do not show the header.
Known limits
On Android, some requests are traced differently from what you might expect. Check these cases when a device span is missing or a request starts a new trace.
- The device clock must not run more than 5 minutes ahead of LogDrop's; otherwise the request is refused and its spans are lost.
- Requests your app retries itself start a new trace.
- A request that waits for its retry is resent unchanged, even if one of its spans has meanwhile aged past the 7-day window; LogDrop then refuses the whole request. This needs a device that stays offline for about a week with a retry pending.
.png)