Prerequisites
- The Atatus SDK initialized in your application. See Android Monitoring Setup.
- A RUM application in Atatus, which provisions the license key the SDK authenticates with.
If your
minSdkVersion is below 26, enable Java 8+ library desugaring in your Gradle configuration. The tracer depends on java.time APIs that are unavailable on earlier API levels without it.Setup
1. Add the trace dependencies
Declare the trace library and the OkHttp integration in your application module’s build script:2. Initialize the SDK
Traces share the core SDK instance with RUM, so initialization is identical to Android Monitoring Setup. Skip this step if the SDK is already initialized in yourApplication class:
3. Enable the trace feature
Enabling the feature registers the trace pipeline. Registering a global tracer then makes it reachable from anywhere in your code without passing an instance through your call graph:4. Set the sample rate
Sampling is decided at the trace level and propagates to every span beneath it, so a sampled trace is never partially recorded. Set the rate, service name, and partial flush threshold when building the tracer:5. Instrument network requests
AtatusInterceptor sits in the OkHttp interceptor chain, opens a span per request, and injects trace context headers on hosts you declare. List only the hosts you control, since the headers are meaningless to third-party services:
tracedHosts and the receiving service runs Atatus APM, the propagated context joins the mobile span to its backend trace.
6. Create custom spans
Resolve the global tracer and wrap any operation whose latency you want measured:7. Activate and nest spans
Activating a span binds it to the current scope, so spans started inside that scope are parented to it automatically. Close the scope and finish the span in afinally block, or an early return leaves the span open:
8. Add tags and errors to spans
Tags add queryable dimensions to a span, and error logging marks it as failed so it surfaces in error rate aggregations:9. Link traces with RUM
RUM bundling stamps each span with the active view and session, which is what lets you pivot from a slow trace to the user journey that triggered it:Next steps
- Track views, actions, and errors with Android Monitoring Setup.
- Correlate logs with your traces using Log Collection.
- Connect mobile traces to your backend with Application Monitoring.