- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
Send traces to Datadog from your iOS applications with Datadog’s dd-sdk-ios
client-side tracing library and leverage the following features:
To integrate using Apple’s Swift Package Manager, add the following as a dependency to your Package.swift
:
.package(url: "https://github.com/Datadog/dd-sdk-ios.git", .upToNextMajor(from: "2.0.0"))
In your project, link the following libraries:
DatadogCore
DatadogTrace
You can use CocoaPods to install dd-sdk-ios
:
pod 'DatadogCore'
pod 'DatadogTrace'
You can use Carthage to install dd-sdk-ios
:
github "DataDog/dd-sdk-ios"
In Xcode, link the following frameworks:
DatadogInternal.xcframework
DatadogCore.xcframework
DatadogTrace.xcframework
dd-sdk-ios
library as they would be exposed client-side in the iOS application IPA byte code.For more information about setting up a client token, see the client token documentation.
import DatadogCore
Datadog.initialize(
with: Datadog.Configuration(
clientToken: "<client token>",
env: "<environment>",
service: "<service name>"
),
trackingConsent: trackingConsent
)
DDConfiguration *configuration = [[DDConfiguration alloc] initWithClientToken:@"<client token>" env:@"<environment>"];
configuration.service = @"<service name>";
[DDDatadog initializeWithConfiguration:configuration
trackingConsent:trackingConsent];
import DatadogCore
Datadog.initialize(
with: Datadog.Configuration(
clientToken: "<client token>",
env: "<environment>",
site: .eu1,
service: "<service name>"
),
trackingConsent: trackingConsent
)
DDConfiguration *configuration = [[DDConfiguration alloc] initWithClientToken:@"<client token>" env:@"<environment>"];
configuration.service = @"<service name>";
configuration.site = [DDSite eu1];
[DDDatadog initializeWithConfiguration:configuration
trackingConsent:trackingConsent];
import DatadogCore
Datadog.initialize(
with: Datadog.Configuration(
clientToken: "<client token>",
env: "<environment>",
site: .us3,
service: "<service name>"
),
trackingConsent: trackingConsent
)
DDConfiguration *configuration = [[DDConfiguration alloc] initWithClientToken:@"<client token>" env:@"<environment>"];
configuration.service = @"<service name>";
configuration.site = [DDSite us3];
[DDDatadog initializeWithConfiguration:configuration
trackingConsent:trackingConsent];
import DatadogCore
Datadog.initialize(
with: Datadog.Configuration(
clientToken: "<client token>",
env: "<environment>",
site: .us5,
service: "<service name>"
),
trackingConsent: trackingConsent
)
DDConfiguration *configuration = [[DDConfiguration alloc] initWithClientToken:@"<client token>" env:@"<environment>"];
configuration.service = @"<service name>";
configuration.site = [DDSite us5];
[DDDatadog initializeWithConfiguration:configuration
trackingConsent:trackingConsent];
import DatadogCore
Datadog.initialize(
with: Datadog.Configuration(
clientToken: "<client token>",
env: "<environment>",
site: .us1_fed,
service: "<service name>"
),
trackingConsent: trackingConsent
)
DDConfiguration *configuration = [[DDConfiguration alloc] initWithClientToken:@"<client token>" env:@"<environment>"];
configuration.service = @"<service name>";
configuration.site = [DDSite us1_fed];
[DDDatadog initializeWithConfiguration:configuration
trackingConsent:trackingConsent];
import DatadogCore
Datadog.initialize(
with: Datadog.Configuration(
clientToken: "<client token>",
env: "<environment>",
site: .ap1,
service: "<service name>"
),
trackingConsent: trackingConsent
)
DDConfiguration *configuration = [[DDConfiguration alloc] initWithClientToken:@"<client token>" env:@"<environment>"];
configuration.service = @"<service name>";
configuration.site = [DDSite ap1];
[DDDatadog initializeWithConfiguration:configuration
trackingConsent:trackingConsent];
To be compliant with the GDPR regulation, the SDK requires the trackingConsent
value at initialization.
The trackingConsent
can be one of the following values:
.pending
: The SDK starts collecting and batching the data but does not send it to Datadog. The SDK waits for the new tracking consent value to decide what to do with the batched data..granted
: The SDK starts collecting the data and sends it to Datadog..notGranted
: The SDK does not collect any data: logs, traces, and RUM events are not sent to Datadog.To change the tracking consent value after the SDK is initialized, use the Datadog.set(trackingConsent:)
API call.
The SDK changes its behavior according to the new value. For example, if the current tracking consent is .pending
:
.granted
, the SDK send all current and future data to Datadog;.notGranted
, the SDK wipe all current data and stop collecting any future data.Before data is uploaded to Datadog, it is stored in cleartext in the cache directory (Library/Caches
) of your application sandbox. The cache directory cannot be read by any other app installed on the device.
When writing your application, enable development logs to log to console all internal messages in the SDK with a priority equal to or higher than the provided level.
Datadog.verbosityLevel = .debug
DDDatadog.verbosityLevel = DDSDKVerbosityLevelDebug;
Tracer
as Tracer.shared()
:import DatadogTrace
Trace.enable(
with: Trace.Configuration(
networkInfoEnabled: true
)
)
let tracer = Tracer.shared()
DDTraceConfiguration *configuration = [[DDTraceConfiguration alloc] init];
configuration.networkInfoEnabled = YES;
[DDTrace enableWithConfiguration:configuration];
DDTracer *tracer = [Tracer shared];
let span = tracer.startSpan(operationName: "<span_name>")
// do something you want to measure ...
// ... then, when the operation is finished:
span.finish()
id<OTSpan> span = [tracer startSpan:@"<span_name>"];
// do something you want to measure ...
// ... then, when the operation is finished:
[span finish];
let responseDecodingSpan = tracer.startSpan(
operationName: "response decoding",
childOf: networkRequestSpan.context // make it a child of `networkRequestSpan`
)
// ... decode HTTP response data ...
responseDecodingSpan.finish()
id<OTSpan> responseDecodingSpan = [tracer startSpan:@"response decoding"
childOf:networkRequestSpan.context];
// ... decode HTTP response data ...
[responseDecodingSpan finish];
span.setTag(key: "http.url", value: url)
[span setTag:@"http.url" value:url];
span.log(
fields: [
OTLogFields.event: "error",
OTLogFields.errorKind: "I/O Exception",
OTLogFields.message: "File not found",
OTLogFields.stack: "FileReader.swift:42",
]
)
[span log:@{
@"event": @"error",
@"error.kind": @"I/O Exception",
@"message": @"File not found",
@"stack": @"FileReader.swift:42",
}];
URLRequest
headers:var request: URLRequest = ... // the request to your API
let span = tracer.startSpan(operationName: "network request")
let headersWriter = HTTPHeadersWriter(samplingRate: 20)
tracer.inject(spanContext: span.context, writer: headersWriter)
for (headerField, value) in headersWriter.tracePropagationHTTPHeaders {
request.addValue(value, forHTTPHeaderField: headerField)
}
id<OTSpan> span = [tracer startSpan:@"network request"];
DDHTTPHeadersWriter *headersWriter = [[DDHTTPHeadersWriter alloc] initWithSamplingRate:20];
NSError *error = nil;
[tracer inject:span.context
format:OT.formatTextMap
carrier:headersWriter
error:&error];
for (NSString *key in headersWriter.tracePropagationHTTPHeaders) {
NSString *value = headersWriter.tracePropagationHTTPHeaders[key];
[request addValue:value forHTTPHeaderField:key];
}
This sets additional tracing headers on your request so your backend can extract the request and continue distributed tracing. Once the request is done, call span.finish()
within a completion handler. If your backend is also instrumented with Datadog APM & Distributed Tracing, the entire front-to-back trace appears in the Datadog dashboard.
firstPartyHosts
array in the Datadog initialization, enable URLSessionInstrumentation
for your delegate type and pass the delegate instance to the URLSession:import DatadogTrace
Trace.enable(
with: Trace.Configuration(
urlSessionTracking: Trace.Configuration.URLSessionTracking(
firstPartyHostsTracing: .trace(hosts: ["example.com", "api.yourdomain.com"])
)
)
)
URLSessionInstrumentation.enable(
with: .init(
delegateClass: <YourSessionDelegate>.self,
)
)
let session = URLSession(
configuration: .default,
delegate: <YourSessionDelegate>(),
delegateQueue: nil
)
@import DatadogObjc;
DDTraceFirstPartyHostsTracing *firstPartyHosts = [DDTraceFirstPartyHostsTracing alloc] initWithHosts:@[@"example.com", @"api.yourdomain.com"]
sampleRate: 20];
DDTraceURLSessionTracking *urlSessionTracking = [DDTraceURLSessionTracking alloc] initWithFirstPartyHostsTracing:firstPartyHosts];
DDTraceConfiguration *configuration = [[DDTraceConfiguration] alloc] init];
[configuration setURLSessionTracking:urlSessionTracking];
[DDTrace enableWithConfiguration:configuration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]
delegate:[[DDNSURLSessionDelegate alloc] init]
delegateQueue:nil];
This traces all requests made with this session
to example.com
and api.yourdomain.com
hosts (for example, https://api.yourdomain.com/v2/users
or https://subdomain.example.com/image.png
).
Note: Tracing auto-instrumentation uses URLSession
swizzling and is opt-in. If you do not specify firstPartyHosts
, swizzling is not applied.
All the spans are first stored on the local device in batches. Each batch follows the intake specification. They are sent periodically if network is available, and the battery is high enough to ensure the Datadog 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 being offline, no data will be lost.
The data on disk will automatically be discarded if it gets too old to ensure the SDK doesn’t use too much disk space.
The following attributes in Trace.Configuration
can be used when creating the Tracer:
Method | Description |
---|---|
service | Set the value for the service . |
networkInfoEnabled | Set to true to enrich traces with network connection info (reachability status, connection type, mobile carrier name, and more). |
tags | Set a <KEY>:<VALUE> pair of tags to be added to spans created by the Tracer. |
bundleWithRumEnabled | Set to true to enable spans to be enriched with the current RUM View information. This enables you to see all of the spans produced during a specific View lifespan in the RUM Explorer. |
sampleRate | Set a value 0-100 to define the percentage of Traces to collect. |