URLSession itself, any client built on URLSession is covered, including Alamofire, Apollo, SDWebImage, and generated OpenAPI clients.
Prerequisites
- RUM is set up in your application. See iOS Monitoring Setup.
Report requests as resources
Resource tracking is off until you seturlSessionTracking on the RUM configuration. Setting it to an empty configuration is enough:
URLSession.shared, sessions you create yourself, completion handler APIs, and async/await calls, with no change to your request code.
Unlike other SDKs you may have used, you do not have to supply a
URLSessionDelegate to get resources. A delegate is only needed for the timing breakdown described below.Add the duration breakdown
To see where a request spent its time, which means DNS, connect, TLS, time to first byte, and download, register a delegate class of your own. It can be empty, because the SDK adds the delegate methods it needs:Connect resources to backend traces
List the hosts you own infirstPartyHostsTracing so the SDK injects trace headers and records the trace and span IDs on the resource:
example.com also covers api.example.com. See Trace Collection for the headers that are injected, the supported formats, and what the backend needs.
firstPartyHostsTracing controls trace propagation only. Resources are reported for every host either way, so there is no need to list a third-party API you do not instrument.Capture request and response headers
Header capture is off by default. Turning on the defaults records the headers that explain caching and content negotiation:
To add headers of your own, list them by name. Matching ignores case, and the names apply to both the request and the response:
Attach your own attributes to a resource
A resource attributes provider runs once per request and returns the attributes to attach:data contains:
- It is
nilforasync/awaitrequests. - It is
nilfor images, video, audio, and binary downloads. - It is
nilwhen the body is larger than 512 KB, so the SDK does not hold a large response in memory.
Drop resources you do not want
Health checks and polling endpoints add volume without adding insight. Drop them with a resource event mapper:nil drops the resource. Returning a modified event is how you redact a URL that embeds an identifier or a token.
Track a request manually
For a client that does not useURLSession, report the request yourself. Start it with a key that is unique among the requests in flight, then stop it with the same key:
document, xhr, beacon, fetch, css, js, image, font, media, other, and native. If you have a URLResponse, pass it instead of the status code and kind, and if you have URLSessionTaskMetrics, add them with addResourceMetrics(resourceKey:metrics:) before stopping the resource.
A manually tracked resource carries no trace context, so it cannot be linked to a backend trace. To correlate a non-
URLSession client with your backend, create a span and inject its headers yourself. See Trace Collection.Report GraphQL operations
GraphQL requests all share one URL, which makes them indistinguishable in a dashboard. Pass the operation details as request headers and the SDK turns them into resource attributes, removing the headers before the request leaves the device:
With an Apollo client, set them in an interceptor. The SDK also extracts the
errors array from a GraphQL response, which is how a request that returns HTTP 200 with errors still shows up as a failure. That extraction needs the response body, so it works for completion handler requests and for instrumented delegates under the 512 KB limit.
Other clients
Objective-C
Resource tracking is configured onATRUMConfiguration, and the duration breakdown through ATURLSessionInstrumentation:
Next steps
- Propagate trace context and emit spans with Trace Collection.
- Report failed requests as errors with Error Tracking.
- Review the rest of the RUM options in Configuration Options.