Skip to content
Merged
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 @@ -4,6 +4,28 @@

- Auto-enable Rails structured logging when `enable_logs` is true ([#2721](https://github.com/getsentry/sentry-ruby/pull/2721))

### Miscellaneous

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

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) }
```

### Internal

- Fix leftover `config.logger` call in `graphql` patch ([#2722](https://github.com/getsentry/sentry-ruby/2722)
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def initialize

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

Expand Down
12 changes: 12 additions & 0 deletions sentry-ruby/lib/sentry/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,28 @@ module Metrics

class << self
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

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

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

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

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

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

Expand All @@ -51,6 +57,12 @@ def timing(key, unit: "second", tags: {}, timestamp: nil, &block)
Sentry.metrics_aggregator&.add(:d, key, value, unit: unit, tags: tags, timestamp: timestamp)
result
end

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
end
end
end
14 changes: 12 additions & 2 deletions sentry-ruby/lib/sentry/metrics/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ module Sentry
module Metrics
class Configuration
include ArgumentCheckingHelper
include LoggingHelper

# Enable metrics usage.
# Starts a new {Sentry::Metrics::Aggregator} instance to aggregate metrics
# and a thread to aggregate flush every 5 seconds.
# @return [Boolean]
attr_accessor :enabled
attr_reader :enabled

# Enable code location reporting.
# Will be sent once per day.
Expand All @@ -32,11 +33,20 @@ class Configuration
# @return [Proc, nil]
attr_reader :before_emit

def initialize
def initialize(sdk_logger)
@sdk_logger = sdk_logger
@enabled = false
@enable_code_locations = true
end

def enabled=(value)
log_warn <<~MSG
`config.metrics` is now deprecated and will be removed in the next major.
MSG

@enabled = value
end

def before_emit=(value)
check_callable!("metrics.before_emit", value)

Expand Down
15 changes: 15 additions & 0 deletions sentry-ruby/spec/sentry/metrics/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# frozen_string_literal: true

RSpec.describe Sentry::Metrics::Configuration do
let(:string_io) { StringIO.new }
let(:sdk_logger) { Logger.new(string_io) }

let(:subject) { described_class.new(sdk_logger) }

describe '#enabled=' do
it 'logs deprecation warning' do
subject.enabled = true

expect(string_io.string).to include(
"WARN -- sentry: `config.metrics` is now deprecated and will be removed in the next major."
)
end
end

describe '#before_emit=' do
it 'raises error when setting before_emit to anything other than callable or nil' do
subject.before_emit = -> { }
Expand Down
49 changes: 46 additions & 3 deletions sentry-ruby/spec/sentry/metrics_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# frozen_string_literal: true

RSpec.describe Sentry::Metrics do
let(:aggregator) { Sentry.metrics_aggregator }
let(:fake_time) { Time.new(2024, 1, 1, 1, 1, 3) }
let(:string_io) { StringIO.new }
let(:sdk_logger) { Logger.new(string_io) }

before do
perform_basic_setup do |config|
config.metrics.enabled = true
config.sdk_logger = sdk_logger
end
end

let(:aggregator) { Sentry.metrics_aggregator }
let(:fake_time) { Time.new(2024, 1, 1, 1, 1, 3) }

describe '.increment' do
it 'passes default value of 1.0 with only key' do
expect(aggregator).to receive(:add).with(
Expand All @@ -36,6 +39,14 @@

described_class.increment('foo', 5.0, unit: 'second', tags: { fortytwo: 42 }, timestamp: fake_time)
end

it 'logs deprecation warning' do
described_class.increment('foo')

expect(string_io.string).to include(
"WARN -- sentry: `Sentry::Metrics` is now deprecated and will be removed in the next major."
)
end
end

describe '.distribution' do
Expand All @@ -51,6 +62,14 @@

described_class.distribution('foo', 5.0, unit: 'second', tags: { fortytwo: 42 }, timestamp: fake_time)
end

it 'logs deprecation warning' do
described_class.distribution('foo', 5.0, unit: 'second', tags: { fortytwo: 42 }, timestamp: fake_time)

expect(string_io.string).to include(
"WARN -- sentry: `Sentry::Metrics` is now deprecated and will be removed in the next major."
)
end
end

describe '.set' do
Expand All @@ -66,6 +85,14 @@

described_class.set('foo', 'jane', tags: { fortytwo: 42 }, timestamp: fake_time)
end

it 'logs deprecation warning' do
described_class.set('foo', 'jane', tags: { fortytwo: 42 }, timestamp: fake_time)

expect(string_io.string).to include(
"WARN -- sentry: `Sentry::Metrics` is now deprecated and will be removed in the next major."
)
end
end

describe '.gauge' do
Expand All @@ -81,6 +108,14 @@

described_class.gauge('foo', 5.0, unit: 'second', tags: { fortytwo: 42 }, timestamp: fake_time)
end

it 'logs deprecation warning' do
described_class.gauge('foo', 5.0, unit: 'second', tags: { fortytwo: 42 }, timestamp: fake_time)

expect(string_io.string).to include(
"WARN -- sentry: `Sentry::Metrics` is now deprecated and will be removed in the next major."
)
end
end

describe '.timing' do
Expand Down Expand Up @@ -109,6 +144,14 @@
expect(result).to eq(42)
end

it 'logs deprecation warning' do
described_class.timing('foo', unit: 'millisecond', tags: { fortytwo: 42 }, timestamp: fake_time) { sleep(0.1); 42 }

expect(string_io.string).to include(
"WARN -- sentry: `Sentry::Metrics` is now deprecated and will be removed in the next major."
)
end

context 'with running transaction' do
let(:transaction) { transaction = Sentry.start_transaction(name: 'metrics') }

Expand Down
Loading