Troubleshooting iOS SDK issues
Overview
If you experience unexpected behavior with Datadog RUM, use this guide to resolve issues quickly. If you continue to have trouble, contact Datadog Support for further assistance.
Check if Datadog SDK is properly initialized
After you configure Datadog SDK and run the app for the first time, check your debugger console in Xcode. The SDK implements several consistency checks and outputs relevant warnings if something is misconfigured.
Debugging
When writing your application, you can enable development logs by setting the verbosityLevel
value. Relevant messages from the SDK with a priority equal to or higher than the provided level are output to the debugger console in Xcode:
Datadog.verbosityLevel = .debug
You should then see an output similar to the below, indicating that a batch of RUM data was properly uploaded:
[DATADOG SDK] 🐶 → 17:23:09.849 [DEBUG] ⏳ (rum) Uploading batch...
[DATADOG SDK] 🐶 → 17:23:10.972 [DEBUG] → (rum) accepted, won't be retransmitted: success
Recommendation: Use Datadog.verbosityLevel
in the DEBUG
configuration, and unset it in RELEASE
.
Using DDURLSessionDelegate
with your own session delegate
If you want to automatically track network requests with DDURLSessionDelegate
but your app already implements its own session delegate, you can use either inheritance or composition patterns and forward calls to DDURLSessionDelegate
.
When using an inheritance pattern, use DDURLSessionDelegate
as a base class for your custom delegate and make sure to call the super
implementation from your overridden methods. For example:
class YourCustomDelegateURLSessionDelegate: DDURLSessionDelegate {
override func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
super.urlSession(session, task: task, didCompleteWithError: error) // forward to Datadog delegate
/* your custom logic */
}
}
When using a composition pattern, leverage Datadog’s __URLSessionDelegateProviding
protocol to keep an internal instance of DDURLSessionDelegate
and forward calls to ddURLSessionDelegate
. For example:
private class YourCustomDelegateURLSessionDelegate: NSObject, URLSessionTaskDelegate, URLSessionDataDelegate, __URLSessionDelegateProviding {
// MARK: - __URLSessionDelegateProviding conformance
let ddURLSessionDelegate = DDURLSessionDelegate()
// MARK: - __URLSessionDelegateProviding handling
func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) {
ddURLSessionDelegate.urlSession(session, task: task, didFinishCollecting: metrics) // forward to Datadog delegate
/* your custom logic */
}
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
ddURLSessionDelegate.urlSession(session, task: task, didCompleteWithError: error) // forward to Datadog delegate
/* your custom logic */
}
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
ddURLSessionDelegate.urlSession(session, dataTask: dataTask, didReceive: data) // forward to Datadog delegate
/* your custom logic */
}
}
Note: If using composition, ddURLSessionDelegate
must receive all necessary calls listed in __URLSessionDelegateProviding
protocol comments. Your delegate needs to:
- implement
URLSessionTaskDelegate
and forward: - implement
URLSessionDataDelegate
and forward:
Sending data when device is offline
RUM ensures availability of data when your user device is offline. In cases of low-network areas, or when the device battery is too low, all the RUM events are first stored on the local device in batches. They are sent as soon as the network is available, and the battery is high enough to ensure the RUM iOS SDK does not impact the end user’s experience. If the network is not available while your application is in the foreground, or if an upload of data fails, the batch is kept until it can be sent successfully.
This means that even if users open your application while offline, no data is lost.
Note: The data on the disk is automatically discarded if it gets too old to ensure the RUM iOS SDK does not use too much disk space.
Further Reading
Additional helpful documentation, links, and articles: