dt-obs-ios
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDynatrace iOS SDK Setup
Dynatrace iOS SDK 设置
This skill sets up the Dynatrace iOS SDK (OneAgent) in the user's iOS project — from zero to first event. It follows the official setup flow from the Dynatrace documentation.
此技能可在用户的iOS项目中完成Dynatrace iOS SDK(OneAgent)的设置——从零基础到生成首个监控事件。流程遵循Dynatrace 官方文档中的官方设置步骤。
When to use this skill
何时使用此技能
- The user wants to add Dynatrace monitoring to their iOS app
- The user asks to integrate, install, or set up the Dynatrace iOS SDK
- The user wants to instrument their iOS app with Dynatrace
- The user pastes a setup prompt copied from the Experience Vitals wizard
- 用户希望为其iOS应用添加Dynatrace监控
- 用户要求集成、安装或设置Dynatrace iOS SDK
- 用户希望为其iOS应用接入Dynatrace埋点
- 用户粘贴了从Experience Vitals向导复制的设置提示
Pre-filled values
预填充值
When invoked from the Experience Vitals wizard, the user's message will contain
pre-filled configuration values in a fenced block labeled
. Example:
dynatrace-ios-setup-configtext
```dynatrace-ios-setup-config
DTXApplicationID: ABC-123
DTXBeaconURL: https://example.dynatrace.com/mbeacon
Product: DynatraceSessionReplay
DTXUserOptIn: true
```When these values are present:
- Skip step 2 (Collect application identification keys) — use the provided
and
DTXApplicationID.DTXBeaconURL - Skip the product question in step 3 — use the provided value (
ProductorDynatrace).DynatraceSessionReplay - Use to determine whether to add the privacy opt-in code in step 5. If
DTXUserOptIn, add the opt-in code. Iftrue, skip step 5.false
All other steps (prerequisites, SPM dependency, plist creation, import, build,
verify) proceed as normal.
当从Experience Vitals向导调用此技能时,用户的消息中会包含一个标记为的代码块,其中包含预填充的配置值。示例:
dynatrace-ios-setup-configtext
```dynatrace-ios-setup-config
DTXApplicationID: ABC-123
DTXBeaconURL: https://example.dynatrace.com/mbeacon
Product: DynatraceSessionReplay
DTXUserOptIn: true
```当存在这些值时:
- 跳过步骤2(收集应用标识密钥)——使用提供的和
DTXApplicationID。DTXBeaconURL - 跳过步骤3中的产品选择问题——使用提供的值(
Product或Dynatrace)。DynatraceSessionReplay - 使用值决定是否在步骤5中添加隐私授权代码。如果为
DTXUserOptIn,则添加授权代码;如果为true,则跳过步骤5。false
所有其他步骤(前置检查、SPM依赖项添加、plist文件创建、导入语句添加、构建、验证)均正常执行。
Procedure
操作步骤
1. Check prerequisites
1. 检查前置条件
Actively verify each prerequisite before proceeding. If any check fails, inform the user and stop.
a) Xcode MCP server is available
This is a hard requirement. The skill uses the Xcode MCP server to interact with the Xcode project (adding SPM dependencies, building, etc.). Verify that Xcode MCP tools are accessible (e.g., ). If not available, tell the user to install and enable the Xcode MCP server before proceeding.
mcp_xcode_XcodeListWindowsb) iOS deployment target >= 12.0
The file is not accessible through the Xcode MCP server (it's project metadata, not a navigator file). Use in the terminal instead:
.pbxprojgrepbash
grep 'IPHONEOS_DEPLOYMENT_TARGET' <path/to/project.pbxproj>Check that all deployment target values are >= 12.0. If any are below 12.0, tell the user to update them.
c) Xcode version >= 16.0
Run in the terminal to verify. If below 16.0, tell the user to update Xcode.
xcodebuild -versiond) Ruby + gem
Needed by scripts/add_spm_dependency.rb in step 3. Check:
xcodeprojbash
ruby -e 'require "xcodeproj"; puts Xcodeproj::VERSION'If it fails, run and retry.
gem install xcodeproj在继续操作前主动验证每个前置条件。如果任何检查失败,告知用户并停止操作。
a) Xcode MCP服务器可用
这是硬性要求。此技能使用Xcode MCP服务器与Xcode项目交互(添加SPM依赖项、构建等)。验证Xcode MCP工具是否可访问(例如)。如果不可用,告知用户先安装并启用Xcode MCP服务器,然后再继续。
mcp_xcode_XcodeListWindowsb) iOS部署目标 >= 12.0
Xcode MCP服务器无法访问文件(它是项目元数据,而非导航器文件)。改用终端中的命令:
.pbxprojgrepbash
grep 'IPHONEOS_DEPLOYMENT_TARGET' <path/to/project.pbxproj>检查所有部署目标值是否 >= 12.0。如果有任何值低于12.0,告知用户进行更新。
c) Xcode版本 >= 16.0
在终端中运行进行验证。如果版本低于16.0,告知用户更新Xcode。
xcodebuild -versiond) Ruby + gem
步骤3中的scripts/add_spm_dependency.rb脚本需要此环境。检查:
xcodeprojbash
ruby -e 'require "xcodeproj"; puts Xcodeproj::VERSION'如果检查失败,运行并重试。
gem install xcodeproj2. Collect application identification keys
2. 收集应用标识密钥
If the user's message contains a block (see
Pre-filled values), extract and
from there and skip to step 3.
dynatrace-ios-setup-configDTXApplicationIDDTXBeaconURLOtherwise, ask the user for the two required values:
- DTXApplicationID — the application's unique identifier
- DTXBeaconURL — the beacon endpoint URL (e.g., )
https://{environment}.dynatrace.com/mbeacon
If the user already provided these values in their message, skip asking.
If the user doesn't have these values or doesn't know how to get them, refer them to the official setup documentation: https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/mobile-frontends/ios/id-01-initial-setup
否则,向用户询问两个必填值:
- DTXApplicationID —— 应用的唯一标识符
- DTXBeaconURL —— 数据上报端点URL(例如)
https://{environment}.dynatrace.com/mbeacon
如果用户已在消息中提供这些值,则跳过询问。
如果用户没有这些值或不知道如何获取,引导他们查看官方设置文档:https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/mobile-frontends/ios/id-01-initial-setup
3. Add OneAgent to the project (SPM dependency)
3. 向项目添加OneAgent(SPM依赖项)
Add the Dynatrace Swift Mobile SDK via Swift Package Manager.
If the user's message contains a block with a
value, use that directly. Otherwise, ask the user which product they
want:
dynatrace-ios-setup-configProduct- Dynatrace — OneAgent for automatic mobile app instrumentation
- DynatraceSessionReplay — OneAgent + Session Replay module (replay on crash)
SPM package URL:
https://github.com/Dynatrace/swift-mobile-sdk.gitRun the bundled Ruby script scripts/add_spm_dependency.rb. It uses the gem to add the package reference, product dependency, and frameworks build-file entry correctly — no string manipulation of .
xcodeproj.pbxprojbash
ruby ./scripts/add_spm_dependency.rb \
<ProjectPath> \
https://github.com/Dynatrace/swift-mobile-sdk.git \
8.0.0 \
<Product> \
[TargetName]- — e.g.
ProjectPath./MyApp.xcodeproj - —
<Product>orDynatrace(from step 3 choice)DynatraceSessionReplay - — optional; defaults to the first application target in the project
TargetName
The script is idempotent — running it twice is a no-op. Prints on success.
OK: project savedIf the script fails for any reason (unusual project layout, Ruby unavailable), fall back to guiding the user through Xcode manually:
- Open the project in Xcode
- File > Add Package Dependencies...
- Enter URL:
https://github.com/Dynatrace/swift-mobile-sdk.git - Up to Next Major Version from
8.0.0 - Add the chosen library to the app target
- Click Add Package
After the script succeeds (or the user confirms manual addition), proceed to step 4.
通过Swift Package Manager添加Dynatrace Swift Mobile SDK。
如果用户的消息中包含带有值的代码块,直接使用该值。否则,询问用户想要的产品类型:
Productdynatrace-ios-setup-config- Dynatrace —— 用于自动移动应用埋点的OneAgent
- DynatraceSessionReplay —— OneAgent + 会话重放模块(崩溃时重放会话)
SPM包URL:
https://github.com/Dynatrace/swift-mobile-sdk.git运行捆绑的Ruby脚本scripts/add_spm_dependency.rb。它使用 gem正确添加包引用、产品依赖项和框架构建文件条目——无需手动修改字符串。
xcodeproj.pbxprojbash
ruby ./scripts/add_spm_dependency.rb \
<ProjectPath> \
https://github.com/Dynatrace/swift-mobile-sdk.git \
8.0.0 \
<Product> \
[TargetName]- —— 例如
ProjectPath./MyApp.xcodeproj - ——
<Product>或Dynatrace(来自步骤3的选择)DynatraceSessionReplay - —— 可选;默认为项目中的第一个应用目标
TargetName
该脚本具有幂等性——运行两次不会产生额外操作。成功时会输出。
OK: project saved如果脚本因任何原因失败(特殊项目结构、Ruby不可用),则改为引导用户手动通过Xcode操作:
- 在Xcode中打开项目
- 文件 > 添加包依赖...
- 输入URL:
https://github.com/Dynatrace/swift-mobile-sdk.git - 选择之后的最新大版本
8.0.0 - 将所选库添加到应用目标
- 点击添加包
脚本成功运行(或用户确认手动添加完成)后,继续步骤4。
4. Create Dynatrace.plist configuration
4. 创建Dynatrace.plist配置文件
Use to create a new file in the app's main source directory. This ensures the file is automatically registered in the Xcode project.
mcp_xcode_XcodeWriteDynatrace.plistContent:
text
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DTXApplicationID</key>
<string>{USER_PROVIDED_APP_ID}</string>
<key>DTXBeaconURL</key>
<string>{USER_PROVIDED_BEACON_URL}</string>
<key>DTXUserOptIn</key>
{USER_OPT_IN_VALUE}
<key>DTXStartupLoadBalancing</key>
<true/>
<key>DTXStartupWithGrailEnabled</key>
<true/>
</dict>
</plist>Replace and with the actual values from step 2.
Replace with or based on the value from the config block. If no config block is provided, default to .
{USER_PROVIDED_APP_ID}{USER_PROVIDED_BEACON_URL}{USER_OPT_IN_VALUE}<true/><false/>DTXUserOptIn<true/>- — when
DTXUserOptIn, starts the agent with data collection OFF, requiring explicit opt-in via the privacy API (configured in step 5). Whentrue, data collection starts immediately without requiring opt-in, and step 5 is skipped.false - — enables load balancing across cluster nodes on startup.
DTXStartupLoadBalancing - — enables RUM on the latest Dynatrace on the first app start before the cluster configuration is received. Once the cluster config is cached, this flag is permanently overridden.
DTXStartupWithGrailEnabled
使用在应用的主源码目录中创建新的文件。这可确保文件自动注册到Xcode项目中。
mcp_xcode_XcodeWriteDynatrace.plist文件内容:
text
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DTXApplicationID</key>
<string>{USER_PROVIDED_APP_ID}</string>
<key>DTXBeaconURL</key>
<string>{USER_PROVIDED_BEACON_URL}</string>
<key>DTXUserOptIn</key>
{USER_OPT_IN_VALUE}
<key>DTXStartupLoadBalancing</key>
<true/>
<key>DTXStartupWithGrailEnabled</key>
<true/>
</dict>
</plist>将和替换为步骤2中获取的实际值。将替换为或,具体取决于配置块中的值。如果没有配置块,默认使用。
{USER_PROVIDED_APP_ID}{USER_PROVIDED_BEACON_URL}{USER_OPT_IN_VALUE}<true/><false/>DTXUserOptIn<true/>- —— 当为
DTXUserOptIn时,代理启动时数据收集处于关闭状态,需要通过隐私API明确授权(在步骤5中配置)。当为true时,数据收集立即启动,无需授权,且跳过步骤5。false - —— 启用启动时跨集群节点的负载均衡。
DTXStartupLoadBalancing - —— 在收到集群配置之前,首次启动应用时启用最新Dynatrace版本的RUM功能。一旦集群配置被缓存,此标志将被永久覆盖。
DTXStartupWithGrailEnabled
5. Add user opt-in privacy configuration
5. 添加用户隐私授权配置
Use to read the app's entry point file, then use to add the privacy configuration code with a TODO comment so the user knows to move it to the appropriate place (e.g., a privacy settings screen):
mcp_xcode_XcodeReadmcp_xcode_XcodeUpdateFor SwiftUI apps ( App struct file):
Add the following inside the struct's method (create one if it doesn't exist):
@mainAppinit()text
init() {
// TODO: Move this privacy configuration to your app's privacy settings screen.
// These settings are provided here for a quick start with capturing monitoring data.
// In production, this should be driven by user consent (e.g., a privacy settings screen).
let privacyConfig = Dynatrace.userPrivacyOptions()
privacyConfig.dataCollectionLevel = .userBehavior
privacyConfig.crashReportingOptedIn = true
Dynatrace.applyUserPrivacyOptions(privacyConfig) { (successful) in
// callback after privacy changed
}
}For UIKit apps (AppDelegate):
Add the same code inside .
application(_:didFinishLaunchingWithOptions:)使用读取应用的入口文件,然后使用添加隐私配置代码,并附带TODO注释,以便用户知道需要将其移至合适的位置(例如隐私设置界面):
mcp_xcode_XcodeReadmcp_xcode_XcodeUpdate对于SwiftUI应用(包含 App结构体的文件):
在结构体的方法中添加以下代码(如果不存在则创建该方法):
@mainAppinit()text
init() {
// TODO: 将此隐私配置移至应用的隐私设置界面。
// 此处提供的设置用于快速启动监控数据采集。
// 在生产环境中,应根据用户同意情况(例如隐私设置界面)进行控制。
let privacyConfig = Dynatrace.userPrivacyOptions()
privacyConfig.dataCollectionLevel = .userBehavior
privacyConfig.crashReportingOptedIn = true
Dynatrace.applyUserPrivacyOptions(privacyConfig) { (successful) in
// 隐私设置更改后的回调
}
}对于UIKit应用(AppDelegate):
在方法中添加相同代码。
application(_:didFinishLaunchingWithOptions:)6. Add the Dynatrace import
6. 添加Dynatrace导入语句
Use to add to the app's entry point file.
mcp_xcode_XcodeUpdateimport DynatraceFor SwiftUI apps: Add to the file containing the App struct.
@mainFor UIKit apps: Add to .
AppDelegate.swift使用在应用的入口文件中添加。
mcp_xcode_XcodeUpdateimport Dynatrace对于SwiftUI应用: 添加到包含 App结构体的文件中。
@main对于UIKit应用: 添加到中。
AppDelegate.swift7. Build and run
7. 构建并运行
Use the Xcode MCP server to build the project:
- Build the project using
mcp_xcode_BuildProject - If the build succeeds, report success to the user
- If the build fails, show the build errors and help the user resolve them
使用Xcode MCP服务器构建项目:
- 使用构建项目
mcp_xcode_BuildProject - 如果构建成功,向用户报告成功
- 如果构建失败,显示构建错误并帮助用户解决
8. Verify installation
8. 验证安装
Run the bundled verification script scripts/verify-setup.sh. It asserts build output, plist values, simulator launch, and agent startup — all serially with , hard-failing with distinct exit codes.
set -eInvocation:
bash
./scripts/verify-setup.sh <ProjectPath> <SchemeName> \
<ExpectedAppID> <ExpectedBeaconURL> [ExpectedOptIn]Arguments (discover from the Xcode project and the values used in step 2/4):
- — e.g.
ProjectPath./MyApp.xcodeproj - — run
SchemeNameto see available schemes, then pick the correct app scheme (not test or irrelevant schemes)xcodebuild -list -project <ProjectPath> - — the
ExpectedAppIDvalue written toDTXApplicationIDDynatrace.plist - — the
ExpectedBeaconURLvalue written toDTXBeaconURLDynatrace.plist - — optional;
ExpectedOptInortrue. Pass thefalsevalue used in step 4 to assert it. Omit to skip.DTXUserOptIn
Exit codes:
| Code | Meaning | Action |
|---|---|---|
| All checks passed; plist values correct; agent startup log seen | Report success |
| Build output missing framework, missing plist, or plist values don't match expected | SPM link / plist target membership / wrong values — stderr says which |
| Simulator boot / install / launch failed | Inspect stderr; re-run step 7 if app bundle is stale |
| | Verify |
| | Simulator state issue; retry after restarting the simulator |
The script prints headers so partial failures are debuggable from stdout.
=== Phase N: ... ===运行捆绑的验证脚本scripts/verify-setup.sh。它会依次检查构建输出、plist值、模拟器启动和代理启动——所有步骤通过强制执行,失败时返回不同的退出码。
set -e调用方式:
bash
./scripts/verify-setup.sh <ProjectPath> <SchemeName> \
<ExpectedAppID> <ExpectedBeaconURL> [ExpectedOptIn]参数(从Xcode项目和步骤2/4中使用的值获取):
- —— 例如
ProjectPath./MyApp.xcodeproj - —— 运行
SchemeName查看可用scheme,然后选择正确的应用scheme(不是测试或无关scheme)xcodebuild -list -project <ProjectPath> - —— 写入
ExpectedAppID的Dynatrace.plist值DTXApplicationID - —— 写入
ExpectedBeaconURL的Dynatrace.plist值DTXBeaconURL - —— 可选;
ExpectedOptIn或true。传入步骤4中使用的false值进行验证。省略则跳过此检查。DTXUserOptIn
退出码:
| 代码 | 含义 | 操作建议 |
|---|---|---|
| 所有检查通过;plist值正确;已检测到代理启动日志 | 报告成功 |
| 构建输出缺少框架、缺少plist或plist值与预期不符 | 检查SPM链接 / plist目标成员资格 / 值是否正确——stderr会提示具体问题 |
| 模拟器启动/安装/运行失败 | 查看stderr;如果应用包已过期,重新执行步骤7 |
| 启动后未找到 | 验证入口文件中是否添加了 |
| | 模拟器状态异常;重启模拟器后重试 |
脚本会输出标题,以便从stdout中调试部分失败的情况。
=== Phase N: ... ===Post-verification guidance
验证后指引
Leave the simulator running with the app open so the user can interact with it and generate events that will appear in their Dynatrace environment. Do NOT shut down the simulator.
After successful verification, inform the user:
- The simulator is running with the app — to verify data reaches their Dynatrace environment, they should:
- Interact with the app: tap buttons, navigate between screens to generate user actions and events
- Send the app to the background (press the Home button in the simulator) and bring it back to the foreground — this triggers an immediate session flush to the Dynatrace cluster
- Within a few minutes, the generated events will appear in their Dynatrace environment
- To view data: Experience Vitals > Overview > Mobile > select frontend
- Data can also be queried directly in Grail using DQL
- For advanced configuration options, see: https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/mobile-frontends/ios/id-03-configuration
保持模拟器运行并打开应用,以便用户与应用交互并生成将显示在其Dynatrace环境中的事件。不要关闭模拟器。
验证成功后,告知用户:
- 模拟器正在运行应用——要验证数据是否到达Dynatrace环境,他们需要:
- 与应用交互:点击按钮、在屏幕间导航以生成用户操作和事件
- 将应用切换到后台(在模拟器中按Home键),再切换回前台——这会触发会话立即上报到Dynatrace集群
- 几分钟内,生成的事件将显示在其Dynatrace环境中
- 查看数据:Experience Vitals > 概览 > 移动 > 选择前端
- 也可以使用DQL在Grail中直接查询数据
- 如需高级配置选项,请查看:https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/mobile-frontends/ios/id-03-configuration
Important notes
重要说明
- This skill covers SPM integration only. CocoaPods and manual framework integration are not supported.
- Do NOT add extra DTX configuration keys unless the user explicitly asks for them — the defaults are optimized for a good first experience.
- The public documentation for this setup is at: https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/mobile-frontends/ios/id-01-initial-setup
- 此技能仅支持SPM集成。不支持CocoaPods和手动框架集成。
- 除非用户明确要求,否则不要添加额外的DTX配置密钥——默认值已针对良好的首次使用体验进行优化。
- 此设置的公开文档地址:https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/mobile-frontends/ios/id-01-initial-setup