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
Create a
WatchAppDelegate.swiftfile in your project, then add a class namedWatchAppDelegatethat inherits fromNSObject. This class should conform to theWKApplicationDelegateprotocol.Add the
applicationDidFinishLaunchingto theWatchAppDelegateclass. As close to the start of theapplicationDidFinishLaunchingfunction, addNewRelic.start(withApplicationToken: "APP_TOKEN"). Be sure to replaceAPP_TOKENwith yourapplication token. Your code might look like this:import WatchKitimport NewRelicclass WatchAppDelegate: NSObject, WKApplicationDelegate {func applicationDidFinishLaunching() {NewRelic.start(withApplicationToken: "APP_TOKEN")return true}}In the main app structure object, add the following snippet:
import NewRelic@mainstruct Watch_App: App {@WKApplicationDelegateAdaptor var appDelegate: WatchAppDelegate}
Enable New Relic with watchOS extension
Add the
WKExtensionDelegateClassNamekey in your WatchKit extension’sInfo.plistfile. This automatically creates a delegate object namedExtensionDelegate. For more information, see WKExtensionDelegate.In the
ExtensionDelegateclass you created, add theapplicationDidFinishLaunchingfunction.As close to the start of
applicationDidFinishLaunchingas possible, addNewRelic.start(withApplicationToken: "APP_TOKEN")replacingAPP_TOKENwith your application token. Your code might look like this:import WatckKitimport NewRelicclass 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:
PLCrashReporteris 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_BackgroundReportingis 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_OfflineStorageis 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.