newrelic / newrelic-ios-agent-spm

This repository hosts the Swift Package Manager deployment of the iOS agent
Apache License 2.0
15 stars 9 forks source link

NewRelic crashes upon starting if @Observable is used anywhere, on iOS16 and lower #42

Closed diogobalseiro closed 2 months ago

diogobalseiro commented 8 months ago

Description

NewRelicAgent 7.4.8 and earlier (at least as far back to 7.4.0) are incompatible with the new macro @Observable, created in the latest iOS SDK release. This means any codebase using NewRelic cannot use the new macro and deploy for iOS 16 or older.

Steps to Reproduce

Having a class declare the macro @observable , even without being used anywhere and only available to iOS 17, makes the NewRelic agent method NewRelic.start(withApplicationToken:"APP_TOKEN") crash. I've created a sample project here showcasing this issue. It has the basic Xcode template code and NewRelic package added.

If you run the project in the iOS 17 simulator, it all works fine: observable-ios17

If you run on iOS 16.X simulator (and 15.X also), the app crashes on start: observable-ios16

If the NewRelic start method is then commented, everything runs fine again on 16.X and lower. observable-no-nr-ios16

Expected Behavior

NewRelic doesn't crash the app on startup.

Relevant Logs / Console output

The stack trace is seemingly unavailable in the sample project above. However, in the enterprise codebase I work with, I can see the offending code is the swizzling being made by NewRelic on start. However, I can't see which specific selector is being impacted.

Your Environment

Apple M1 Max Sonoma 14.2.1 (23C71) Xcode 15.2 (15C500b)

cdillard-NewRelic commented 8 months ago

Thank you for reporting this issue.

If you don't need interation tracing enabled you may be able to work around this issue by calling the following code on the line before your call to NewRelic.start

        NewRelic.disableFeatures([
            NRMAFeatureFlags.NRFeatureFlag_InteractionTracing
        ])

Full example:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        NewRelic.disableFeatures([
            NRMAFeatureFlags.NRFeatureFlag_InteractionTracing
        ])

        NewRelic.start(withApplicationToken:"APP-TOKEN")

        return true
    }

We have created a ticket on our side to investigate if a fix is possible on the agent side.

diogobalseiro commented 8 months ago

Thanks for the suggestion Chris. Indeed that works around the problem.

We'll wait then for a more oficial solution from the agent side.

dnbrito commented 8 months ago

FYI I faced the same crash but when using Tip.Event (from TipKit, also iOS 17 only). So another case to test when the fix is made.

Disabling InteractionTracing flag before initializing the SDK also worked for me.

NewRelic.disableFeatures(.NRFeatureFlag_InteractionTracing)
NewRelic.start(withApplicationToken: "<TOKEN>")
nunogoncalves commented 5 months ago

Hello! Have you had the change to check this? Thank you!

smalsam-newr commented 2 months ago

This appears to be an issue with the interaction of the Swift Runtime and the way classes are swizzled. Unfortunately, without a back ported fix to iOS 15, we are unable to address this.