dt-setup-flutter
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDynatrace Flutter Plugin Integration Skill
Dynatrace Flutter Plugin集成技能
Prerequisites
前置条件
- Flutter SDK installed and available on
flutterPATH - An existing Flutter project with a at the project root
pubspec.yaml - A Dynatrace environment with access to Experience Vitals (to obtain and
applicationId, or to downloadbeaconUrl)dynatrace.config.yaml - Console access to Experience Vitals → Mobile to configure app settings (Data Privacy, Enablement and Cost Control)
- CLI available (comes with Flutter SDK; used to run the plugin configuration script)
dart
Work through the steps below in order, interacting with the user at each decision point. Read actual project files before suggesting changes — do not assume the current state.
- 已安装Flutter SDK,且命令可在
flutter中访问PATH - 已有一个Flutter项目,项目根目录下存在文件
pubspec.yaml - 拥有可访问Experience Vitals的Dynatrace环境(用于获取和
applicationId,或下载beaconUrl)dynatrace.config.yaml - 具备Experience Vitals → Mobile的控制台访问权限,用于配置应用设置(数据隐私、功能启用与成本控制)
- 可使用命令行工具(随Flutter SDK一同安装;用于运行插件配置脚本)
dart
请按顺序完成以下步骤,在每个决策点与用户交互。在建议修改前,请先读取实际项目文件——不要假设当前状态。
Step 1 — Check for existing dynatrace.config.yaml
dynatrace.config.yaml步骤1 — 检查是否存在dynatrace.config.yaml
dynatrace.config.yamlBefore asking the user anything, check whether exists at the project root.
dynatrace.config.yaml- File exists: Read it, show the and
applicationId, and confirm they match the target environment. If correct, run thebeaconUrlcheck below and skip to Step 3.userOptIn - File does not exist: Proceed to Step 2.
userOptInInspect the file for (Android) and (iOS).
userOptInDTXUserOptIn- Present on both platforms: Trust the value as-is. If , flag Step 7a. If
true, skip Step 7a.false - Absent from either platform: Ask the user: "Do you have User Opt-In mode enabled or disabled?" (If unsure: Experience Vitals → Mobile → [Your App] → Settings → Data Privacy.) Add the missing value to the relevant platform(s), then flag Step 7a if the final value is .
true
在询问用户任何问题之前,先检查项目根目录下是否存在。
dynatrace.config.yaml- 文件已存在: 读取该文件,展示和
applicationId,并确认它们与目标环境匹配。如果正确,执行下方的beaconUrl检查,然后跳过步骤3。userOptIn - 文件不存在: 继续执行步骤2。
userOptIn检查文件中是否存在Android的和iOS的配置。
userOptInDTXUserOptIn- 两个平台均已配置: 保留现有值。如果值为,标记步骤7a;如果值为
true,跳过步骤7a。false - 任一平台未配置: 询问用户:"您是否启用了用户选择加入模式?"(若不确定:请前往Experience Vitals → Mobile → [您的应用] → 设置 → 数据隐私。)为相关平台添加缺失的值,若最终值为则标记步骤7a。
true
Step 2 — Obtain dynatrace.config.yaml
(only if Step 1 found no file)
dynatrace.config.yaml步骤2 — 获取dynatrace.config.yaml
(仅当步骤1未找到文件时执行)
dynatrace.config.yamlAsk the user which approach they prefer:
Option A — Download from console (recommended):
- Open their Dynatrace environment
- Navigate to: Experience Vitals → New Frontend → Mobile
- Enter app name and choose Flutter as the platform
- On the Select capability and settings screen, configure monitoring features (Crash reporting, user action monitoring, etc.). User action monitoring can be changed later via Experience Vitals → [App] → Settings → Enablement and Cost Control.
- Download and place it at the project root (same level as
dynatrace.config.yaml)pubspec.yaml
Once the file is in place, apply the check from Step 1 and flag Step 7a if needed.
userOptInOption B — Provide credentials manually:
Read for the full template and conditional blocks. Collect all required values from the user before creating any files, then apply the check and flag Step 7a if needed.
references/config-yaml.mduserOptIn询问用户偏好的方式:
选项A — 从控制台下载(推荐):
- 打开您的Dynatrace环境
- 导航至:Experience Vitals → New Frontend → Mobile
- 输入应用名称,选择Flutter作为平台
- 在选择功能与设置页面,配置监控功能(崩溃报告、用户行为监控等)。用户行为监控可后续通过Experience Vitals → [应用] → 设置 → 功能启用与成本控制修改。
- 下载并放置在项目根目录(与
dynatrace.config.yaml同级)pubspec.yaml
文件就位后,执行步骤1中的检查,必要时标记步骤7a。
userOptIn选项B — 手动提供凭证:
阅读获取完整模板和条件块。在创建任何文件前,先向用户收集所有必填值,然后执行检查,必要时标记步骤7a。
references/config-yaml.mduserOptInStep 3 — Add the dependency
步骤3 — 添加依赖
Read first.
pubspec.yaml- Not present: Run:
bash
flutter pub add dynatrace_flutter_plugin - Already under : No change — proceed to Step 4.
dependencies - Under : Remove it from
dev_dependencies, then rundev_dependencies. The plugin is required at runtime, including in release builds.flutter pub add dynatrace_flutter_plugin
先读取文件。
pubspec.yaml- 依赖未存在: 执行命令:
bash
flutter pub add dynatrace_flutter_plugin - 已在下: 无需修改——继续执行步骤4。
dependencies - 在下: 将其从
dev_dependencies中移除,然后执行dev_dependencies。该插件为运行时所需,包括发布版本构建。flutter pub add dynatrace_flutter_plugin
Step 4 — Fetch dependencies
步骤4 — 获取依赖
If Step 3 ran , dependencies are already fetched — skip this step.
flutter pub addOtherwise run:
bash
flutter pub getConfirm success before continuing.
如果步骤3执行了,则依赖已自动获取——跳过此步骤。
flutter pub add否则执行:
bash
flutter pub get确认执行成功后再继续。
Step 5 — Run the Dynatrace configuration script
步骤5 — 运行Dynatrace配置脚本
bash
dart run dynatrace_flutter_pluginThis reads and automatically configures Android Gradle and . No manual native file edits are needed.
dynatrace.config.yamlios/Runner/Info.plistCommon mistakes to flag and correct:
- — wrong, use
flutter pub run dynatrace_flutter_plugindart run dynatrace_flutter_plugin - Manual edits to /
build.gradleorbuild.gradle.kts— not neededInfo.plist
bash
dart run dynatrace_flutter_plugin该脚本会读取并自动配置Android Gradle和。无需手动编辑原生文件。
dynatrace.config.yamlios/Runner/Info.plist需标记并纠正的常见错误:
- 错误命令:— 正确命令为
flutter pub run dynatrace_flutter_plugindart run dynatrace_flutter_plugin - 手动编辑/
build.gradle或build.gradle.kts— 无需操作Info.plist
Step 6 — Bootstrap the SDK in main.dart
main.dart步骤6 — 在main.dart
中初始化SDK
main.dartRead . Replace with :
lib/main.dartrunApp(...)Dynatrace().start(...)dart
import 'package:dynatrace_flutter_plugin/dynatrace_flutter_plugin.dart';
import 'package:flutter/material.dart';
void main() {
Dynatrace().start(const MyApp());
}- calls
Dynatrace().start()internally — remove any separaterunAppcallrunApp - is not required by Dynatrace before
WidgetsFlutterBinding.ensureInitialized(), but keep it if your app needs it for other pre-start initialization (for example, plugin or platform setup)start() - Do not
awaititself; only useDynatrace().start()for other app initialization that must complete before callingawaitstart()
读取文件。将替换为:
lib/main.dartrunApp(...)Dynatrace().start(...)dart
import 'package:dynatrace_flutter_plugin/dynatrace_flutter_plugin.dart';
import 'package:flutter/material.dart';
void main() {
Dynatrace().start(const MyApp());
}- 内部会调用
Dynatrace().start()— 移除单独的runApp调用runApp - Dynatrace不要求在前调用
start(),但如果您的应用因其他初始化需求(如插件或平台设置)需要该调用,请保留WidgetsFlutterBinding.ensureInitialized() - 不要
await本身;仅对必须在调用Dynatrace().start()前完成的其他应用初始化操作使用start()await
Step 7 — Add navigation tracking
步骤7 — 添加导航跟踪
In the root or , add to :
MaterialAppCupertinoAppDynatraceNavigationObserver()navigatorObserversdart
MaterialApp(
navigatorObservers: [DynatraceNavigationObserver()],
...
)dart
CupertinoApp(
navigatorObservers: [DynatraceNavigationObserver()],
...
)在根或中,将添加到:
MaterialAppCupertinoAppDynatraceNavigationObserver()navigatorObserversdart
MaterialApp(
navigatorObservers: [DynatraceNavigationObserver()],
...
)dart
CupertinoApp(
navigatorObservers: [DynatraceNavigationObserver()],
...
)Step 7a — Privacy options call (only if userOptIn: true
)
userOptIn: true步骤7a — 隐私选项调用(仅当userOptIn: true
时执行)
userOptIn: trueSkip this step if was not set to during Steps 1 or 2.
userOptIntrueRead for the full guidance on , , and placement options. Ask the user the questions defined there, then apply the call to the relevant file.
references/user-opt-in.mdDataCollectionLevelcrashReportingOptedIn如果步骤1或步骤2中未设置为,请跳过此步骤。
userOptIntrue阅读获取关于、和代码放置位置的完整指南。询问用户该文档中定义的问题,然后在相关文件中添加调用代码。
references/user-opt-in.mdDataCollectionLevelcrashReportingOptedInStep 8 — HTTP instrumentation (if applicable)
步骤8 — HTTP埋点(如适用)
Check for the package dependency. Separately, search the codebase for and usages. If either is present, apply instrumentation:
pubspec.yamlhttpimport 'dart:io'HttpClient| Package | Instrumentation |
|---|---|
| |
| Manual timing via |
createHttpClient()client:http.Client()Dynatrace().createHttpClient()If none are present, note it for when network calls are added.
检查中是否存在包依赖。另外,搜索代码库中是否有和的使用。如果存在其中任一情况,执行埋点操作:
pubspec.yamlhttpimport 'dart:io'HttpClient| 包 | 埋点方式 |
|---|---|
| 使用 |
| 通过 |
createHttpClient()client:http.Client()Dynatrace().createHttpClient()如果均不存在,请记录下来,以便后续添加网络调用时使用。
Step 9 — Post-setup summary
步骤9 — 安装后总结
Confirm to the user what is active:
Enabled by default (when is or absent):
userOptInfalse- ✅ Crash reporting
- ✅ User action tracking
- ✅ Network monitoring
- ✅ Lifecycle monitoring
- ✅ Auto-start
When, all data collection — including crash reporting — is gated on theuserOptIn: truecall.applyUserPrivacyOptions(...)
Configured during this setup:
- Privacy mode: [userOptIn: true — consent call added / opt-out (SDK default)]
- Navigation tracking: [DynatraceNavigationObserver added]
- HTTP instrumentation: [applied / not applicable yet]
向用户确认已启用的功能:
默认启用(当为或未配置时):
userOptInfalse- ✅ 崩溃报告
- ✅ 用户行为跟踪
- ✅ 网络监控
- ✅ 生命周期监控
- ✅ 自动启动
当时,所有数据收集(包括崩溃报告)均受userOptIn: true调用控制。applyUserPrivacyOptions(...)
本次安装已配置:
- 隐私模式:[userOptIn: true — 已添加授权调用 / 选择退出(SDK默认值)]
- 导航跟踪:[已添加DynatraceNavigationObserver]
- HTTP埋点:[已配置 / 暂不适用]
Step 10 — Verification
步骤10 — 验证
Read and show the user the verification checklist. If no data appears after 5 minutes, work through the troubleshooting steps in that file.
references/verification.md阅读并向用户展示验证清单。如果5分钟后仍无数据显示,请按照该文档中的故障排除步骤操作。
references/verification.mdReference Files
参考文件
- — Full
references/config-yaml.mdtemplate with Grail and userOptIn conditional blocksdynatrace.config.yaml - —
references/user-opt-in.mdguidance,applyUserPrivacyOptionsoptions, placement optionsDataCollectionLevel - — Post-setup verification checklist and troubleshooting
references/verification.md
- — 完整的
references/config-yaml.md模板,包含Grail和userOptIn条件块dynatrace.config.yaml - —
references/user-opt-in.md指南、applyUserPrivacyOptions选项、代码放置位置选项DataCollectionLevel - — 安装后验证清单及故障排除
references/verification.md
External References
外部参考
- dynatrace_flutter_plugin on pub.dev — package changelog, API docs, and latest version
- Dynatrace Flutter Installation Docs — initial setup docs
- dynatrace_flutter_plugin on pub.dev — 包更新日志、API文档及最新版本
- Dynatrace Flutter安装文档 — 初始安装文档