DataDog / dd-sdk-ios

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

Xcode 15 builds crash on iOS 16 #1880

Open anuragajwani opened 3 weeks ago

anuragajwani commented 3 weeks ago

Stack trace

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000000000000
    frame #1: 0x0000000106cf6fbc DatadogCore`specialized DatadogContextProvider.__allocating_init(site:clientToken:service:env:version:buildNumber:buildId:variant:source:nativeSourceOverride:sdkVersion:ciAppOrigin:applicationName:applicationBundleIdentifier:applicationVersion:sdkInitDate:device:dateProvider:serverDateProvider:) [inlined] Network.NWPathMonitor.__allocating_init() -> Network.NWPathMonitor at <compiler-generated>:0 [opt]
  * frame #2: 0x0000000106cf6fb4 DatadogCore`specialized DatadogContextProvider.__allocating_init(site:clientToken:service:env:version:buildNumber:buildId:variant:source:nativeSourceOverride:sdkVersion:ciAppOrigin:applicationName:applicationBundleIdentifier:applicationVersion:sdkInitDate:device:dateProvider:serverDateProvider:) [inlined] default argument 0 of DatadogCore.NWPathMonitorPublisher.init(monitor: Network.NWPathMonitor, queue: __C.OS_dispatch_queue) -> DatadogCore.NWPathMonitorPublisher at NetworkConnectionInfoPublisher.swift:36:35 [opt]
    frame #3: 0x0000000106cf6fb4 DatadogCore`specialized DatadogContextProvider.__allocating_init(site=<unavailable>, clientToken=<unavailable>, service=<unavailable>, env=<unavailable>, buildNumber="1", buildId=nil, variant=nil, source="ios", nativeSourceOverride=nil, sdkVersion="2.12.0", ciAppOrigin=nil, applicationName="TK Staging", applicationBundleIdentifier="com.travelperk.tkapp.preproduction", applicationVersion="3.8.0", sdkInitDate=2024-06-04 12:21:15 UTC, device=DatadogInternal.DeviceInfo @ 0x000000016dbb3a30, dateProvider=DatadogInternal.SystemDateProvider @ 0x000000016dbb3720, serverDateProvider=0x0000000280999280) at DatadogCore.swift:432:74 [opt]
    frame #4: 0x0000000106cecf54 DatadogCore`specialized static Datadog.initializeOrThrow(with:trackingConsent:instanceName:) [inlined] DatadogCore.DatadogContextProvider.__allocating_init(site: DatadogInternal.DatadogSite, clientToken: Swift.String, service: Swift.String, env: Swift.String, version: Swift.String, buildNumber: Swift.String, buildId: Swift.Optional<Swift.String>, variant: Swift.Optional<Swift.String>, source: Swift.String, nativeSourceOverride: Swift.Optional<Swift.String>, sdkVersion: Swift.String, ciAppOrigin: Swift.Optional<Swift.String>, applicationName: Swift.String, applicationBundleIdentifier: Swift.String, applicationVersion: Swift.String, sdkInitDate: Foundation.Date, device: DatadogInternal.DeviceInfo, dateProvider: DatadogInternal.DateProvider, serverDateProvider: DatadogCore.ServerDateProvider) -> DatadogCore.DatadogContextProvider at <compiler-generated>:0 [opt]
    frame #5: 0x0000000106cece8c DatadogCore`specialized static Datadog.initializeOrThrow(configuration=DatadogCore.Datadog.Configuration @ 0x000000016dbb4498, trackingConsent=granted, instanceName="main") at Datadog.swift:447:30 [opt]
    frame #6: 0x0000000106ce88e8 DatadogCore`static Datadog.initialize(with:trackingConsent:instanceName:) [inlined] static DatadogCore.Datadog.initializeOrThrow(with: DatadogCore.Datadog.Configuration, trackingConsent: DatadogInternal.TrackingConsent, instanceName: Swift.String) throws -> DatadogInternal.DatadogCoreProtocol at <compiler-generated>:0 [opt]
    frame #7: 0x0000000106ce88e0 DatadogCore`static Datadog.initialize(configuration=<unavailable>, trackingConsent=<unavailable>, instanceName=<unavailable>, self=DatadogCore.Datadog) at Datadog.swift:384:24 [opt]
    frame #8: 0x0000000102269dc8 TK Staging`DatadogApplicationMonitor.startDatadog(self=TK_Staging.DatadogApplicationMonitor @ 0x00000002837c5eb0) at DatadogApplicationMonitor.swift:51:17
    frame #9: 0x0000000102269a04 TK Staging`DatadogApplicationMonitor.start(self=TK_Staging.DatadogApplicationMonitor @ 0x00000002837c5eb0) at DatadogApplicationMonitor.swift:32:9
    frame #10: 0x000000010226ab64 MyApp`protocol witness for ApplicationMonitoring.start() in conformance DatadogApplicationMonitor at <compiler-generated>:0

Reproduction steps

Tech Stack:

  1. Add the following to the Carfile:

    github "Datadog/dd-sdk-ios" ~> 2.12.0
  2. Run carthage update --platform iOS --use-xcframeworks --no-use-binaries.

  3. Add binaries of DataDog and OpenTelemetryApi to app.

  4. Initialise DataDog on launch, here is our config:

        let environment = AppConfiguration.current.environmentConfiguration.environment
        let datadogConfiguration = DatadogConfiguration(
            environmentName: environment.datadogName,
            shouldLogToConsole: environment == .staging
        )
    
        var configuration = Datadog.Configuration(clientToken: thirdPartyKeys.datadogClientToken, env: datadogConfiguration.environmentName)
        configuration.service = "ios"
        configuration.site = .eu1
    
        Datadog.initialize(
            with: configuration,
            trackingConsent: .granted
        )
    
        var rumConfiguration = RUM.Configuration(applicationID: thirdPartyKeys.datadogApplicationId)
        rumConfiguration.uiKitActionsPredicate = DefaultUIKitRUMActionsPredicate()
        rumConfiguration.uiKitViewsPredicate = DatadogRUMViewsPredicate()
        rumConfiguration.urlSessionTracking = RUM.Configuration.URLSessionTracking(
            firstPartyHostsTracing: .trace(hosts: Set(String.allBaseDomains))
        )
    
        RUM.enable(with: rumConfiguration)
    
        Logs.enable()
        let logger = buildLogger(datadogConfiguration: datadogConfiguration)
        logger.info("Logger and RUMMonitor initialized")
    
        let rum = RUMMonitor.shared()
        for (key, value) in Self.customAttributes {
            rum.addAttribute(forKey: key, value: value)
        }
    
        MXMetricManager.shared.add(mxMetricDataDogService)
  5. Run app on physical device running iOS 16.x.x

  6. See it crash on launch

Volume

100% on iOS 16.x.x

Affected SDK versions

2.11.0, 2.12.0

Latest working SDK version

2.11.0 using GH release binary

Does the crash manifest in the latest SDK version?

Yes

Deployment Target

16.0

Device Information

All affected crashes were reported only on iOS 16.x.x only when built through Carthage. Same version of DD did not crash when using the binary/xcframework provided in GH releases tab.

Other relevant information

No response

maxep commented 3 weeks ago

Hi @anuragajwani 👋

I hope you don't mind that I reformatted your report.

I'm not able to reproduce the issue using the following project: OTelCarthage.zip Could you please provide a sample project that replicate the crash? What you describe is very similar to #1509 so there might be an issue re. the minimum target.

I don't see any configuration of DatadogTrace in your snippet, so I wondering if you need to add OpenTelemetryApi as a dependency.

JonathanFuentesF commented 3 weeks ago

Hi @anuragajwani, reported issue: https://github.com/DataDog/dd-sdk-ios/issues/1875 I made a mistake, I'm using SDK ver 2.11.0 and crash is still happening. Screenshot 2024-06-04 at 11 21 05 AM

anuragajwani commented 3 weeks ago

Hi @anuragajwani 👋

I hope you don't mind that I reformatted your report.

I'm not able to reproduce the issue using the following project: OTelCarthage.zip Could you please provide a sample project that replicate the crash? What you describe is very similar to #1509 so there might be an issue re. the minimum target.

I don't see any configuration of DatadogTrace in your snippet, so I wondering if you need to add OpenTelemetryApi as a dependency.

I hope you don't mind that I reformatted your report.

Yes no worries fine with that.

so I wondering if you need to add OpenTelemetryApi

This seems to be only needed in 2.12.0. However we experienced the issue in 2.11.0 too where there doesn't seem to be OpenTelemetryApi.

I'll create a sample project. See if I can reproduce this. However I will have to test this next week as I don't have a device on iOS 16.x.x. I will need to re-borrow the device from a colleague when I see them next week.

maxep commented 3 weeks ago

Hey @anuragajwani & @JonathanFuentesF 👋

We have acknowledge the issue by running on a physical iOS 16 device. The problem is that our SDK still target iOS 11 as a minimum target, by running carthage with --no-use-binaries you are rebuilding the SDK with Xcode 15 and face the same crash as described in #1509.

As a workaround while we work on a fix, you can link our prebuilt xcframeworks with carthage update --platform iOS --use-xcframeworks. Please let us know if that works for you, sorry for the inconvenience.

JonathanFuentesF commented 3 weeks ago

@maxep Thanks for sharing, in my case I'm using cocoa pods what would be the equivalent fix? thanks

maxep commented 3 weeks ago

@JonathanFuentesF For CocoaPods, you can follow the suggestion in https://github.com/DataDog/dd-sdk-ios/issues/1509#issuecomment-1766134828

anuragajwani commented 2 weeks ago

Thanks for looking into it.

As a workaround while we work on a fix, you can link our prebuilt xcframeworks with carthage update --platform iOS --use-xcframeworks

Currently we are using the xcframework published on the release tab as a workaround. However we would like to recompile datadog with the current xcode version that we are using.

ganeshnj commented 1 week ago

We have released 2.13.0 which contains the fix.