Sentry's SDKs support sending performance metrics data to Sentry. These are numeric values attached to transactions that are aggregated and displayed in Sentry.
In addition to automatic performance metrics, the SDK supports setting custom performance metrics on transactions. This allows you to define metrics that are important to your application and send them to Sentry.
To set a performance metric, you need to supply the following:
- name (
- value (any numeric type -
- unit (
string, Defaults to the string
Sentry supports adding arbitrary custom units, but we recommend using one of the supported units listed below.
Adding custom metrics is supported in
5.8.0 and above.
transaction = Sentry.get_current_scope.get_transaction # Record amount of memory used transaction.set_measurement('memory_used', 123, 'byte') # Record time when job was started transaction.set_measurement('job_start_time', 1.3, 'second') # Record amount of times cache was read transaction.set_measurement('cache_read_count', 4)
Currently, unit conversion is only supported once the data has already been stored. This means that, for example,
('myMetric', 60, 'second') and
('myMetric', 3, 'minute') would not be aggregated, but rather stored as two separate metrics. To avoid this, make sure to use a consistent unit when recording a custom metric.
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
If you want to explore further, you can find details about supported units in our event ingestion documentation.