Set up OneAgent for your iOS apps
iOS tvOS
To monitor your mobile app with Dynatrace, you need to create an application in Dynatrace and set up OneAgent for your mobile app.
After that, you might also want to instrument your app's SwiftUI controls, fine-tune the auto-instrumentation features via configuration keys, or capture additional details via manual instrumentation.
Create an app in Dynatrace
To create a mobile application in Dynatrace
- In Dynatrace, go to Mobile.
- Select Create mobile app.
- Enter a name for your application and select Create mobile app. The application settings page opens.
Set up OneAgent
Use CocoaPods, Swift Package Manager, or Carthage to set up Real User Monitoring for your app. You can also follow the manual approach, though it's better to use one of the automated approaches.
You can set up OneAgent as a dynamic XCFramework, static XCFramework (available for OneAgent for iOS version 8.237+), traditional framework, or static library.
You can't combine the static Dynatrace XCFramework and the dynamic Session Replay XCFramework. For Session Replay, both XCFrameworks have to be dynamic.
If you use the static XCFramework, the traditional framework, or the static library to instrument your iOS app, you'll need to perform some additional steps.
Set up OneAgent with CocoaPods
-
Add Dynatrace OneAgent as a dependency within the CocoaPods
Podfile
specification. You can do this by setting up OneAgent as a dynamic XCFramework, static XCFramework, traditional framework, or static library.The traditional framework and the static library were deprecated as they don't support ARM64 Simulator architecture. This architecture is required to build apps on Mac computers with Apple silicon.
-
Add your application's identification keys to the
Info.plist
file. Check the instrumentation wizard in Dynatrace for the exact values. -
Trigger your project build once before using OneAgent SDK or any import declarations in Xcode.
CocoaPods automatically adds OneAgent to your iOS project during the build process.
For more information on Podfiles, see Podfile Syntax Reference.
Set up OneAgent with Swift Package Manager
- In Xcode, select File > Swift Packages > Add Package Dependency.
- Add
https://github.com/Dynatrace/swift-mobile-sdk.git
as the package repository URL. - Select only one package product:
Dynatrace
to add only OneAgentDynatraceSessionReplay
to add both OneAgent and the Session Replay on crashes moduleDo not select
DynatraceSessionReplay
for tvOS, as Session Replay is not available for this operating system.Dynatrace-Static
to add only OneAgent as a static XCFramework
- Perform additional steps depending on the framework you use.
- In Xcode, go to the Build Settings tab of your application target.
- Expand Linking.
- Add the
-ObjC
linker flag to Other Linker Flags.
You can skip this step if your application doesn't have Swift code or doesn't need access to the Dynatrace framework.
We assume that you already created the Objective-C bridging header file for your Swift code in Xcode.
- Make sure you set the bridging header file in your application target build settings.
- Add the following import line to the bridging header file:
#import <DynatraceStatic/Dynatrace.h>
- In Xcode, go to the Build Settings tab of your application target.
- Expand Linking.
- Add the
-ObjC
linker flag to Other Linker Flags.
You can skip this step if your application doesn't have Swift code or doesn't need access to the Dynatrace library.
We assume that you already created the Objective-C bridging header file for your Swift code in Xcode.
- Make sure you set the bridging header file in your application target build settings.
- Add the following import line to the bridging header file:
#import Dynatrace.h
- Add your application's identification keys to the
Info.plist
file. Check the instrumentation wizard in Dynatrace for the exact values. - Trigger your project build once before using OneAgent SDK or any import declarations in Xcode.
To update the package version rule, double-click the product entry in the Swift Packages tab within the Xcode project settings. To change the product selection, remove the package and add it again.
To update the package, select File > Swift Packages > Update to Latest Package Versions in Xcode.
When switching from Carthage to Swift Package Manager, remove the script that you previously added in Xcode to remove iOS Simulator architecture from the release binary. Otherwise, you might have issues when building your project in Xcode 15+.
Set up OneAgent with Carthage
- Add
binary "https://mobileagent.downloads.dynatrace.com/ios/carthage/dynatrace.json" ~> 8.279
to yourCartfile
. - Run
carthage update --use-xcframeworks
.
If you use the deprecated traditionalDynatrace.framework
framework, runcarthage update
. - Add the following framework or frameworks from the Carthage/Build folder to the Frameworks, Libraries and Embedded Content section located within the General tab of your application target, and set it or them to Embed & Sign.
Dynatrace.xcframework
to add only OneAgentDynatrace.xcframework
andDynatraceSessionReplay.xcframework
to add both OneAgent and the Session Replay on crashes moduleDo not add
DynatraceSessionReplay.xcframework
for tvOS, as Session Replay is not available for this operating system.
- Perform some additional steps depending on the framework you use.
- In Xcode, go to the Build Settings tab of your application target.
- Expand Linking.
- Add the
-ObjC
linker flag to Other Linker Flags.
- In Xcode, go to the General tab of your application target.
- Expand Frameworks, Libraries, and Embedded Content.
- Add the
libc++.tbd
library.
You might need to add this library twice. In our internal tests, the library was linked to the project tree only after we added the library a second time.
You can skip this step if your application doesn't have Swift code or doesn't need access to the Dynatrace framework.
We assume that you already created the Objective-C bridging header file for your Swift code in Xcode.
- Make sure you set the bridging header file in your application target build settings.
- Add the following import line to the bridging header file:
#import <DynatraceStatic/Dynatrace.h>
-
In Xcode, add a Run Script phase as the last Build Phase of your application target.
-
Add the following script:
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORKdoFRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"EXTRACTED_ARCHS=()for ARCH in $ARCHSdolipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")donelipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"rm "${EXTRACTED_ARCHS[@]}"rm "$FRAMEWORK_EXECUTABLE_PATH"mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"done -
Select Run script: For install builds only.
This removes the iOS Simulator architecture from your release binary used for AppStore Connect upload.
- In Xcode, go to the Build Settings tab of your application target.
- Expand Linking.
- Add the
-ObjC
linker flag to Other Linker Flags.
You can skip this step if your application doesn't have Swift code or doesn't need access to the Dynatrace library.
We assume that you already created the Objective-C bridging header file for your Swift code in Xcode.
- Make sure you set the bridging header file in your application target build settings.
- Add the following import line to the bridging header file:
#import Dynatrace.h
- Add your application's identification keys to the
Info.plist
file. Check the instrumentation wizard in Dynatrace for the exact values. - Trigger your project build once before using OneAgent SDK or any import declarations in Xcode.
Set up OneAgent manually
-
Access the mobile instrumentation wizard.
-
Select iOS, and then go to the Developer tab.
-
Follow the provided instructions.
Add
Dynatrace.xcframework
to have only OneAgent.
Add bothDynatrace.xcframework
andDynatraceSessionReplay.xcframework
to have both OneAgent and the Session Replay on crashes module.Do not add
DynatraceSessionReplay.xcframework
for tvOS, as Session Replay is not available for this operating system. -
Perform some additional steps depending on the framework you use.
- In Xcode, go to the Build Settings tab of your application target.
- Expand Linking.
- Add the
-ObjC
linker flag to Other Linker Flags.
- In Xcode, go to the General tab of your application target.
- Expand Frameworks, Libraries, and Embedded Content.
- Add the
libc++.tbd
library.
You might need to add this library twice. In our internal tests, the library was linked to the project tree only after we added the library a second time.
You can skip this step if your application doesn't have Swift code or doesn't need access to the Dynatrace framework.
We assume that you already created the Objective-C bridging header file for your Swift code in Xcode.
- Make sure you set the bridging header file in your application target build settings.
- Add the following import line to the bridging header file:
#import <DynatraceStatic/Dynatrace.h>
-
In Xcode, add a Run Script phase as the last Build Phase of your application target.
-
Add the following script:
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORKdoFRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"EXTRACTED_ARCHS=()for ARCH in $ARCHSdolipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")donelipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"rm "${EXTRACTED_ARCHS[@]}"rm "$FRAMEWORK_EXECUTABLE_PATH"mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"done -
Select Run script: For install builds only.
This removes the iOS Simulator architecture from your release binary used for AppStore Connect upload.
- In Xcode, go to the Build Settings tab of your application target.
- Expand Linking.
- Add the
-ObjC
linker flag to Other Linker Flags.
You can skip this step if your application doesn't have Swift code or doesn't need access to the Dynatrace library.
We assume that you already created the Objective-C bridging header file for your Swift code in Xcode.
- Make sure you set the bridging header file in your application target build settings.
- Add the following import line to the bridging header file:
#import Dynatrace.h
-
Trigger your project build once before using OneAgent SDK or any import declarations in Xcode.
Access mobile instrumentation wizard
The mobile instrumentation wizard in Dynatrace provides you with get-started instructions on instrumenting your iOS apps. To follow more detailed instructions, go to the Set up OneAgent section on this page.
The wizard also contains code snippets with your app's identification keys that you'll need to add to the Info.plist
file.
- Go to Mobile.
- Select the mobile application that you want to configure.
- Select More (…) > Edit in the upper-right corner of the tile with your application name.
- From the application settings, select Instrumentation wizard.
Known limitations
-
We don't recommend using several monitoring tools simultaneously with crash reporting or web request instrumentation functionality enabled. This might cause compatibility issues, reporting of wrong or invalid information, and loss of monitoring and crash data. Nevertheless, if you decide to do so, verify via manual testing that these tools are compatible.
-
To use both Dynatrace and Firebase, do one of the following.
Follow only one of the approaches above; don't perform both actions.
-
To use both Dynatrace and mPaaS, do one of the following.
- Disable automatic web request instrumentation in OneAgent for iOS.
- Don't use the MPNebulaAdapter framework.
Follow only one of the approaches above; don't perform both actions.
-
An auto-instrumented application can't carry out functions such as
Dynatrace.shutdown()
or Dynatrace.flushEvents()
. You can manually insert these methods and other user-defined actions and events before performing auto-instrumentation. -
The following controls can't be used to create autogenerated actions:
- Gestures
- Certain
UIBarButton
items, including customUIBarButton
items added to the navigation bar by a storyboard (such asinfo
) that use segues to transition to other views.