LogDrop

Tracing

Trace iOS requests from the device into your backend with the LogDrop iOS SDK.

The iOS SDK adds a W3C traceparent header to every URLSession 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

Tracing is part of the iOS SDK from version 2.1.11, so you only need to update the SDK. Earlier versions do not trace requests.

With Swift Package Manager, use https://github.com/initialcodess/LogDrop-iOS at 2.1.11 or later. With CocoaPods, install from the LogDrop-iOS git repository and run pod update LogDrop in an existing project. See SDK Installation.

2. Initialize as usual

Tracing needs no extra code. The usual initialization below is enough.

import LogDropSDK

let config = LogDropConfig.Builder()
    .setAppId("YOUR_APP_ID")
    .setBaseUrl("YOUR_BASE_URL")        // optional: self-hosted LogDrop
    .build()

LogDrop.initialize(with: config)

Initialize in application(_:didFinishLaunchingWithOptions:), or in your App initializer, before the app makes requests. The App ID is all the SDK needs: it sends spans to <base URL>/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 bundle identifier, and the service version is your app's version. No Info.plist entry or background mode is needed for tracing.

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 requests made through the networking APIs it instruments. This section lists which iOS requests get a traceparent header and a span.

  • URLSession requests on URLSession.shared and on sessions created with the default or ephemeral configuration, which covers most networking libraries (Alamofire and similar build on these).
  • Not traced: background sessions (URLSessionConfiguration.background), sessions whose protocolClasses your app replaces, and requests made inside a WKWebView.
  • Each redirect is its own span in the same trace, and every hop is checked against the ignore rules again; an ignored hop is sent without the header.
  • Both Ignored domains (the host and its subdomains) and Ignored host and path rules stop tracing.

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 iOS.

Spans are kept in an encrypted queue (AES-GCM with a Keychain key, at most 1,000 spans). About 15 seconds after the first span is queued, the SDK sends them when the network is available, in requests 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. When the app moves to the background, the SDK asks iOS for a little time to finish sending; anything left goes out on the next launch.

A 400 answer drops the request. 408, 425, 429, 5xx and transport failures are retried after 10 and then 20 seconds, 3 attempts in all, also across an app restart; newer spans wait until that request is resolved. Spans older than about 7 days or more than 5 minutes ahead of the device clock are dropped before sending, also when a waiting request is resent. Other error answers, and successful answers that cannot be read, drop the request.

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.

LogDrop.flushOtlpTracing { delivered in
    // Runs on the main queue. true: the queue was delivered and no span was lost since the previous flush.
}

The flush waits for the first network status. It has no timeout of its own: each request can take up to 10 seconds, and a backlog is sent request by request before the completion reports true. While a request waits for its retry, the device is offline, or HTTP Logging is not confirmed, the completion reports false; the spans are still sent later. Objective-C callers use logDropFlushOtlpTracing: with an NSNumber completion.

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(...) keeps only the new project's spans. A request already on its way finishes under its own App ID; export pauses until the SDK has the new project's settings, and the next request carries only spans of the new project.

Disabling

Tracing runs only while the SDK is enabled and HTTP Logging is on for the project. This is what happens to queued spans when either is turned off.

Disabling the SDK or HTTP Logging clears the queue once the SDK has LogDrop's confirmed configuration. Before that (on the first launch, or after a new App ID), export only pauses.

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. In a proxy such as Charles or Proxyman, the outgoing request carries traceparent: 00-<trace ID>-<span ID>-01; the same trace ID is in Trace Explorer under your bundle identifier.

Known limits

On iOS, some requests are traced differently from what you might expect. Check these cases when a trace looks incomplete or a request starts a new trace.

  • URLSession's own retries share one client span. When a reused connection closes before any response, URLSession may resend an idempotent request by itself. The SDK cannot see that retry, so both attempts carry the same traceparent: the trace stays connected, but the device side shows one attempt.
  • Ignore rules on later launches. The SDK learns the ignore rules from the project's settings on each launch. Requests sent before the settings arrive can carry traceparent even to ignored hosts, and are sent as spans.
  • 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.

On this page