Skip to content

Latest commit

 

History

History
351 lines (304 loc) · 12.7 KB

_index.md

File metadata and controls

351 lines (304 loc) · 12.7 KB
title kind beta description aliases further_reading
RUM iOS and tvOS Monitoring
documentation
true
Collect RUM data from your iOS and tvOS applications.
/real_user_monitoring/ios/getting_started
link tag text
Github
dd-sdk-ios Source Code
link tag text
/real_user_monitoring
Documentation
Learn how to explore your RUM data
link tag text
/real_user_monitoring/error_tracking/ios/
Documentation
Learn how to track iOS errors
link tag text
/real_user_monitoring/ios/swiftui/
Documentation
Learn about instrumenting SwiftUI applications

Overview

Datadog Real User Monitoring (RUM) enables you to visualize and analyze the real-time performance and user journeys of your application's individual users.

Setup

  1. Declare the SDK as a dependency.
  2. Specify application details in the UI.
  3. Initialize the library.
  4. Initialize the RUM Monitor, DDURLSessionDelegate, to start sending data.

Note: The minimum supported version for the Datadog iOS SDK is iOS v11+. The Datadog iOS SDK also supports tvOS.

Declare the SDK as a dependency

  1. Declare dd-sdk-ios as a dependency, depending on your package manager.
Package manager Installation method
CocoaPods pod 'DatadogSDK'
Swift Package Manager .package(url: "https://github.com/DataDog/dd-sdk-ios.git", .upToNextMajor(from: "1.0.0"))
Carthage github "DataDog/dd-sdk-ios"

Specify application details in the UI

  1. Navigate to UX Monitoring > RUM Applications > New Application.

  2. Select iOS as the application type and enter an application name to generate a unique Datadog application ID and client token.

  3. To instrument your web views, click the Instrument your webviews toggle. For more information, see Web View Tracking.

  4. To disable automatic user data collection for either client IP or geolocation data, uncheck the boxes for those settings. For more information, see RUM iOS Data Collected.

    {{< img src="real_user_monitoring/ios/ios-create-application.png" alt="Create a RUM application for iOS in Datadog" style="width:100%;border:none" >}}

To ensure the safety of your data, you must use a client token. If you used only Datadog API keys to configure the dd-sdk-ios library, they would be exposed client-side in the iOS application's byte code.

For more information about setting up a client token, see the Client token documentation.

Initialize the library

In the initialization snippet, set an environment name, service name, and version number. In the examples below, app-name specifies the variant of the application that generates data.

For more information, see Using Tags.

{{< site-region region="us" >}} {{< tabs >}} {{% tab "Swift" %}}

Datadog.initialize(
    appContext: .init(),
    trackingConsent: trackingConsent,
    configuration: Datadog.Configuration
        .builderUsing(
            rumApplicationID: "<rum_application_id>",
            clientToken: "<client_token>",
            environment: "<environment_name>"
        )
        .set(serviceName: "app-name")
        .set(endpoint: .us1)
        .trackUIKitRUMViews()
        .trackUIKitRUMActions()
        .trackURLSession()
        .build()
)

{{% /tab %}} {{% tab "Objective-C" %}}

DDConfigurationBuilder *builder = [DDConfiguration builderWithRumApplicationID:@"<rum_application_id>"
                                                                   clientToken:@"<client_token>"
                                                                   environment:@"<environment_name>"];
[builder setWithServiceName:@"app-name"];
[builder setWithEndpoint:[DDEndpoint us1]];
[builder trackUIKitRUMViews];
[builder trackUIKitRUMActions];
[builder trackURLSessionWithFirstPartyHosts:[NSSet new]];

[DDDatadog initializeWithAppContext:[DDAppContext new]
                    trackingConsent:trackingConsent
                      configuration:[builder build]];

{{% /tab %}} {{< /tabs >}} {{< /site-region >}}

{{< site-region region="eu" >}} {{< tabs >}} {{% tab "Swift" %}}

Datadog.initialize(
    appContext: .init(),
    trackingConsent: trackingConsent,
    configuration: Datadog.Configuration
        .builderUsing(
            rumApplicationID: "<rum_application_id>",
            clientToken: "<client_token>",
            environment: "<environment_name>"
        )
        .set(serviceName: "app-name")
        .set(endpoint: .eu1)
        .trackUIKitRUMViews()
        .trackUIKitRUMActions()
        .trackURLSession()
        .build()
)

{{% /tab %}} {{% tab "Objective-C" %}}

DDConfigurationBuilder *builder = [DDConfiguration builderWithRumApplicationID:@"<rum_application_id>"
                                                                   clientToken:@"<client_token>"
                                                                   environment:@"<environment_name>"];
[builder setWithServiceName:@"app-name"];
[builder setWithEndpoint:[DDEndpoint eu1]];
[builder trackUIKitRUMViews];
[builder trackUIKitRUMActions];
[builder trackURLSessionWithFirstPartyHosts:[NSSet new]];

[DDDatadog initializeWithAppContext:[DDAppContext new]
                    trackingConsent:trackingConsent
                      configuration:[builder build]];

{{% /tab %}} {{< /tabs >}} {{< /site-region >}}

{{< site-region region="us3" >}} {{< tabs >}} {{% tab "Swift" %}}

Datadog.initialize(
    appContext: .init(),
    trackingConsent: trackingConsent,
    configuration: Datadog.Configuration
        .builderUsing(
            rumApplicationID: "<rum_application_id>",
            clientToken: "<client_token>",
            environment: "<environment_name>"
        )
        .set(serviceName: "app-name")
        .set(endpoint: .us3)
        .trackUIKitRUMViews()
        .trackUIKitRUMActions()
        .trackURLSession()
        .build()
)

{{% /tab %}} {{% tab "Objective-C" %}}

DDConfigurationBuilder *builder = [DDConfiguration builderWithRumApplicationID:@"<rum_application_id>"
                                                                   clientToken:@"<client_token>"
                                                                   environment:@"<environment_name>"];
[builder setWithServiceName:@"app-name"];
[builder setWithEndpoint:[DDEndpoint us3]];
[builder trackUIKitRUMViews];
[builder trackUIKitRUMActions];
[builder trackURLSessionWithFirstPartyHosts:[NSSet new]];

[DDDatadog initializeWithAppContext:[DDAppContext new]
                    trackingConsent:trackingConsent
                      configuration:[builder build]];

{{% /tab %}} {{< /tabs >}} {{< /site-region >}}

{{< site-region region="us5" >}} {{< tabs >}} {{% tab "Swift" %}}

Datadog.initialize(
    appContext: .init(),
    trackingConsent: trackingConsent,
    configuration: Datadog.Configuration
        .builderUsing(
            rumApplicationID: "<rum_application_id>",
            clientToken: "<client_token>",
            environment: "<environment_name>"
        )
        .set(serviceName: "app-name")
        .set(endpoint: .us5)
        .trackUIKitRUMViews()
        .trackUIKitRUMActions()
        .trackURLSession()
        .build()
)

{{% /tab %}} {{% tab "Objective-C" %}}

DDConfigurationBuilder *builder = [DDConfiguration builderWithRumApplicationID:@"<rum_application_id>"
                                                                   clientToken:@"<client_token>"
                                                                   environment:@"<environment_name>"];
[builder setWithServiceName:@"app-name"];
[builder setWithEndpoint:[DDEndpoint us5]];
[builder trackUIKitRUMViews];
[builder trackUIKitRUMActions];
[builder trackURLSessionWithFirstPartyHosts:[NSSet new]];

[DDDatadog initializeWithAppContext:[DDAppContext new]
                    trackingConsent:trackingConsent
                      configuration:[builder build]];

{{% /tab %}} {{< /tabs >}} {{< /site-region >}}

{{< site-region region="gov" >}} {{< tabs >}} {{% tab "Swift" %}}

Datadog.initialize(
    appContext: .init(),
    trackingConsent: trackingConsent,
    configuration: Datadog.Configuration
        .builderUsing(
            rumApplicationID: "<rum_application_id>",
            clientToken: "<client_token>",
            environment: "<environment_name>"
        )
        .set(serviceName: "app-name")
        .set(endpoint: .us1_fed)
        .trackUIKitRUMViews()
        .trackUIKitRUMActions()
        .trackURLSession()
        .build()
)

{{% /tab %}} {{% tab "Objective-C" %}}

DDConfigurationBuilder *builder = [DDConfiguration builderWithRumApplicationID:@"<rum_application_id>"
                                                                   clientToken:@"<client_token>"
                                                                   environment:@"<environment_name>"];
[builder setWithServiceName:@"app-name"];
[builder setWithEndpoint:[DDEndpoint us1_fed]];
[builder trackUIKitRUMViews];
[builder trackUIKitRUMActions];
[builder trackURLSessionWithFirstPartyHosts:[NSSet new]];

[DDDatadog initializeWithAppContext:[DDAppContext new]
                    trackingConsent:trackingConsent
                      configuration:[builder build]];

{{% /tab %}} {{< /tabs >}} {{< /site-region >}}

The RUM iOS SDK automatically tracks user sessions depending on options provided at the SDK initialization. To add GDPR compliance for your EU users and other initialization parameters to the SDK configuration, see the Set tracking consent documentation.

Initialize the RUM Monitor and DDURLSessionDelegate

Configure and register the RUM Monitor. You only need to do it once, usually in your AppDelegate code:

{{< tabs >}} {{% tab "Swift" %}}

import Datadog

Global.rum = RUMMonitor.initialize()

{{% /tab %}} {{% tab "Objective-C" %}}

@import DatadogObjc;

DDGlobal.rum = [[DDRUMMonitor alloc] init];

{{% /tab %}} {{< /tabs >}}

To monitor requests sent from the URLSession instance as resources, assign DDURLSessionDelegate() as a delegate of that URLSession:

{{< tabs >}} {{% tab "Swift" %}}

let session = URLSession(
    configuration: .default,
    delegate: DDURLSessionDelegate(),
    delegateQueue: nil
)

{{% /tab %}} {{% tab "Objective-C" %}}

NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]
                                                      delegate:[[DDNSURLSessionDelegate alloc] init]
                                                 delegateQueue:nil];

{{% /tab %}} {{< /tabs >}}

Track background events

Tracking background events may lead to additional sessions, which can impact billing. For questions, contact Datadog support.

You can track events such as crashes and network requests when your application is in the background (for example, no active view is available).

Add the following snippet during initialization in your Datadog configuration:

.trackBackgroundEvents()

Track iOS errors

iOS Crash Reporting and Error Tracking displays any issues in your application and the latest available errors. You can view error details and attributes including JSON in the RUM Explorer.

Further Reading

{{< partial name="whats-next/whats-next.html" >}}