DataDog / dd-sdk-ios

Datadog SDK for iOS - Swift and Objective-C.
Apache License 2.0
219 stars 127 forks source link

RUM + Tracer works only one way #1571

Closed mswswing closed 11 months ago

mswswing commented 11 months ago

Version: 2.5.0

Implementation 1

Datadog.initialize(
    with: Datadog.Configuration(
        clientToken: clientToken,
        env: environment,
        site: .us1,
        service: serviceName
    ),
    trackingConsent: .granted
)
Datadog.setUserInfo(id: UIDevice.current.identifierForVendor?.uuidString ?? "")
RUM.enable(
    with: RUM.Configuration(
        applicationID: appID,
        uiKitViewsPredicate: DefaultUIKitRUMViewsPredicate(),
        uiKitActionsPredicate: DefaultUIKitRUMActionsPredicate(),
        urlSessionTracking: RUM.Configuration.URLSessionTracking(firstPartyHostsTracing: .trace(
            hosts: [
                "domain.com"
            ],
            sampleRate: sampleRate
        ))
    )
)
Trace.enable(
    with: Trace.Configuration(
        sampleRate: sampleRate,
        service: serviceName,
        urlSessionTracking: Trace.Configuration.URLSessionTracking(
            firstPartyHostsTracing: .trace(
                hosts: [
                    "domain.com"
                ],
                sampleRate: sampleRate
            )
        ),
        bundleWithRumEnabled: false,
        networkInfoEnabled: false
    )
)
URLSessionInstrumentation.enable(with: .init(
    delegateClass: SessionDelegate.self,
    firstPartyHostsTracing: .trace(hosts: [
        "domain.com"
    ])
))
SessionReplay.enable(
    with: SessionReplay.Configuration(
        replaySampleRate: sampleRate,
        defaultPrivacyLevel: .allow
    )
)

let session = Session(
    configuration: configuration,
    interceptor: DDRequestInterceptor(),
    redirectHandler: redirector,
    eventMonitors: [DDEventMonitor()]
)

Implementation 2

Datadog.initialize(
    with: Datadog.Configuration(
        clientToken: clientToken,
        env: environment,
        site: .us1,
        service: serviceName
    ),
    trackingConsent: .granted
)
Datadog.setUserInfo(id: UIDevice.current.identifierForVendor?.uuidString ?? "")
RUM.enable(
    with: RUM.Configuration(
        applicationID: appID,
        uiKitViewsPredicate: DefaultUIKitRUMViewsPredicate(),
        uiKitActionsPredicate: DefaultUIKitRUMActionsPredicate(),
    )
)
Trace.enable(
    with: Trace.Configuration(
        sampleRate: sampleRate,
        service: serviceName,
        urlSessionTracking: Trace.Configuration.URLSessionTracking(
            firstPartyHostsTracing: .trace(
                hosts: [
                    "domain.com"
                ],
                sampleRate: sampleRate
            )
        ),
        bundleWithRumEnabled: false,
        networkInfoEnabled: false
    )
)
URLSessionInstrumentation.enable(with: .init(
    delegateClass: SessionDelegate.self,
    firstPartyHostsTracing: .trace(hosts: [
        "domain.com"
    ])
))
SessionReplay.enable(
    with: SessionReplay.Configuration(
        replaySampleRate: sampleRate,
        defaultPrivacyLevel: .allow
    )
)

let session = Session(
    configuration: configuration,
    interceptor: DDRequestInterceptor(),
    redirectHandler: redirector,
    eventMonitors: [DDEventMonitor()]
)

urlSessionTracking configuration removed on RUM

Problem

Inspect

Screenshot of Google Chrome (2023-12-01 3-14-47 PM) Screenshot of Google Chrome (2023-12-01 3-14-37 PM)

I need help

Thanks

maxep commented 11 months ago

Hi @mswswing ! Thank you for the detailed report, it is super clear.

When using RUM, what we offer is a RUM-to-APM distributing tracing integration. This integration prevents from sending Span events to APM, instead a Trace is created backend side when a RUM Resource is received. That's why the TracingURLSessionHandler is not invoked when using RUM. I will ask internally why the RUM-to-APM does not generate service data in APM.

Thanks again 🙏

mswswing commented 11 months ago

Answer cleared thanks