性能指标
了解如何将性能指标附加到事务中。
Sentry 的 SDK 支持将性能指标数据发送到 Sentry。这些是附加到事务的数值,会被聚合并在 Sentry 中显示。
If configured, the React Native SDK automatically collects the following performance metrics:
除了自动性能指标外,SDK 还支持在事务上设置 自定义性能测量值。这允许您定义对应用程序重要的测量值,并将其发送到 Sentry。
要设置性能测量值,您需要提供以下内容:
- 名称 (
string
) - 值 (任何数值类型 -
float
、integer
等) - 单位 (
string
,如果省略,默认为字符串none
)
Sentry 支持添加任意自定义单位,但我们建议使用以下 支持的单位之一。
Adding custom measurements is supported in Sentry's React Native SDK version 4.0.0
and above.
Copied
import * as Sentry from "@sentry/react-native";
const transaction = Sentry.getCurrentScope().getTransaction();
// Record amount of memory used
transaction.setMeasurement("memoryUsed", 123, "byte");
// Record time when Footer component renders on page
transaction.setMeasurement("ui.footerComponent.render", 1.3, "second");
// Record amount of times localStorage was read
transaction.setMeasurement("localStorageRead", 4);
目前,单位转换仅在数据已经存储后才支持。这意味着,例如,('myMeasurement', 60, 'second')
和 ('myMeasurement', 3, 'minute')
不会被聚合, 而是作为两个单独的测量值存储。为了避免这种情况,在记录自定义测量时,请确保使用一致的单位。
单位通过赋予抽象数字意义来增强测量值。添加单位还允许 Sentry 提供基于这些单位的控件,如单位转换、过滤等。对于无单位的值,您可以提供一个空字符串或 none
。
纳秒
(nanosecond
)微秒
(microsecond
)毫秒
(millisecond
)秒
(second
)分钟
(minute
)小时
(hour
)天
(day
)周
(week
)
位
(bit
)字节
(byte
)千字节
(kilobyte
)基字节
(kibibyte
)兆字节
(megabyte
)基兆字节
(mebibyte
)吉字节
(gigabyte
)基吉字节
(gibibyte
)太字节
(terabyte
)基太字节
(tebibyte
)拍字节
(petabyte
)基拍字节
(pebibyte
)艾字节
(exabyte
)基艾字节
(exbibyte
)
比率
(ratio
)百分比
(percent
)
如果您想进一步了解,可以在我们的 事件摄取文档 中找到有关支持单位的详细信息。