SuperAPI AI 工具集

sentry-span-streaming-dart

通用与其它

查看项目

更新于 10-16 08:47

技能介绍

用途:把 Dart/Flutter 项目从默认基于 transaction 的追踪生命周期(SentryTraceLifecycle.static)迁移到 span streaming(SentryTraceLifecycle.stream),span 在完成时单独发送,而非在结束时批量打包成 transaction。

主要能力:只需在 init 中设置 options.traceLifecycle = SentryTraceLifecycle.stream(前提为 sentry/sentry_flutter >= 9.19.0 且已启用 tracing)。自动埋点(帧、应用启动、TTID/TTFD、导航、交互、HTTP、数据库、GraphQL)会自动切换,无需改代码。

迁移要点:Sentry.startTransaction 改为 Sentry.startSpan / startSpanSync / startInactiveSpan;startChild 改为嵌套 startSpan(通过 zone 自动建立父子关系);setData/setTag 改为 setAttribute 配合 SentryAttribute.string/int/bool/double;beforeSendTransaction 在流模式下不执行,逻辑迁到 beforeSendSpan(仅可修改,不能丢弃)或 ignoreSpans(按名称匹配)。同一时间只能用一种追踪系统:流模式下事务 API 变为空操作并告警,静态模式下新 span API 变为空操作。

验证:运行 dart analyze 或 flutter analyze;开启 options.debug = true,span 信封内容类型为 application/vnd.sentry.items.span.v2+json;若日志出现 startTransaction is not supported,说明仍有旧事务 API 未迁移。

限制:ignoreSpans 暂不支持按属性匹配;tracesSampleRate/tracesSampler 仅对根 span 采样,子 span 继承决策;未采样时回调仍执行但 span 为空操作;startInactiveSpan 需手动调用 end(),其他 span 不会自动成为其子级。定价、平台等资料暂未提供。