- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
If you have not set up the RUM iOS SDK yet, follow the in-app setup instructions or refer to the RUM iOS setup documentation.
iOS RUM automatically tracks attributes such as user activity, screens, errors, and network requests. See the RUM Data Collection documentation to learn about the RUM events and default attributes. You can further enrich user session information and gain finer control over the attributes collected by tracking custom events.
In addition to tracking views automatically, you can also track specific distinct views such as viewControllers
when they become visible and interactive. Stop tracking when the view is no longer visible using the following methods in RUMMonitor.shared()
:
.startView(viewController:)
.stopView(viewController:)
For example:
import DatadogRUM
// in your `UIViewController`:
let rum = RUMMonitor.shared()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
rum.startView(viewController: self)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
rum.stopView(viewController: self)
}
@import DatadogObjc;
// in your `UIViewController`:
DDRUMMonitor *rum = [DDRUMMonitor shared];
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[rum startViewWithViewController:self name:nil attributes:nil];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[rum stopViewWithViewController:self attributes:nil];
}
For more details and available options, filter the relevant file on GitHub for the DDRUMMonitor
class.
In addition to RUM’s default attributes, you can measure where your application is spending its time by using the addTiming(name:)
API. The timing measure is relative to the start of the current RUM view.
For example, you can time how long it takes for your hero image to appear:
func onHeroImageLoaded() {
let rum = RUMMonitor.shared()
rum.addTiming(name: "hero_image")
}
- (void)onHeroImageLoad {
[[DDRUMMonitor shared] addTimingWithName:@"hero_image"];
}
Once you set the timing, it is accessible as @view.custom_timings.<timing_name>
. For example, @view.custom_timings.hero_image
.
To create visualizations in your dashboards, create a measure first.
In addition to tracking actions automatically, you can track specific custom user actions (taps, clicks, and scrolls) with the addAction(type:name:)
API.
To manually register instantaneous RUM actions such as .tap
on RUMMonitor.shared()
, use .addAction(type:name:)
. For continuous RUM actions such as .scroll
, use .startAction(type:name:)
or .stopAction(type:name:)
.
For example:
import DatadogRUM
// in your `UIViewController`:
let rum = RUMMonitor.shared()
@IBAction func didTapDownloadResourceButton(_ sender: UIButton) {
rum.addAction(
type: .tap,
name: sender.currentTitle ?? "",
)
}
- (IBAction)didTapDownloadResourceButton:(UIButton *)sender {
NSString *name = sender.currentTitle ? sender.currentTitle : @"";
[[DDRUMMonitor shared] addActionWithType:DDRUMActionTypeTap name:name attributes:@{}];
}
Note: When using .startAction(type:name:)
and .stopAction(type:name:)
, the action type
must be the same. This is necessary for the RUM iOS SDK to match an action start with its completion.
Find more details and available options in the DDRUMMonitor
class.
In addition to tracking resources automatically, you can also track specific custom resources such as network requests or third-party provider APIs. Use the following methods on RUMMonitor.shared()
to manually collect RUM resources:
.startResource(resourceKey:request:)
.stopResource(resourceKey:response:)
.stopResourceWithError(resourceKey:error:)
.stopResourceWithError(resourceKey:message:)
For example:
import DatadogRUM
// in your network client:
let rum = RUMMonitor.shared()
rum.startResource(
resourceKey: "resource-key",
request: request
)
rum.stopResource(
resourceKey: "resource-key",
response: response
)
// in your network client:
[[DDRUMMonitor shared] startResourceWithResourceKey:@"resource-key"
request:request
attributes:@{}];
[[DDRUMMonitor shared] stopResourceWithResourceKey:@"resource-key"
response:response
attributes:@{}];
Note: The String
used for resourceKey
in both calls must be unique for the resource you are calling. This is necessary for the RUM iOS SDK to match a resource’s start with its completion.
Find more details and available options in the DDRUMMonitor
class.
To track specific errors, notify RUMMonitor
when an error occurs with the message, source, exception, and additional attributes. Refer to the Error Attributes documentation.
let rum = RUMMonitor.shared()
rum.addError(message: "error message.")
[[DDRUMMonitor shared] addErrorWithMessage:@"error message." stack:nil source:DDRUMErrorSourceCustom attributes:@{}];
For more details and available options, refer to the code documentation comments in the DDRUMMonitor
class.
In addition to the default RUM attributes captured by the RUM iOS SDK automatically, you can choose to add additional contextual information (such as custom attributes) to your RUM events to enrich your observability within Datadog.
Custom attributes allow you to filter and group information about observed user behavior (such as the cart value, merchant tier, or ad campaign) with code-level information (such as backend services, session timeline, error logs, and network health).
To set a custom global attribute, use RUMMonitor.shared().addAttribute(forKey:value:)
.
RUMMonitor.shared().addAttribute(forKey: "<KEY>", value: "<VALUE>")
.RUMMonitor.shared().addAttribute(forKey: "<KEY>", value: "<UPDATED_VALUE>")
.RUMMonitor.shared().removeAttribute(forKey: "<KEY_TO_REMOVE>")
.Note: You can’t create facets on custom attributes if you use spaces or special characters in your key names. For example, use forKey: "store_id"
instead of forKey: "Store ID"
.
Adding user information to your RUM sessions makes it easy to:
The following attributes are optional, you should provide at least one of them:
Attribute | Type | Description |
---|---|---|
usr.email | String | User email, displayed in the RUM UI if the user name is not present. It is also used to fetch Gravatars. |
usr.id | String | Unique user identifier. |
usr.name | String | User friendly name, displayed by default in the RUM UI. |
To identify user sessions, use the setUserInfo(id:name:email:)
API.
For example:
Datadog.setUserInfo(id: "1234", name: "John Doe", email: "john@doe.com")
[DDDatadog setUserInfoWithId:@"1234" name:@"John Doe" email:@"john@doe.com" extraInfo:@{}];
You can use the following properties in Datadog.Configuration
when creating the Datadog configuration to initialize the library:
backgroundTasksEnabled
UIApplication
methods beginBackgroundTask(expirationHandler:)
and endBackgroundTask:
are used to perform background uploads. Enabling this flag might increase the amount of time that the app operates in the background by 30 seconds. Tasks are normally stopped when there’s nothing to upload or when encountering a blocker to uploading, such as having no internet connection or having a low battery. By default, this flag is set to false
.batchSize
.small
, .medium
, and .large
.bundle
clientToken
encryption
DataEncryption
protocol.env
staging
or production
).proxyConfiguration
serverDateProvider
ServerDateProvider
implementation results in a de-synchronization of the SDK instance and the Datadog servers. This can lead to significant time shifts in RUM sessions or distributed traces.service
site
.us1
.uploadFrequency
.frequent
, .average
, and .rare
.You can use the following properties in RUM.Configuration
when enabling RUM:
actionEventMapper
appHangThreshold
0.1
seconds. To disable reporting, set this value to nil
. For more information, see Add app hang reporting.applicationID
customEndpoint
errorEventMapper
longTaskEventMapper
longTaskThreshold
0.1
seconds.onSessionStart
resourceEventMapper
sessionSampleRate
sessionSampleRate
value must be between 0.0
and 100.0
. A value of 0.0
means no sessions are sent, while 100.0
means that all sessions are sent to Datadog. The default value is 100.0
.telemetrySampleRate
0
and 100
. By default, this is set to 20
.trackFrustrations
true
.trackBackgroundEvents
false
.trackWatchdogTerminations
false
.uiKitActionsPredicate
predicate
by setting the DefaultUIKitRUMActionsPredicate
or implement your own UIKitRUMActionsPredicate
customized for your app.uiKitViewsPredicate
UIViewControllers
as RUM views. You can use default implementation of predicate
by setting the DefaultUIKitRUMViewsPredicate
or implement your own UIKitRUMViewsPredicate
customized for your app.urlSessionTracking
URLSession
tasks (network requests) as RUM resources. The firstPartyHostsTracing
parameter defines hosts that are categorized as first-party
resources (if RUM is enabled) and have tracing information injected (if tracing feature is enabled). The resourceAttributesProvider
parameter defines a closure to provide custom attributes for intercepted resources that is called for each resource collected by the RUM iOS SDK. This closure is called with task information and may return custom resource attributes or nil
if no attributes should be attached.viewEventMapper
vitalsUpdateFrequency
.frequent
(every 100ms), .average
(every 500ms), .rare
(every 1s), and .never
(which disables vitals monitoring).To automatically track views (UIViewControllers
), use the uiKitViewsPredicate
option when enabling RUM. By default, views are named with the view controller’s class name. To customize it, provide your own implementation of the predicate
which conforms to UIKitRUMViewsPredicate
protocol:
public protocol UIKitRUMViewsPredicate {
func rumView(for viewController: UIViewController) -> RUMView?
}
@objc
public protocol DDUIKitRUMViewsPredicate: AnyObject {
func rumView(for viewController: UIViewController) -> DDRUMView?
}
Inside the rumView(for:)
implementation, your app should decide if a given UIViewController
instance should start the RUM view (return value) or not (return nil
). The returned RUMView
value must specify the name
and may provide additional attributes
for the created RUM view.
For instance, you can configure the predicate to use explicit type check for each view controller in your app:
class YourCustomPredicate: UIKitRUMViewsPredicate {
func rumView(for viewController: UIViewController) -> RUMView? {
switch viewController {
case is HomeViewController: return .init(name: "Home")
case is DetailsViewController: return .init(name: "Details")
default: return nil
}
}
}
@interface YourCustomPredicate : NSObject<DDUIKitRUMViewsPredicate>
@end
@implementation YourCustomPredicate
- (DDRUMView * _Nullable)rumViewFor:(UIViewController * _Nonnull)viewController {
if ([viewController isKindOfClass:[HomeViewController class]]) {
return [[DDRUMView alloc] initWithName:@"Home" attributes:@{}];
}
if ([viewController isKindOfClass:[DetailsViewController class]]) {
return [[DDRUMView alloc] initWithName:@"Details" attributes:@{}];
}
return nil;
}
@end
You can even come up with a more dynamic solution depending on your app’s architecture.
For example, if your view controllers use accessibilityLabel
consistently, you can name views by the value of accessibility label:
class YourCustomPredicate: UIKitRUMViewsPredicate {
func rumView(for viewController: UIViewController) -> RUMView? {
guard let accessibilityLabel = viewController.accessibilityLabel else {
return nil
}
return RUMView(name: accessibilityLabel)
}
}
@interface YourCustomPredicate : NSObject<DDUIKitRUMViewsPredicate>
@end
@implementation YourCustomPredicate
- (DDRUMView * _Nullable)rumViewFor:(UIViewController * _Nonnull)viewController {
if (viewController.accessibilityLabel) {
return [[DDRUMView alloc] initWithName:viewController.accessibilityLabel attributes:@{}];
}
return nil;
}
@end
Note: The RUM iOS SDK calls rumView(for:)
many times while your app is running. It is recommended to keep its implementation fast and single-threaded.
To automatically track user tap actions, set the uiKitActionsPredicate
option when enabling RUM.
To automatically track resources (network requests) and get their timing information such as time to first byte or DNS resolution, use the urlSessionTracking
option when enabling RUM and enable URLSessionInstrumentation
:
URLSessionInstrumentation.enable(
with: .init(
delegateClass: <YourSessionDelegate>.self
)
)
let session = URLSession(
configuration: .default,
delegate: <YourSessionDelegate>(),
delegateQueue: nil
)
DDURLSessionInstrumentationConfiguration *config = [[DDURLSessionInstrumentationConfiguration alloc] initWithDelegateClass:[<YourSessionDelegate> class]];
[DDURLSessionInstrumentation enableWithConfiguration:config];
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]
delegate:[[<YourSessionDelegate> alloc] init]
delegateQueue:nil];
If you have more than one delegate type in your app that you want to instrument, you can call URLSessionInstrumentation.enable(with:)
for each delegate type.
Also, you can configure first party hosts using urlSessionTracking
. This classifies resources that match the given domain as “first party” in RUM and propagates tracing information to your backend (if you have enabled Tracing). Network traces are sampled with an adjustable sampling rate. A sampling of 20% is applied by default.
For instance, you can configure example.com
as the first party host and enable both RUM and Tracing features:
import DatadogRUM
RUM.enable(
with: RUM.Configuration(
applicationID: "<rum application id>",
uiKitViewsPredicate: DefaultUIKitRUMViewsPredicate(),
uiKitActionsPredicate: DefaultUIKitRUMActionsPredicate(),
urlSessionTracking: RUM.Configuration.URLSessionTracking(
firstPartyHostsTracing: .trace(hosts: ["example.com"], sampleRate: 20)
)
)
)
URLSessionInstrumentation.enable(
with: .init(
delegateClass: <YourSessionDelegate>.self
)
)
let session = URLSession(
configuration: .default,
delegate: <YourSessionDelegate>(),
delegateQueue: nil
)
This tracks all requests sent with the instrumented session
. Requests matching the example.com
domain are marked as “first party” and tracing information is sent to your backend to connect the RUM resource with its Trace.
@import DatadogObjc;
DDRUMConfiguration *configuration = [[DDRUMConfiguration alloc] initWithApplicationID:@"<rum application id>"];
DDRUMURLSessionTracking *urlSessionTracking = [DDRUMURLSessionTracking new];
[urlSessionTracking setFirstPartyHostsTracing:[DDRUMFirstPartyHostsTracing alloc] initWithHosts:@[@"example.com"] sampleRate:20];
[configuration setURLSessionTracking:urlSessionTracking];
[DDRUM enableWith:configuration];
To add custom attributes to resources, use the URLSessionTracking.resourceAttributesProvider
option when enabling the RUM. By setting attributes provider closure, you can return additional attributes to be attached to tracked resource.
For instance, you may want to add HTTP request and response headers to the RUM resource:
RUM.enable(
with: RUM.Configuration(
...
urlSessionTracking: RUM.Configuration.URLSessionTracking(
resourceAttributesProvider: { request, response, data, error in
return [
"request.headers" : redactedHeaders(from: request),
"response.headers" : redactedHeaders(from: response)
]
}
)
)
)
If you don’t want to track requests, you can disable URLSessionInstrumentation for the delegate type:
URLSessionInstrumentation.disable(delegateClass: <YourSessionDelegate>.self)
[DDURLSessionInstrumentation disableWithDelegateClass:[<YourSessionDelegate> class]];
All “error” and “critical” logs sent with Logger
are automatically reported as RUM errors and linked to the current RUM view:
import DatadogLogs
let logger = Logger.create()
logger.error("message")
logger.critical("message")
@import DatadogObjc;
DDLogger *logger = [DDLogger create];
[logger error:@"message"];
[logger critical:@"message"];
Similarly, all finished spans marked as error are reported as RUM errors:
import DatadogTrace
let span = Tracer.shared().startSpan(operationName: "operation")
// ... capture the `error`
span.setError(error)
span.finish()
// ... capture the `error`
id<OTSpan> span = [[DDTracer shared] startSpan:@"operation"];
[span setError:error];
[span finish];
To modify attributes of a RUM event before it is sent to Datadog or to drop an event entirely, use the Event Mappers API when configuring the RUM iOS SDK:
let configuration = RUM.Configuration(
applicationID: "<rum application id>",
viewEventMapper: { RUMViewEvent in
return RUMViewEvent
}
resourceEventMapper: { RUMResourceEvent in
return RUMResourceEvent
}
actionEventMapper: { RUMActionEvent in
return RUMActionEvent
}
errorEventMapper: { RUMErrorEvent in
return RUMErrorEvent
}
longTaskEventMapper: { RUMLongTaskEvent in
return RUMLongTaskEvent
}
)
DDRUMConfiguration *configuration = [[DDRUMConfiguration alloc] initWithApplicationID:@"<rum application id>"];
[configuration setViewEventMapper:^DDRUMViewEvent * _Nonnull(DDRUMViewEvent * _Nonnull RUMViewEvent) {
return RUMViewEvent;
}];
[configuration setErrorEventMapper:^DDRUMErrorEvent * _Nullable(DDRUMErrorEvent * _Nonnull RUMErrorEvent) {
return RUMErrorEvent;
}];
[configuration setResourceEventMapper:^DDRUMResourceEvent * _Nullable(DDRUMResourceEvent * _Nonnull RUMResourceEvent) {
return RUMResourceEvent;
}];
[configuration setActionEventMapper:^DDRUMActionEvent * _Nullable(DDRUMActionEvent * _Nonnull RUMActionEvent) {
return RUMActionEvent;
}];
[configuration setLongTaskEventMapper:^DDRUMLongTaskEvent * _Nullable(DDRUMLongTaskEvent * _Nonnull RUMLongTaskEvent) {
return RUMLongTaskEvent;
}];
Each mapper is a Swift closure with a signature of (T) -> T?
, where T
is a concrete RUM event type. This allows changing portions of the event before it is sent.
For example, to redact sensitive information in a RUM Resource’s url
, implement a custom redacted(_:) -> String
function and use it in resourceEventMapper
:
let configuration = RUM.Configuration(
applicationID: "<rum application id>",
resourceEventMapper: { RUMResourceEvent in
var RUMResourceEvent = RUMResourceEvent
RUMResourceEvent.resource.url = redacted(RUMResourceEvent.resource.url)
return RUMResourceEvent
}
)
DDRUMConfiguration *configuration = [[DDRUMConfiguration alloc] initWithApplicationID:@"<rum application id>"];
[configuration setResourceEventMapper:^DDRUMResourceEvent * _Nullable(DDRUMResourceEvent * _Nonnull RUMResourceEvent) {
return RUMResourceEvent;
}];
Returning nil
from the error, resource, or action mapper drops the event entirely; the event is not sent to Datadog. The value returned from the view event mapper must not be nil
(to drop views, customize your implementation of UIKitRUMViewsPredicate
; read more in tracking views automatically).
Depending on the event’s type, only some specific properties can be modified:
Event Type | Attribute key | Description |
---|---|---|
RUMActionEvent | RUMActionEvent.action.target?.name | Name of the action. |
RUMActionEvent.view.url | URL of the view linked to this action. | |
RUMErrorEvent | RUMErrorEvent.error.message | Error message. |
RUMErrorEvent.error.stack | Stacktrace of the error. | |
RUMErrorEvent.error.resource?.url | URL of the resource the error refers to. | |
RUMErrorEvent.view.url | URL of the view linked to this error. | |
RUMResourceEvent | RUMResourceEvent.resource.url | URL of the resource. |
RUMResourceEvent.view.url | URL of the view linked to this resource. | |
RUMViewEvent | RUMViewEvent.view.name | Name of the view. |
RUMViewEvent.view.url | URL of the view. |
Retrieving the RUM session ID can be helpful for troubleshooting. For example, you can attach the session ID to support requests, emails, or bug reports so that your support team can later find the user session in Datadog.
You can access the RUM session ID at runtime without waiting for the sessionStarted
event:
RumMonitor.shared().currentSessionID(completion: { sessionId in
currentSessionId = sessionId
})
To be compliant with the GDPR regulation, the RUM iOS SDK requires the tracking consent value at initialization.
The trackingConsent
setting can be one of the following values:
.pending
: The RUM iOS SDK starts collecting and batching the data but does not send it to Datadog. The RUM iOS SDK waits for the new tracking consent value to decide what to do with the batched data..granted
: The RUM iOS SDK starts collecting the data and sends it to Datadog..notGranted
: The RUM iOS SDK does not collect any data. No logs, traces, or RUM events are sent to Datadog.To change the tracking consent value after the RUM iOS SDK is initialized, use the Datadog.set(trackingConsent:)
API call. The RUM iOS SDK changes its behavior according to the new value.
For example, if the current tracking consent is .pending
:
.granted
, the RUM iOS SDK sends all current and future data to Datadog;.notGranted
, the RUM iOS SDK wipes all current data and does not collect future data.You can use the addUserExtraInfo
API to append extra user properties to previously set properties.
public static func addUserExtraInfo(
_ extraInfo: [AttributeKey: AttributeValue?],
in core: DatadogCoreProtocol = CoreRegistry.default
) {
let core = core as? DatadogCore
core?.addUserExtraInfo(extraInfo)
}
The iOS SDK first stores events locally and only uploads events when the intake specifications conditions are met.
You have the option of deleting all unsent data stored by the SDK with the clearAllData
API.
public static func clearAllData(in core: DatadogCoreProtocol = CoreRegistry.default) {
let core = core as? DatadogCore
core?.clearAllData()
}
You can use the StopInstance
API to stop a named SDK instance (or the default instance if the name is null) from collecting and uploading data further.
public static func stopInstance(named instanceName: String = CoreRegistry.defaultInstanceName) {
let core = CoreRegistry.unregisterInstance(named: instanceName) as? DatadogCore
core?.stop()
}
You can define the minimum log level (priority) at which to send events to Datadog in a logger instance. If the log’s priority is below the one you set in this threshold, the log does not get sent. The default value is debug
(send all logs).
public init(
service: String? = nil,
name: String? = nil,
networkInfoEnabled: Bool = false,
bundleWithRumEnabled: Bool = true,
bundleWithTraceEnabled: Bool = true,
remoteSampleRate: Float = 100,
remoteLogThreshold: LogLevel = .debug,
consoleLogFormat: ConsoleLogFormat? = nil
) {
self.service = service
self.name = name
self.networkInfoEnabled = networkInfoEnabled
self.bundleWithRumEnabled = bundleWithRumEnabled
self.bundleWithTraceEnabled = bundleWithTraceEnabled
self.remoteSampleRate = remoteSampleRate
self.remoteLogThreshold = remoteLogThreshold
self.consoleLogFormat = consoleLogFormat
}