|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -require "sentry/metrics/metric" |
4 | | -require "sentry/metrics/counter_metric" |
5 | | -require "sentry/metrics/distribution_metric" |
6 | | -require "sentry/metrics/gauge_metric" |
7 | | -require "sentry/metrics/set_metric" |
8 | | -require "sentry/metrics/timing" |
9 | | -require "sentry/metrics/aggregator" |
10 | | - |
11 | 3 | module Sentry |
12 | 4 | module Metrics |
13 | | - DURATION_UNITS = %w[nanosecond microsecond millisecond second minute hour day week] |
14 | | - INFORMATION_UNITS = %w[bit byte kilobyte kibibyte megabyte mebibyte gigabyte gibibyte terabyte tebibyte petabyte pebibyte exabyte exbibyte] |
15 | | - FRACTIONAL_UNITS = %w[ratio percent] |
16 | | - |
17 | | - OP_NAME = "metric.timing" |
18 | | - SPAN_ORIGIN = "auto.metric.timing" |
19 | | - |
20 | 5 | class << self |
21 | | - def increment(key, value = 1.0, unit: "none", tags: {}, timestamp: nil) |
22 | | - Sentry.metrics_aggregator&.add(:c, key, value, unit: unit, tags: tags, timestamp: timestamp) |
23 | | - end |
24 | | - |
25 | | - def distribution(key, value, unit: "none", tags: {}, timestamp: nil) |
26 | | - Sentry.metrics_aggregator&.add(:d, key, value, unit: unit, tags: tags, timestamp: timestamp) |
27 | | - end |
28 | | - |
29 | | - def set(key, value, unit: "none", tags: {}, timestamp: nil) |
30 | | - Sentry.metrics_aggregator&.add(:s, key, value, unit: unit, tags: tags, timestamp: timestamp) |
31 | | - end |
32 | | - |
33 | | - def gauge(key, value, unit: "none", tags: {}, timestamp: nil) |
34 | | - Sentry.metrics_aggregator&.add(:g, key, value, unit: unit, tags: tags, timestamp: timestamp) |
35 | | - end |
36 | | - |
37 | | - def timing(key, unit: "second", tags: {}, timestamp: nil, &block) |
38 | | - return unless block_given? |
39 | | - return yield unless DURATION_UNITS.include?(unit) |
| 6 | + def method_missing(m, *args, &block) |
| 7 | + return unless Sentry.initialized? |
40 | 8 |
|
41 | | - result, value = Sentry.with_child_span(op: OP_NAME, description: key, origin: SPAN_ORIGIN) do |span| |
42 | | - tags.each { |k, v| span.set_tag(k, v.is_a?(Array) ? v.join(", ") : v.to_s) } if span |
43 | | - |
44 | | - start = Timing.send(unit.to_sym) |
45 | | - result = yield |
46 | | - value = Timing.send(unit.to_sym) - start |
47 | | - |
48 | | - [result, value] |
| 9 | + Sentry.logger.warn(LOGGER_PROGNAME) do |
| 10 | + "`Sentry::Metrics` is now deprecated and will be removed in the next major." |
49 | 11 | end |
50 | | - |
51 | | - Sentry.metrics_aggregator&.add(:d, key, value, unit: unit, tags: tags, timestamp: timestamp) |
52 | | - result |
53 | 12 | end |
54 | 13 | end |
55 | 14 | end |
|
0 commit comments