- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
There are a few reasons to manually instrument your applications with the OpenTelemetry API:
ddtrace
library’s functionality.The ddtrace
library provides several techniques to help you achieve these goals. The following sections demonstrate how to use the OpenTelemetry API for custom instrumentation to use with Datadog.
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:
OpenTelemetryApi.xcframework
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
)
import DatadogCore
Datadog.initialize(
with: Datadog.Configuration(
clientToken: "<client token>",
env: "<environment>",
site: .eu1,
service: "<service name>"
),
trackingConsent: trackingConsent
)
import DatadogCore
Datadog.initialize(
with: Datadog.Configuration(
clientToken: "<client token>",
env: "<environment>",
site: .us3,
service: "<service name>"
),
trackingConsent: trackingConsent
)
import DatadogCore
Datadog.initialize(
with: Datadog.Configuration(
clientToken: "<client token>",
env: "<environment>",
site: .us5,
service: "<service name>"
),
trackingConsent: trackingConsent
)
import DatadogCore
Datadog.initialize(
with: Datadog.Configuration(
clientToken: "<client token>",
env: "<environment>",
site: .us1_fed,
service: "<service name>"
),
trackingConsent: trackingConsent
)
import DatadogCore
Datadog.initialize(
with: Datadog.Configuration(
clientToken: "<client token>",
env: "<environment>",
site: .ap1,
service: "<service name>"
),
trackingConsent: trackingConsent
)
To be GDPR compliant, 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 sends all current and future data to Datadog;.notGranted
, the SDK wipes all current data and stops 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
import DatadogTrace
import OpenTelemetryApi
Trace.enable(
with: Trace.Configuration(
networkInfoEnabled: true
)
)
OpenTelemetry.registerTracerProvider(
tracerProvider: OTelTracerProvider()
)
let tracer = OpenTelemetry
.instance
.tracerProvider
.get(instrumentationName: "", instrumentationVersion: nil)
let span = tracer.spanBuilder(spanName: "<span_name>").startSpan()
// do something you want to measure ...
// ... then, when the operation is finished:
span.end()
let responseDecodingSpan = tracer.spanBuilder(spanName: "response decoding")
.setParent(networkRequestSpan) // make it child of `networkRequestSpan`
.startSpan()
// ... decode HTTP response data ...
responseDecodingSpan.end()
span.setAttribute(key: "http.url", value: url)
span.status = .error(description: "Failed to decode response")
let linkedSpan = tracer.spanBuilder(spanName: "linked span").startSpan()
linkedSpan.end()
let spanWithLinks = tracer.spanBuilder(spanName: "span with links")
.addLink(spanContext: linkedSpan.context)
.startSpan()
spanWithLinks.end()