1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
# frozen_string_literal: true
require "sentry/metric_event"
module Sentry
module Metrics
class << self
# Increments a counter metric
# @param name [String] the metric name
# @param value [Numeric] the value to increment by (default: 1)
# @param attributes [Hash, nil] additional attributes for the metric (optional)
# @return [void]
def count(name, value: 1, attributes: nil)
return unless Sentry.initialized?
Sentry.get_current_hub.capture_metric(
name: name,
type: :counter,
value: value,
attributes: attributes
)
end
# Records a gauge metric
# @param name [String] the metric name
# @param value [Numeric] the gauge value
# @param unit [String, nil] the metric unit (optional)
# @param attributes [Hash, nil] additional attributes for the metric (optional)
# @return [void]
def gauge(name, value, unit: nil, attributes: nil)
return unless Sentry.initialized?
Sentry.get_current_hub.capture_metric(
name: name,
type: :gauge,
value: value,
unit: unit,
attributes: attributes
)
end
# Records a distribution metric
# @param name [String] the metric name
# @param value [Numeric] the distribution value
# @param unit [String, nil] the metric unit (optional)
# @param attributes [Hash, nil] additional attributes for the metric (optional)
# @return [void]
def distribution(name, value, unit: nil, attributes: nil)
return unless Sentry.initialized?
Sentry.get_current_hub.capture_metric(
name: name,
type: :distribution,
value: value,
unit: unit,
attributes: attributes
)
end
end
end
end
|