Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate config.metrics and Sentry::Metrics #2539

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@
- Revert "[rails] support string errors in error reporter (#2464)" ([#2533](https://github.com/getsentry/sentry-ruby/pull/2533))
- Removed unnecessary warning about missing `stackprof` when Vernier is configured as the profiler ([#2537](https://github.com/getsentry/sentry-ruby/pull/2537))

### Miscellaneous

- Deprecate all Metrics related APIs [#2539](https://github.com/getsentry/sentry-ruby/pull/2539)

Sentry [no longer has the Metrics Beta offering](https://sentry.zendesk.com/hc/en-us/articles/26369339769883-Metrics-Beta-Ended-on-October-7th) so
all the following APIs linked to Metrics have been deprecated and will be removed in the next major.

```ruby
Sentry.init do |config|
# ...
config.metrics.enabled = true
config.metrics.enable_code_locations = true
config.metrics.before_emit = lambda {}
end

Sentry::Metrics.increment('button_click')
Sentry::Metrics.distribution('page_load', 15.0, unit: 'millisecond')
Sentry::Metrics.gauge('page_load', 15.0, unit: 'millisecond')
Sentry::Metrics.set('user_view', 'jane')
Sentry::Metrics.timing('how_long') { sleep(1) }
```

## 5.22.3

### Bug Fixes
Expand Down
11 changes: 3 additions & 8 deletions sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def exception_locals_tp
attr_reader :backpressure_monitor

# @!attribute [r] metrics_aggregator
# @return [Metrics::Aggregator, nil]
# @deprecated
# @return [nil]
attr_reader :metrics_aggregator

##### Patch Registration #####
Expand Down Expand Up @@ -241,7 +242,7 @@ def init(&block)
@background_worker = Sentry::BackgroundWorker.new(config)
@session_flusher = config.session_tracking? ? Sentry::SessionFlusher.new(config, client) : nil
@backpressure_monitor = config.enable_backpressure_handling ? Sentry::BackpressureMonitor.new(config, client) : nil
@metrics_aggregator = config.metrics.enabled ? Sentry::Metrics::Aggregator.new(config, client) : nil
@metrics_aggregator = nil
exception_locals_tp.enable if config.include_local_variables
at_exit { close }
end
Expand All @@ -262,12 +263,6 @@ def close
@backpressure_monitor = nil
end

if @metrics_aggregator
@metrics_aggregator.flush(force: true)
@metrics_aggregator.kill
@metrics_aggregator = nil
end

if client = get_current_client
client.flush

Expand Down
3 changes: 2 additions & 1 deletion sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def capture_exception_frame_locals=(value)
attr_reader :cron

# Metrics related configuration.
# @deprecated It will be removed in the next major release.
# @return [Metrics::Configuration]
attr_reader :metrics

Expand Down Expand Up @@ -450,7 +451,7 @@ def initialize

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

run_post_initialization_callbacks
Expand Down
6 changes: 3 additions & 3 deletions sentry-ruby/lib/sentry/cron/monitor_check_ins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
:in_progress,
monitor_config: monitor_config)

start = Metrics::Timing.duration_start
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)

Check warning on line 17 in sentry-ruby/lib/sentry/cron/monitor_check_ins.rb

View check run for this annotation

Codecov / codecov/patch

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

Added line #L17 was not covered by tests

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

Check warning on line 22 in sentry-ruby/lib/sentry/cron/monitor_check_ins.rb

View check run for this annotation

Codecov / codecov/patch

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

Added line #L22 was not covered by tests

Sentry.capture_check_in(slug,
:ok,
Expand All @@ -29,7 +29,7 @@

ret
rescue Exception
duration = Metrics::Timing.duration_end(start)
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start

Check warning on line 32 in sentry-ruby/lib/sentry/cron/monitor_check_ins.rb

View check run for this annotation

Codecov / codecov/patch

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

Added line #L32 was not covered by tests

Sentry.capture_check_in(slug,
:error,
Expand Down
1 change: 0 additions & 1 deletion sentry-ruby/lib/sentry/envelope/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def self.data_category(type)
when "session", "attachment", "transaction", "profile", "span" then type
when "sessions" then "session"
when "check_in" then "monitor"
when "statsd", "metric_meta" then "metric_bucket"
when "event" then "error"
when "client_report" then "internal"
else "default"
Expand Down
8 changes: 0 additions & 8 deletions sentry-ruby/lib/sentry/interfaces/stacktrace_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ def build(backtrace:, &frame_callback)
StacktraceInterface.new(frames: frames)
end

# Get the code location hash for a single line for where metrics where added.
# @return [Hash]
def metrics_code_location(unparsed_line)
parsed_line = Backtrace::Line.parse(unparsed_line)
frame = convert_parsed_line_into_frame(parsed_line)
frame.to_hash.reject { |k, _| %i[project_root in_app].include?(k) }
end

private

def convert_parsed_line_into_frame(line)
Expand Down
49 changes: 4 additions & 45 deletions sentry-ruby/lib/sentry/metrics.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,14 @@
# frozen_string_literal: true

require "sentry/metrics/metric"
require "sentry/metrics/counter_metric"
require "sentry/metrics/distribution_metric"
require "sentry/metrics/gauge_metric"
require "sentry/metrics/set_metric"
require "sentry/metrics/timing"
require "sentry/metrics/aggregator"

module Sentry
module Metrics
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 << self
def increment(key, value = 1.0, unit: "none", tags: {}, timestamp: nil)
Sentry.metrics_aggregator&.add(:c, key, value, unit: unit, tags: tags, timestamp: timestamp)
end

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

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

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

def timing(key, unit: "second", tags: {}, timestamp: nil, &block)
return unless block_given?
return yield unless DURATION_UNITS.include?(unit)
def method_missing(m, *args, &block)
return unless Sentry.initialized?

Check warning on line 7 in sentry-ruby/lib/sentry/metrics.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/metrics.rb#L7

Added line #L7 was not covered by tests

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]
Sentry.logger.warn(LOGGER_PROGNAME) do
"`Sentry::Metrics` is now deprecated and will be removed in the next major."

Check warning on line 10 in sentry-ruby/lib/sentry/metrics.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/metrics.rb#L9-L10

Added lines #L9 - L10 were not covered by tests
end

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