Skip to content

Commit 49ece04

Browse files
committed
Deprecate config.metrics and Sentry::Metrics
1 parent b5a4948 commit 49ece04

31 files changed

+73
-1535
lines changed

CHANGELOG.md

+22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@
66
- Revert "[rails] support string errors in error reporter (#2464)" ([#2533](https://github.com/getsentry/sentry-ruby/pull/2533))
77
- Removed unnecessary warning about missing `stackprof` when Vernier is configured as the profiler ([#2537](https://github.com/getsentry/sentry-ruby/pull/2537))
88

9+
### Miscellaneous
10+
11+
- Deprecate all Metrics related APIs [#2539](https://github.com/getsentry/sentry-ruby/pull/2539)
12+
13+
Sentry [no longer has the Metrics Beta offering](https://sentry.zendesk.com/hc/en-us/articles/26369339769883-Metrics-Beta-Ended-on-October-7th) so
14+
all the following APIs linked to Metrics have been deprecated and will be removed in the next major.
15+
16+
```ruby
17+
Sentry.init do |config|
18+
# ...
19+
config.metrics.enabled = true
20+
config.metrics.enable_code_locations = true
21+
config.metrics.before_emit = lambda {}
22+
end
23+
24+
Sentry::Metrics.increment('button_click')
25+
Sentry::Metrics.distribution('page_load', 15.0, unit: 'millisecond')
26+
Sentry::Metrics.gauge('page_load', 15.0, unit: 'millisecond')
27+
Sentry::Metrics.set('user_view', 'jane')
28+
Sentry::Metrics.timing('how_long') { sleep(1) }
29+
```
30+
931
## 5.22.3
1032

1133
### Bug Fixes

sentry-ruby/lib/sentry-ruby.rb

+3-8
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ def exception_locals_tp
8383
attr_reader :backpressure_monitor
8484

8585
# @!attribute [r] metrics_aggregator
86-
# @return [Metrics::Aggregator, nil]
86+
# @deprecated
87+
# @return [nil]
8788
attr_reader :metrics_aggregator
8889

8990
##### Patch Registration #####
@@ -241,7 +242,7 @@ def init(&block)
241242
@background_worker = Sentry::BackgroundWorker.new(config)
242243
@session_flusher = config.session_tracking? ? Sentry::SessionFlusher.new(config, client) : nil
243244
@backpressure_monitor = config.enable_backpressure_handling ? Sentry::BackpressureMonitor.new(config, client) : nil
244-
@metrics_aggregator = config.metrics.enabled ? Sentry::Metrics::Aggregator.new(config, client) : nil
245+
@metrics_aggregator = nil
245246
exception_locals_tp.enable if config.include_local_variables
246247
at_exit { close }
247248
end
@@ -262,12 +263,6 @@ def close
262263
@backpressure_monitor = nil
263264
end
264265

265-
if @metrics_aggregator
266-
@metrics_aggregator.flush(force: true)
267-
@metrics_aggregator.kill
268-
@metrics_aggregator = nil
269-
end
270-
271266
if client = get_current_client
272267
client.flush
273268

sentry-ruby/lib/sentry/configuration.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def capture_exception_frame_locals=(value)
245245
attr_reader :cron
246246

247247
# Metrics related configuration.
248+
# @deprecated It will be removed in the next major release.
248249
# @return [Metrics::Configuration]
249250
attr_reader :metrics
250251

@@ -450,7 +451,7 @@ def initialize
450451

451452
@transport = Transport::Configuration.new
452453
@cron = Cron::Configuration.new
453-
@metrics = Metrics::Configuration.new
454+
@metrics = Metrics::Configuration.new(self.logger)
454455
@gem_specs = Hash[Gem::Specification.map { |spec| [spec.name, spec.version.to_s] }] if Gem::Specification.respond_to?(:map)
455456

456457
run_post_initialization_callbacks

sentry-ruby/lib/sentry/cron/monitor_check_ins.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ def perform(*args, **opts)
1414
:in_progress,
1515
monitor_config: monitor_config)
1616

17-
start = Metrics::Timing.duration_start
17+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
1818

1919
begin
2020
# need to do this on ruby <= 2.6 sadly
2121
ret = method(:perform).super_method.arity == 0 ? super() : super
22-
duration = Metrics::Timing.duration_end(start)
22+
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
2323

2424
Sentry.capture_check_in(slug,
2525
:ok,
@@ -29,7 +29,7 @@ def perform(*args, **opts)
2929

3030
ret
3131
rescue Exception
32-
duration = Metrics::Timing.duration_end(start)
32+
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
3333

3434
Sentry.capture_check_in(slug,
3535
:error,

sentry-ruby/lib/sentry/interfaces/stacktrace_builder.rb

-8
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,6 @@ def build(backtrace:, &frame_callback)
7575
StacktraceInterface.new(frames: frames)
7676
end
7777

78-
# Get the code location hash for a single line for where metrics where added.
79-
# @return [Hash]
80-
def metrics_code_location(unparsed_line)
81-
parsed_line = Backtrace::Line.parse(unparsed_line)
82-
frame = convert_parsed_line_into_frame(parsed_line)
83-
frame.to_hash.reject { |k, _| %i[project_root in_app].include?(k) }
84-
end
85-
8678
private
8779

8880
def convert_parsed_line_into_frame(line)

sentry-ruby/lib/sentry/metrics.rb

+4-45
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,14 @@
11
# frozen_string_literal: true
22

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-
113
module Sentry
124
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-
205
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?
408

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."
4911
end
50-
51-
Sentry.metrics_aggregator&.add(:d, key, value, unit: unit, tags: tags, timestamp: timestamp)
52-
result
5312
end
5413
end
5514
end

0 commit comments

Comments
 (0)