Module: Sentry::Metrics

Defined in:
lib/sentry/metrics.rb,
lib/sentry/metrics/metric.rb,
lib/sentry/metrics/timing.rb,
lib/sentry/metrics/aggregator.rb,
lib/sentry/metrics/set_metric.rb,
lib/sentry/metrics/gauge_metric.rb,
lib/sentry/metrics/configuration.rb,
lib/sentry/metrics/counter_metric.rb,
lib/sentry/metrics/local_aggregator.rb,
lib/sentry/metrics/distribution_metric.rb

Defined Under Namespace

Modules: Timing Classes: Aggregator, Configuration, CounterMetric, DistributionMetric, GaugeMetric, LocalAggregator, Metric, SetMetric

Constant Summary collapse

DURATION_UNITS =
%w[nanosecond microsecond millisecond second minute hour day week]
INFORMATION_UNITS =
%w[bit byte kilobyte kibibyte megabyte mebibyte gigabyte gibibyte terabyte tebibyte petabyte pebibyte exabyte exbibyte]
FRACTIONAL_UNITS =
%w[ratio percent]
OP_NAME =
"metric.timing"
SPAN_ORIGIN =
"auto.metric.timing"

Class Method Summary collapse

Class Method Details

.distribution(key, value, unit: "none", tags: {}, timestamp: nil) ⇒ Object



26
27
28
29
# File 'lib/sentry/metrics.rb', line 26

def distribution(key, value, unit: "none", tags: {}, timestamp: nil)
  log_deprecation
  Sentry.metrics_aggregator&.add(:d, key, value, unit: unit, tags: tags, timestamp: timestamp)
end

.gauge(key, value, unit: "none", tags: {}, timestamp: nil) ⇒ Object



36
37
38
39
# File 'lib/sentry/metrics.rb', line 36

def gauge(key, value, unit: "none", tags: {}, timestamp: nil)
  log_deprecation
  Sentry.metrics_aggregator&.add(:g, key, value, unit: unit, tags: tags, timestamp: timestamp)
end

.increment(key, value = 1.0, unit: "none", tags: {}, timestamp: nil) ⇒ Object



21
22
23
24
# File 'lib/sentry/metrics.rb', line 21

def increment(key, value = 1.0, unit: "none", tags: {}, timestamp: nil)
  log_deprecation
  Sentry.metrics_aggregator&.add(:c, key, value, unit: unit, tags: tags, timestamp: timestamp)
end

.log_deprecationObject



61
62
63
64
65
# File 'lib/sentry/metrics.rb', line 61

def log_deprecation
  Sentry.sdk_logger.warn(LOGGER_PROGNAME) do
    "`Sentry::Metrics` is now deprecated and will be removed in the next major."
  end
end

.set(key, value, unit: "none", tags: {}, timestamp: nil) ⇒ Object



31
32
33
34
# File 'lib/sentry/metrics.rb', line 31

def set(key, value, unit: "none", tags: {}, timestamp: nil)
  log_deprecation
  Sentry.metrics_aggregator&.add(:s, key, value, unit: unit, tags: tags, timestamp: timestamp)
end

.timing(key, unit: "second", tags: {}, timestamp: nil, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sentry/metrics.rb', line 41

def timing(key, unit: "second", tags: {}, timestamp: nil, &block)
  log_deprecation

  return unless block_given?
  return yield unless DURATION_UNITS.include?(unit)

  result, value = Sentry.with_child_span(op: OP_NAME, description: key, origin: SPAN_ORIGIN) do |span|
    tags.each { |k, v| span.set_tag(k, v.is_a?(Array) ? v.join(", ") : v.to_s) } if span

    start = Timing.send(unit.to_sym)
    result = yield
    value = Timing.send(unit.to_sym) - start

    [result, value]
  end

  Sentry.metrics_aggregator&.add(:d, key, value, unit: unit, tags: tags, timestamp: timestamp)
  result
end