• /
  • EnglishEspañol日本語한국어Português
  • Log inStart now

Instrument your watchOS project with New Relic

This doc walks you through how to update your watchOS project so you can monitor with New Relic. Because watchOS projects don't already contain an ApplicationDelegate or ExtensionDelegate class, you'll need to add one or the other to your project. These delegates are necessary to configure and start the New Relic agent in a watchOS project.

Requirements

Before adding the WatchAppDelegate, first install the New Relic agent.

Important

To ensure proper instrumentation, you must configure and start the agent as the first step in applicationDidFinishLaunching() and then run the agent on the main thread. Starting the call later, on a background thread or asynchronously, can cause unexpected or unstable behavior.

After you've installed the agent, see the instructions below for using either WatchAppDelegate or the watchOs extension.

Enable New Relic with WatchAppDelegate

  1. Create a WatchAppDelegate.swift file in your project, then add a class named WatchAppDelegate that inherits from NSObject. This class should conform to the WKApplicationDelegate protocol.

  2. Add the applicationDidFinishLaunching to the WatchAppDelegate class. As close to the start of the applicationDidFinishLaunching function, add NewRelic.start(withApplicationToken: "APP_TOKEN"). Be sure to replace APP_TOKEN with yourapplication token. Your code might look like this:

    import WatchKit
    import NewRelic
    class WatchAppDelegate: NSObject, WKApplicationDelegate {
    func applicationDidFinishLaunching() {
    NewRelic.start(withApplicationToken: "APP_TOKEN")
    return true
    }
    }
  3. In the main app structure object, add the following snippet:

    import NewRelic
    @main
    struct Watch_App: App {
    @WKApplicationDelegateAdaptor var appDelegate: WatchAppDelegate
    }

Enable New Relic with watchOS extension

  1. Add the WKExtensionDelegateClassName key in your WatchKit extension’s Info.plist file. This automatically creates a delegate object named ExtensionDelegate. For more information, see WKExtensionDelegate.

  2. In the ExtensionDelegate class you created, add the applicationDidFinishLaunching function.

  3. As close to the start of applicationDidFinishLaunching as possible, add NewRelic.start(withApplicationToken: "APP_TOKEN") replacing APP_TOKEN with your application token. Your code might look like this:

    import WatckKit
    import NewRelic
    class ExtensionDelegate: NSObject, WKExtensionDelegate {
    func applicationDidFinishLaunching() {
    NewRelic.start(withApplicationToken: "APP_TOKEN")
    return true
    }
    }

Limitations to the watchOS platform

Apple doesn't provide the same iOS APIs to the watchOS platform. This means that certain iOS agent features are not yet available on watchOS. We seek to have parity in our platforms, so as Apple releases new functionality, we will continue to update the agent. Here are some known, currently unsupported features:

  • Crash handling: PLCrashReporter is a third party library that the agent uses, which is not compatible with watchOS.
  • Crash count: Because crashes are not reported on watchOS, we can't collect crash count.
  • Handled exceptions: The agent captures and uploads handled exceptions, but New Relic can't currently display them.
  • Background harvesting: If NRFeatureFlag_BackgroundReporting is enabled, the agent will continue to monitor the application, but won't harvest or upload to New Relic while in background.
  • Offline marked events: If NRFeatureFlag_OfflineStorage is enabled, the agent can store offline harvests and then send them when it's online. Events created in an offline state, however, won't be marked as such on the attribute level.
  • Hot/Cold app start times: The agent depends on UIKit notifications to capture hot/cold start times, but this information is not yet available for watchOS.

If you need additional help, you can reach support at support.newrelic.com.

Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.