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:

Further Reading

Additional helpful documentation, links, and articles:

PREVIEWING: esther/docs-8632-slo-blog-links