dt-obs-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 - 拥有Dynatrace环境,且可访问Experience Vitals(用于获取和
applicationId,或下载beaconUrl)dynatrace.config.yaml - 可通过控制台访问Experience Vitals → Mobile来配置应用设置(数据隐私、功能启用与成本控制)
- 可使用CLI(随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 → 新前端 → 移动
- 输入应用名称,并选择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 instrumentation(如适用)
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.
检查中是否存在包依赖。另外,搜索代码库中是否有和的使用。如果存在其中任意一项,进行instrumentation:
pubspec.yamlhttpimport 'dart:io'HttpClient| 包 | Instrumentation方式 |
|---|---|
| 使用 |
| 通过 |
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 instrumentation:[已配置 / 暂不适用]
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
- pub.dev上的dynatrace_flutter_plugin — 包更新日志、API文档及最新版本
- Dynatrace Flutter安装文档 — 初始设置文档