Performance Metrics

Sentry's SDKs support sending performance metrics data to Sentry. These are numeric values attached to transactions that are aggregated and displayed in Sentry.

Custom Metrics

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 (string)
  • value (any numeric type - float, integer, etc.)
  • unit (string, Defaults to the string none if omitted.)

Sentry supports adding arbitrary custom units, but we recommend using one of the supported units listed below.

Adding custom metrics is supported in Sentry's Python SDK version 1.5.12 and above.

To enable the capturing of custom metrics, you'll need to enable the custom_measurements experiment option.

Copied
sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    _experiments={
        "custom_measurements": True,
    },
)

To capture in the SDK:

Copied
transaction = Hub.current.scope.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);

Supported Performance Metric Units

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.

Duration Units

  • nanosecond
  • microsecond
  • millisecond
  • second
  • minute
  • hour
  • day
  • week

Information Units

  • bit
  • byte
  • kilobyte
  • kibibyte
  • megabyte
  • mebibyte
  • gigabyte
  • gibibyte
  • terabyte
  • tebibyte
  • petabyte
  • pebibyte
  • exabyte
  • exbibyte

Fraction Units

  • ratio
  • percent

If you want to explore further, you can find details about supported units in our event ingestion documentation.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").