Performance Metrics
Learn how to attach performance metrics to your transactions.
Sentry's SDKs support sending performance metrics data to Sentry. These are numeric values attached to transactions that are aggregated and displayed in Sentry.
If configured, the Cocoa SDK automatically collects the following performance metrics:
In addition to automatic performance metrics, the SDK supports setting custom performance measurements on transactions. This allows you to define measurements that are important to your application and send them to Sentry.
To set a performance measurement, you need to supply the following:
- name (
string
) - value (any numeric type -
float
,integer
, etc.) - unit (
string
, defaults to the stringnone
if omitted)
Sentry supports adding arbitrary custom units, but we recommend using one of the supported units listed below.
Adding custom measurements is supported in Sentry's Cocoa SDK, version 7.28.0
and above.
import Sentry
let span = SentrySDK.span;
// Record amount of memory used
span?.setMeasurement(name: "memory_used", value: 64, unit: MeasurementUnitInformation.megabyte);
// Record time it took to load user profile
span?.setMeasurement(name: "user_profile_loading_time", value: 1.3, unit: MeasurementUnitDuration.second);
// Record number of times the screen was loaded
span?.setMeasurement(name: "screen_load_count", value: 4);
目前,单位转换仅在数据已经存储后才支持。这意味着,例如,('myMeasurement', 60, 'second')
和 ('myMeasurement', 3, 'minute')
不会被聚合, 而是作为两个单独的测量值存储。为了避免这种情况,在记录自定义测量时,请确保使用一致的单位。
Units augment metric values by giving meaning to what otherwise might be abstract numbers. Adding units also allows Sentry to offer controls - unit conversions, filters, and so on - based on those units. For values that are unitless, you can supply an empty string or 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
If you want to explore further, you can find details about supported units in our event ingestion documentation.