diff --git a/CHANGELOG.md b/CHANGELOG.md index da6450a14..2f7284006 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Breaking Changes - Remove `config.async` [#1894](https://github.com/getsentry/sentry-ruby/pull/1894) +- Migrate from to_hash to to_h ([#2351](https://github.com/getsentry/sentry-ruby/pull/2351)) ## Unreleased diff --git a/sentry-delayed_job/spec/sentry/delayed_job_spec.rb b/sentry-delayed_job/spec/sentry/delayed_job_spec.rb index 24a1de77d..4d4febe58 100644 --- a/sentry-delayed_job/spec/sentry/delayed_job_spec.rb +++ b/sentry-delayed_job/spec/sentry/delayed_job_spec.rb @@ -46,7 +46,7 @@ def do_nothing_with_args(a) enqueued_job.invoke_job expect(transport.events.count).to eq(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:message]).to eq("report") expect(event[:contexts][:"Delayed-Job"][:id]).to eq(enqueued_job.id.to_s) expect(event[:tags]).to eq({ "delayed_job.id" => enqueued_job.id.to_s, "delayed_job.queue" => nil }) @@ -68,7 +68,7 @@ def do_nothing_with_args(a) enqueued_job.invoke_job expect(transport.events.count).to eq(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:message]).to eq("tagged report") expect(event[:tags]).to eq({ "delayed_job.id" => enqueued_job.id.to_s, "delayed_job.queue" => nil, number: 1 }) @@ -77,7 +77,7 @@ def do_nothing_with_args(a) enqueued_job.invoke_job expect(transport.events.count).to eq(2) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:tags]).to eq({ "delayed_job.id" => enqueued_job.id.to_s, "delayed_job.queue" => nil }) end @@ -93,7 +93,7 @@ def do_nothing_with_args(a) end.to raise_error(ZeroDivisionError) expect(transport.events.count).to eq(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:sdk]).to eq({ name: "sentry.ruby.delayed_job", version: described_class::VERSION }) expect(event.dig(:exception, :values, 0, :type)).to eq("ZeroDivisionError") @@ -109,7 +109,7 @@ def do_nothing_with_args(a) end.to raise_error(RuntimeError) expect(transport.events.count).to eq(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:tags]).to eq({ "delayed_job.id" => enqueued_job.id.to_s, "delayed_job.queue" => nil, number: 1 }) expect(Sentry.get_current_scope.extra).to eq({}) @@ -123,7 +123,7 @@ def do_nothing_with_args(a) end.to raise_error(ZeroDivisionError) expect(transport.events.count).to eq(2) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:tags]).to eq({ "delayed_job.id" => enqueued_job.id.to_s, "delayed_job.queue" => nil }) expect(Sentry.get_current_scope.extra).to eq({}) expect(Sentry.get_current_scope.tags).to eq({}) @@ -228,7 +228,7 @@ def perform it "injects ActiveJob information to the event" do expect(transport.events.count).to eq(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:message]).to eq("report from ActiveJob") expect(event[:tags]).to match({ "delayed_job.id" => anything, "delayed_job.queue" => "default", number: 1 }) expect(event[:contexts][:"Active-Job"][:job_class]).to eq("ReportingJob") @@ -255,7 +255,7 @@ def perform it "injects ActiveJob information to the event" do expect(transport.events.count).to eq(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event.dig(:exception, :values, 0, :type)).to eq("ZeroDivisionError") expect(event[:tags]).to match({ "delayed_job.id" => anything, "delayed_job.queue" => "default", number: 2 }) expect(event[:contexts][:"Active-Job"][:job_class]).to eq("FailedJob") diff --git a/sentry-rails/spec/sentry/rails/activejob_spec.rb b/sentry-rails/spec/sentry/rails/activejob_spec.rb index 380230605..2b6142218 100644 --- a/sentry-rails/spec/sentry/rails/activejob_spec.rb +++ b/sentry-rails/spec/sentry/rails/activejob_spec.rb @@ -254,7 +254,7 @@ def perform expect(transport.events.size).to eq(1) event = transport.events.first - exceptions_data = event.exception.to_hash[:values] + exceptions_data = event.exception.to_h[:values] expect(exceptions_data.count).to eq(2) expect(exceptions_data[0][:type]).to eq("FailedJob::TestError") @@ -293,7 +293,7 @@ def perform first = transport.events[0] check_in_id = first.check_in_id expect(first).to be_a(Sentry::CheckInEvent) - expect(first.to_hash).to include( + expect(first.to_h).to include( type: 'check_in', check_in_id: check_in_id, monitor_slug: "normaljobwithcron", @@ -302,7 +302,7 @@ def perform second = transport.events[1] expect(second).to be_a(Sentry::CheckInEvent) - expect(second.to_hash).to include( + expect(second.to_h).to include( :duration, type: 'check_in', check_in_id: check_in_id, @@ -321,7 +321,7 @@ def perform first = transport.events[0] check_in_id = first.check_in_id expect(first).to be_a(Sentry::CheckInEvent) - expect(first.to_hash).to include( + expect(first.to_h).to include( type: 'check_in', check_in_id: check_in_id, monitor_slug: "failed_job", @@ -331,7 +331,7 @@ def perform second = transport.events[1] expect(second).to be_a(Sentry::CheckInEvent) - expect(second.to_hash).to include( + expect(second.to_h).to include( :duration, type: 'check_in', check_in_id: check_in_id, diff --git a/sentry-rails/spec/sentry/rails/breadcrumbs/active_support_logger_spec.rb b/sentry-rails/spec/sentry/rails/breadcrumbs/active_support_logger_spec.rb index e6a0ae6e3..b133d8f47 100644 --- a/sentry-rails/spec/sentry/rails/breadcrumbs/active_support_logger_spec.rb +++ b/sentry-rails/spec/sentry/rails/breadcrumbs/active_support_logger_spec.rb @@ -130,7 +130,7 @@ expect(transport.events.count).to eq(1) - transaction = transport.events.last.to_hash + transaction = transport.events.last.to_h breadcrumbs = transaction[:breadcrumbs][:values] process_action_crumb = breadcrumbs.last expect(process_action_crumb[:category]).to eq("process_action.action_controller") diff --git a/sentry-rails/spec/sentry/rails/breadcrumbs/monotonic_active_support_logger_spec.rb b/sentry-rails/spec/sentry/rails/breadcrumbs/monotonic_active_support_logger_spec.rb index 031443c25..11bb0cbaa 100644 --- a/sentry-rails/spec/sentry/rails/breadcrumbs/monotonic_active_support_logger_spec.rb +++ b/sentry-rails/spec/sentry/rails/breadcrumbs/monotonic_active_support_logger_spec.rb @@ -134,7 +134,7 @@ expect(transport.events.count).to eq(1) - transaction = transport.events.last.to_hash + transaction = transport.events.last.to_h breadcrumbs = transaction[:breadcrumbs][:values] process_action_crumb = breadcrumbs.last expect(process_action_crumb[:category]).to eq("process_action.action_controller") diff --git a/sentry-rails/spec/sentry/rails/controller_methods_spec.rb b/sentry-rails/spec/sentry/rails/controller_methods_spec.rb index 6254dc290..0f9c82af6 100644 --- a/sentry-rails/spec/sentry/rails/controller_methods_spec.rb +++ b/sentry-rails/spec/sentry/rails/controller_methods_spec.rb @@ -37,7 +37,7 @@ def request event = transport.events.last expect(event.message).to eq("foo") expect(event.tags).to eq({ new_tag: true }) - expect(event.to_hash.dig(:request, :url)).to eq("http://example.org/test") + expect(event.to_h.dig(:request, :url)).to eq("http://example.org/test") end end @@ -49,8 +49,8 @@ def request event = transport.events.last expect(event.tags).to eq({ new_tag: true }) - expect(event.to_hash.dig(:exception, :values, 0, :type)).to eq("ZeroDivisionError") - expect(event.to_hash.dig(:request, :url)).to eq("http://example.org/test") + expect(event.to_h.dig(:exception, :values, 0, :type)).to eq("ZeroDivisionError") + expect(event.to_h.dig(:request, :url)).to eq("http://example.org/test") end end end diff --git a/sentry-rails/spec/sentry/rails/event_spec.rb b/sentry-rails/spec/sentry/rails/event_spec.rb index 6c3f7b661..c841266c6 100644 --- a/sentry-rails/spec/sentry/rails/event_spec.rb +++ b/sentry-rails/spec/sentry/rails/event_spec.rb @@ -8,7 +8,7 @@ end it "sets right SDK information" do - event_hash = Sentry::Rails.capture_message("foo").to_hash + event_hash = Sentry::Rails.capture_message("foo").to_h expect(event_hash[:sdk]).to eq(name: "sentry.ruby.rails", version: Sentry::Rails::VERSION) end @@ -27,7 +27,7 @@ e end - let(:hash) { Sentry::Rails.capture_exception(exception).to_hash } + let(:hash) { Sentry::Rails.capture_exception(exception).to_h } it 'marks in_app correctly' do frames = hash[:exception][:values][0][:stacktrace][:frames] diff --git a/sentry-rails/spec/sentry/rails/tracing/action_controller_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/tracing/action_controller_subscriber_spec.rb index 9d0a4df4e..bec52a40d 100644 --- a/sentry-rails/spec/sentry/rails/tracing/action_controller_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing/action_controller_subscriber_spec.rb @@ -32,7 +32,7 @@ expect(transport.events.count).to eq(1) - transaction = transport.events.first.to_hash + transaction = transport.events.first.to_h expect(transaction[:type]).to eq("transaction") expect(transaction[:spans].count).to eq(2) diff --git a/sentry-rails/spec/sentry/rails/tracing/action_view_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/tracing/action_view_subscriber_spec.rb index 555584024..dba6c9546 100644 --- a/sentry-rails/spec/sentry/rails/tracing/action_view_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing/action_view_subscriber_spec.rb @@ -20,7 +20,7 @@ expect(transport.events.count).to eq(1) - transaction = transport.events.first.to_hash + transaction = transport.events.first.to_h expect(transaction[:type]).to eq("transaction") expect(transaction[:spans].count).to eq(2) diff --git a/sentry-rails/spec/sentry/rails/tracing/active_record_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/tracing/active_record_subscriber_spec.rb index 2441a63d3..24a1b8186 100644 --- a/sentry-rails/spec/sentry/rails/tracing/active_record_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing/active_record_subscriber_spec.rb @@ -30,7 +30,7 @@ expect(transport.events.count).to eq(1) - transaction = transport.events.first.to_hash + transaction = transport.events.first.to_h expect(transaction[:type]).to eq("transaction") expect(transaction[:spans].count).to eq(1) @@ -67,7 +67,7 @@ def foo it "doesn't record query's source location" do expect(transport.events.count).to eq(1) - transaction = transport.events.first.to_hash + transaction = transport.events.first.to_h expect(transaction[:type]).to eq("transaction") expect(transaction[:spans].count).to eq(1) @@ -86,7 +86,7 @@ def foo it "records query's source location" do expect(transport.events.count).to eq(1) - transaction = transport.events.first.to_hash + transaction = transport.events.first.to_h expect(transaction[:type]).to eq("transaction") expect(transaction[:spans].count).to eq(1) @@ -104,7 +104,7 @@ def foo it "doesn't record query's source location" do expect(transport.events.count).to eq(1) - transaction = transport.events.first.to_hash + transaction = transport.events.first.to_h expect(transaction[:type]).to eq("transaction") expect(transaction[:spans].count).to eq(1) @@ -131,7 +131,7 @@ def foo expect(transport.events.count).to eq(1) - transaction = transport.events.first.to_hash + transaction = transport.events.first.to_h expect(transaction[:type]).to eq("transaction") expect(transaction[:spans].count).to eq(2) diff --git a/sentry-rails/spec/sentry/rails/tracing/active_storage_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/tracing/active_storage_subscriber_spec.rb index a5e186d7e..a6764aea7 100644 --- a/sentry-rails/spec/sentry/rails/tracing/active_storage_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing/active_storage_subscriber_spec.rb @@ -25,7 +25,7 @@ expect(response).to have_http_status(:ok) expect(transport.events.count).to eq(2) - analysis_transaction = transport.events.first.to_hash + analysis_transaction = transport.events.first.to_h expect(analysis_transaction[:type]).to eq("transaction") if Rails.version.to_f > 6.1 @@ -40,7 +40,7 @@ expect(analysis_transaction[:spans][0][:origin]).to eq("auto.file.rails") end - request_transaction = transport.events.last.to_hash + request_transaction = transport.events.last.to_h expect(request_transaction[:type]).to eq("transaction") expect(request_transaction[:spans].count).to eq(2) diff --git a/sentry-rails/spec/sentry/rails/tracing_spec.rb b/sentry-rails/spec/sentry/rails/tracing_spec.rb index 36063f39d..40d0b9efe 100644 --- a/sentry-rails/spec/sentry/rails/tracing_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing_spec.rb @@ -26,8 +26,8 @@ expect(response).to have_http_status(:internal_server_error) expect(transport.events.count).to eq(2) - event = transport.events.first.to_hash - transaction = transport.events.last.to_hash + event = transport.events.first.to_h + transaction = transport.events.last.to_h expect(event.dig(:contexts, :trace, :trace_id).length).to eq(32) expect(event.dig(:contexts, :trace, :trace_id)).to eq(transaction.dig(:contexts, :trace, :trace_id)) @@ -64,7 +64,7 @@ expect(response).to have_http_status(:ok) expect(transport.events.count).to eq(1) - transaction = transport.events.last.to_hash + transaction = transport.events.last.to_h expect(transaction[:type]).to eq("transaction") expect(transaction.dig(:contexts, :trace, :op)).to eq("http.server") @@ -254,7 +254,7 @@ expect(transport.events.count).to eq(3) - transaction = transport.events.last.to_hash + transaction = transport.events.last.to_h expect(transaction[:type]).to eq("transaction") expect(transaction[:transaction]).to eq("PostsController#show") diff --git a/sentry-resque/spec/sentry/resque_spec.rb b/sentry-resque/spec/sentry/resque_spec.rb index 7239284e3..00e7b1e73 100644 --- a/sentry-resque/spec/sentry/resque_spec.rb +++ b/sentry-resque/spec/sentry/resque_spec.rb @@ -66,7 +66,7 @@ def self.perform(msg) process_job(worker) expect(transport.events.count).to eq(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:message]).to eq("report") expect(event[:tags]).to eq({ "resque.queue" => "default" }) expect(event[:contexts][:"Resque"]).to include({ job_class: "MessageJob", arguments: ["report"], queue: "default" }) @@ -88,7 +88,7 @@ def self.perform(msg) process_job(worker) expect(transport.events.count).to eq(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:message]).to eq("tagged report") expect(event[:tags]).to include({ number: 1 }) @@ -97,7 +97,7 @@ def self.perform(msg) process_job(worker) expect(transport.events.count).to eq(2) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:tags]).to eq({ "resque.queue" => "default" }) end @@ -109,7 +109,7 @@ def self.perform(msg) end.to change { Resque::Stat.get("failed") }.by(1) expect(transport.events.count).to eq(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:sdk]).to eq({ name: "sentry.ruby.resque", version: described_class::VERSION }) expect(event.dig(:exception, :values, 0, :type)).to eq("ZeroDivisionError") @@ -123,7 +123,7 @@ def self.perform(msg) end.to change { Resque::Stat.get("failed") }.by(1) expect(transport.events.count).to eq(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:tags]).to eq({ "resque.queue" => "default", number: 1 }) expect(Sentry.get_current_scope.extra).to eq({}) @@ -135,7 +135,7 @@ def self.perform(msg) end.to change { Resque::Stat.get("failed") }.by(1) expect(transport.events.count).to eq(2) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:tags]).to eq({ "resque.queue" => "default" }) expect(Sentry.get_current_scope.extra).to eq({}) expect(Sentry.get_current_scope.tags).to eq({}) @@ -161,7 +161,7 @@ def self.perform(msg) end end.to change { transport.events.count }.by(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:sdk]).to eq({ name: "sentry.ruby.resque", version: described_class::VERSION }) expect(event.dig(:exception, :values, 0, :type)).to eq("ZeroDivisionError") @@ -175,7 +175,7 @@ def self.perform(msg) end.to change { Resque::Stat.get("failed") }.by(1) .and change { transport.events.count }.by(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:sdk]).to eq({ name: "sentry.ruby.resque", version: described_class::VERSION }) expect(event.dig(:exception, :values, 0, :type)).to eq("ZeroDivisionError") @@ -201,7 +201,7 @@ def self.perform(msg) end end.to change { transport.events.count }.by(3) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:sdk]).to eq({ name: "sentry.ruby.resque", version: described_class::VERSION }) expect(event.dig(:exception, :values, 0, :type)).to eq("ZeroDivisionError") @@ -266,7 +266,7 @@ def perform it "injects ActiveJob information to the event" do expect(transport.events.count).to eq(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:message]).to eq("report from ActiveJob") expect(event[:tags]).to match({ "resque.queue" => "default", number: 1 }) expect(event[:contexts][:"Active-Job"][:job_class]).to eq("AJMessageJob") @@ -291,7 +291,7 @@ def perform it "injects ActiveJob information to the event" do expect(transport.events.count).to eq(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event.dig(:exception, :values, 0, :type)).to eq("ZeroDivisionError") expect(event[:tags]).to match({ "resque.queue" => "default", number: 2 }) expect(event[:contexts][:"Active-Job"][:job_class]).to eq("AJFailedJob") diff --git a/sentry-resque/spec/sentry/tracing_spec.rb b/sentry-resque/spec/sentry/tracing_spec.rb index bf81f9006..827d4ab20 100644 --- a/sentry-resque/spec/sentry/tracing_spec.rb +++ b/sentry-resque/spec/sentry/tracing_spec.rb @@ -35,10 +35,10 @@ def self.perform(msg) worker.work(0) expect(transport.events.count).to eq(2) - event = transport.events.first.to_hash + event = transport.events.first.to_h expect(event[:message]).to eq("report") - tracing_event = transport.events.last.to_hash + tracing_event = transport.events.last.to_h expect(tracing_event[:transaction]).to eq("MessageJob") expect(tracing_event[:transaction_info]).to eq({ source: :task }) expect(tracing_event[:type]).to eq("transaction") @@ -53,10 +53,10 @@ def self.perform(msg) worker.work(0) expect(transport.events.count).to eq(2) - event = transport.events.first.to_hash + event = transport.events.first.to_h expect(event.dig(:exception, :values, 0, :type)).to eq("ZeroDivisionError") - tracing_event = transport.events.last.to_hash + tracing_event = transport.events.last.to_h expect(tracing_event[:transaction]).to eq("FailedJob") expect(tracing_event[:transaction_info]).to eq({ source: :task }) expect(tracing_event[:type]).to eq("transaction") @@ -78,7 +78,7 @@ def self.perform(msg) worker.work(0) expect(transport.events.count).to eq(1) - event = transport.events.first.to_hash + event = transport.events.first.to_h expect(event[:message]).to eq("report") end end diff --git a/sentry-ruby/lib/sentry/breadcrumb.rb b/sentry-ruby/lib/sentry/breadcrumb.rb index 4dce35df1..cbb0bc914 100644 --- a/sentry-ruby/lib/sentry/breadcrumb.rb +++ b/sentry-ruby/lib/sentry/breadcrumb.rb @@ -33,7 +33,7 @@ def initialize(category: nil, data: nil, message: nil, timestamp: nil, level: ni end # @return [Hash] - def to_hash + def to_h { category: @category, data: serialized_data, diff --git a/sentry-ruby/lib/sentry/breadcrumb_buffer.rb b/sentry-ruby/lib/sentry/breadcrumb_buffer.rb index 7f3a2dc04..3a5cc0177 100644 --- a/sentry-ruby/lib/sentry/breadcrumb_buffer.rb +++ b/sentry-ruby/lib/sentry/breadcrumb_buffer.rb @@ -48,9 +48,9 @@ def empty? end # @return [Hash] - def to_hash + def to_h { - values: members.map(&:to_hash) + values: members.map(&:to_h) } end diff --git a/sentry-ruby/lib/sentry/check_in_event.rb b/sentry-ruby/lib/sentry/check_in_event.rb index 91ae17dc3..31e81c618 100644 --- a/sentry-ruby/lib/sentry/check_in_event.rb +++ b/sentry-ruby/lib/sentry/check_in_event.rb @@ -47,13 +47,13 @@ def initialize( end # @return [Hash] - def to_hash + def to_h data = super data[:check_in_id] = check_in_id data[:monitor_slug] = monitor_slug data[:status] = status data[:duration] = duration if duration - data[:monitor_config] = monitor_config.to_hash if monitor_config + data[:monitor_config] = monitor_config.to_h if monitor_config data end end diff --git a/sentry-ruby/lib/sentry/cron/monitor_config.rb b/sentry-ruby/lib/sentry/cron/monitor_config.rb index dfd28a4bd..36d7b52e8 100644 --- a/sentry-ruby/lib/sentry/cron/monitor_config.rb +++ b/sentry-ruby/lib/sentry/cron/monitor_config.rb @@ -40,9 +40,9 @@ def self.from_interval(num, unit, **options) new(MonitorSchedule::Interval.new(num, unit), **options) end - def to_hash + def to_h { - schedule: schedule.to_hash, + schedule: schedule.to_h, checkin_margin: checkin_margin, max_runtime: max_runtime, timezone: timezone diff --git a/sentry-ruby/lib/sentry/cron/monitor_schedule.rb b/sentry-ruby/lib/sentry/cron/monitor_schedule.rb index d7c80cdd8..cb5423cab 100644 --- a/sentry-ruby/lib/sentry/cron/monitor_schedule.rb +++ b/sentry-ruby/lib/sentry/cron/monitor_schedule.rb @@ -12,7 +12,7 @@ def initialize(value) @value = value end - def to_hash + def to_h { type: :crontab, value: value } end end @@ -33,7 +33,7 @@ def initialize(value, unit) @unit = unit end - def to_hash + def to_h { type: :interval, value: value, unit: unit } end end diff --git a/sentry-ruby/lib/sentry/error_event.rb b/sentry-ruby/lib/sentry/error_event.rb index 13a891f71..a76e8b2ab 100644 --- a/sentry-ruby/lib/sentry/error_event.rb +++ b/sentry-ruby/lib/sentry/error_event.rb @@ -10,10 +10,10 @@ class ErrorEvent < Event attr_reader :threads # @return [Hash] - def to_hash + def to_h data = super - data[:threads] = threads.to_hash if threads - data[:exception] = exception.to_hash if exception + data[:threads] = threads.to_h if threads + data[:exception] = exception.to_h if exception data end diff --git a/sentry-ruby/lib/sentry/event.rb b/sentry-ruby/lib/sentry/event.rb index 154452599..fa0b7e8a8 100644 --- a/sentry-ruby/lib/sentry/event.rb +++ b/sentry-ruby/lib/sentry/event.rb @@ -117,16 +117,16 @@ def rack_env=(env) end # @return [Hash] - def to_hash + def to_h data = serialize_attributes - data[:breadcrumbs] = breadcrumbs.to_hash if breadcrumbs - data[:request] = request.to_hash if request + data[:breadcrumbs] = breadcrumbs.to_h if breadcrumbs + data[:request] = request.to_h if request data end # @return [Hash] def to_json_compatible - JSON.parse(JSON.generate(to_hash)) + JSON.parse(JSON.generate(to_h)) end private diff --git a/sentry-ruby/lib/sentry/hub.rb b/sentry-ruby/lib/sentry/hub.rb index b9b58638d..edf54c0db 100644 --- a/sentry-ruby/lib/sentry/hub.rb +++ b/sentry-ruby/lib/sentry/hub.rb @@ -89,7 +89,7 @@ def start_transaction(transaction: nil, custom_sampling_context: {}, instrumente transaction ||= Transaction.new(**options.merge(hub: self)) sampling_context = { - transaction_context: transaction.to_hash, + transaction_context: transaction.to_h, parent_sampled: transaction.parent_sampled } diff --git a/sentry-ruby/lib/sentry/interface.rb b/sentry-ruby/lib/sentry/interface.rb index d54d605b1..ed8f60cb0 100644 --- a/sentry-ruby/lib/sentry/interface.rb +++ b/sentry-ruby/lib/sentry/interface.rb @@ -3,7 +3,7 @@ module Sentry class Interface # @return [Hash] - def to_hash + def to_h Hash[instance_variables.map { |name| [name[1..-1].to_sym, instance_variable_get(name)] }] end end diff --git a/sentry-ruby/lib/sentry/interfaces/exception.rb b/sentry-ruby/lib/sentry/interfaces/exception.rb index 58cb1a576..4ca18d5ae 100644 --- a/sentry-ruby/lib/sentry/interfaces/exception.rb +++ b/sentry-ruby/lib/sentry/interfaces/exception.rb @@ -13,9 +13,9 @@ def initialize(exceptions:) end # @return [Hash] - def to_hash + def to_h data = super - data[:values] = data[:values].map(&:to_hash) if data[:values] + data[:values] = data[:values].map(&:to_h) if data[:values] data end diff --git a/sentry-ruby/lib/sentry/interfaces/single_exception.rb b/sentry-ruby/lib/sentry/interfaces/single_exception.rb index db2d54e7b..1753ed0ae 100644 --- a/sentry-ruby/lib/sentry/interfaces/single_exception.rb +++ b/sentry-ruby/lib/sentry/interfaces/single_exception.rb @@ -32,10 +32,10 @@ def initialize(exception:, mechanism:, stacktrace: nil) @mechanism = mechanism end - def to_hash + def to_h data = super - data[:stacktrace] = data[:stacktrace].to_hash if data[:stacktrace] - data[:mechanism] = data[:mechanism].to_hash + data[:stacktrace] = data[:stacktrace].to_h if data[:stacktrace] + data[:mechanism] = data[:mechanism].to_h data end diff --git a/sentry-ruby/lib/sentry/interfaces/stacktrace.rb b/sentry-ruby/lib/sentry/interfaces/stacktrace.rb index 5f4be3719..104b7a0fb 100644 --- a/sentry-ruby/lib/sentry/interfaces/stacktrace.rb +++ b/sentry-ruby/lib/sentry/interfaces/stacktrace.rb @@ -11,8 +11,8 @@ def initialize(frames:) end # @return [Hash] - def to_hash - { frames: @frames.map(&:to_hash) } + def to_h + { frames: @frames.map(&:to_h) } end # @return [String] @@ -66,7 +66,7 @@ def set_context(linecache, context_lines) linecache.get_file_context(abs_path, lineno, context_lines) end - def to_hash(*args) + def to_h(*args) data = super(*args) data.delete(:vars) unless vars && !vars.empty? data.delete(:pre_context) unless pre_context && !pre_context.empty? diff --git a/sentry-ruby/lib/sentry/interfaces/stacktrace_builder.rb b/sentry-ruby/lib/sentry/interfaces/stacktrace_builder.rb index d2d0758ec..bbe4150c1 100644 --- a/sentry-ruby/lib/sentry/interfaces/stacktrace_builder.rb +++ b/sentry-ruby/lib/sentry/interfaces/stacktrace_builder.rb @@ -80,7 +80,7 @@ def build(backtrace:, &frame_callback) 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) } + frame.to_h.reject { |k, _| %i[project_root in_app].include?(k) } end private diff --git a/sentry-ruby/lib/sentry/interfaces/threads.rb b/sentry-ruby/lib/sentry/interfaces/threads.rb index f250050db..bac6e0e25 100644 --- a/sentry-ruby/lib/sentry/interfaces/threads.rb +++ b/sentry-ruby/lib/sentry/interfaces/threads.rb @@ -13,7 +13,7 @@ def initialize(crashed: false, stacktrace: nil) end # @return [Hash] - def to_hash + def to_h { values: [ { @@ -21,7 +21,7 @@ def to_hash name: @name, crashed: @crashed, current: @current, - stacktrace: @stacktrace&.to_hash + stacktrace: @stacktrace&.to_h } ] } diff --git a/sentry-ruby/lib/sentry/metrics/local_aggregator.rb b/sentry-ruby/lib/sentry/metrics/local_aggregator.rb index 99d50a5b1..375ca7052 100644 --- a/sentry-ruby/lib/sentry/metrics/local_aggregator.rb +++ b/sentry-ruby/lib/sentry/metrics/local_aggregator.rb @@ -18,7 +18,7 @@ def add(key, value) end end - def to_hash + def to_h return nil if @buckets.empty? @buckets.map do |bucket_key, metric| diff --git a/sentry-ruby/lib/sentry/profiler.rb b/sentry-ruby/lib/sentry/profiler.rb index d81e46024..a87f5a2ec 100644 --- a/sentry-ruby/lib/sentry/profiler.rb +++ b/sentry-ruby/lib/sentry/profiler.rb @@ -80,7 +80,7 @@ def set_initial_sample_decision(transaction_sampled) log("Discarding profile due to sampling decision") unless @sampled end - def to_hash + def to_h unless @sampled record_lost_event(:sample_rate) return {} diff --git a/sentry-ruby/lib/sentry/span.rb b/sentry-ruby/lib/sentry/span.rb index 3dd2158ea..66176e99a 100644 --- a/sentry-ruby/lib/sentry/span.rb +++ b/sentry-ruby/lib/sentry/span.rb @@ -167,7 +167,7 @@ def get_dynamic_sampling_context end # @return [Hash] - def to_hash + def to_h hash = { trace_id: @trace_id, span_id: @span_id, @@ -308,7 +308,7 @@ def metrics_local_aggregator end def metrics_summary - @metrics_local_aggregator&.to_hash + @metrics_local_aggregator&.to_h end end end diff --git a/sentry-ruby/lib/sentry/transaction.rb b/sentry-ruby/lib/sentry/transaction.rb index 5e3ceb982..1c4fa7378 100644 --- a/sentry-ruby/lib/sentry/transaction.rb +++ b/sentry-ruby/lib/sentry/transaction.rb @@ -139,7 +139,7 @@ def self.extract_sentry_trace(sentry_trace) end # @return [Hash] - def to_hash + def to_h hash = super hash.merge!( diff --git a/sentry-ruby/lib/sentry/transaction_event.rb b/sentry-ruby/lib/sentry/transaction_event.rb index a1a8767d1..92ea2b12b 100644 --- a/sentry-ruby/lib/sentry/transaction_event.rb +++ b/sentry-ruby/lib/sentry/transaction_event.rb @@ -35,7 +35,7 @@ def initialize(transaction:, **options) self.metrics_summary = transaction.metrics_summary finished_spans = transaction.span_recorder.spans.select { |span| span.timestamp && span != transaction } - self.spans = finished_spans.map(&:to_hash) + self.spans = finished_spans.map(&:to_h) populate_profile(transaction) end @@ -48,9 +48,9 @@ def start_timestamp=(time) end # @return [Hash] - def to_hash + def to_h data = super - data[:spans] = @spans.map(&:to_hash) if @spans + data[:spans] = @spans.map(&:to_h) if @spans data[:start_timestamp] = @start_timestamp data[:measurements] = @measurements data[:_metrics_summary] = @metrics_summary if @metrics_summary @@ -60,7 +60,7 @@ def to_hash private def populate_profile(transaction) - profile_hash = transaction.profiler.to_hash + profile_hash = transaction.profiler.to_h return if profile_hash.empty? profile_hash.merge!( diff --git a/sentry-ruby/lib/sentry/transport.rb b/sentry-ruby/lib/sentry/transport.rb index 406d5101b..c904ff953 100644 --- a/sentry-ruby/lib/sentry/transport.rb +++ b/sentry-ruby/lib/sentry/transport.rb @@ -116,7 +116,7 @@ def any_rate_limited? def envelope_from_event(event) # Convert to hash - event_payload = event.to_hash + event_payload = event.to_h event_id = event_payload[:event_id] || event_payload["event_id"] item_type = event_payload[:type] || event_payload["type"] diff --git a/sentry-ruby/spec/sentry/breadcrumb_buffer_spec.rb b/sentry-ruby/spec/sentry/breadcrumb_buffer_spec.rb index f68e223b3..612e0c0bb 100644 --- a/sentry-ruby/spec/sentry/breadcrumb_buffer_spec.rb +++ b/sentry-ruby/spec/sentry/breadcrumb_buffer_spec.rb @@ -57,13 +57,13 @@ end end - describe "#to_hash" do + describe "#to_h" do it "doesn't break because of 1 problematic crumb" do subject.record(crumb_1) subject.record(crumb_2) subject.record(problematic_crumb) - result = subject.to_hash[:values] + result = subject.to_h[:values] expect(result[0][:category]).to eq("foo") expect(result[0][:data]).to eq({ "name" => "John", "age" => 25 }) diff --git a/sentry-ruby/spec/sentry/breadcrumb_spec.rb b/sentry-ruby/spec/sentry/breadcrumb_spec.rb index 2eddb7101..ad21a8db0 100644 --- a/sentry-ruby/spec/sentry/breadcrumb_spec.rb +++ b/sentry-ruby/spec/sentry/breadcrumb_spec.rb @@ -56,7 +56,7 @@ end end - describe "#to_hash" do + describe "#to_h" do let(:problematic_crumb) do # circular reference a = [] @@ -72,7 +72,7 @@ end it "serializes data correctly" do - result = crumb.to_hash + result = crumb.to_h expect(result[:category]).to eq("foo") expect(result[:message]).to eq("crumb") @@ -80,7 +80,7 @@ end it "rescues data serialization issue and ditch the data" do - result = problematic_crumb.to_hash + result = problematic_crumb.to_h expect(result[:category]).to eq("baz") expect(result[:message]).to eq("I cause issues") diff --git a/sentry-ruby/spec/sentry/client_spec.rb b/sentry-ruby/spec/sentry/client_spec.rb index e069ccc5b..20b25a145 100644 --- a/sentry-ruby/spec/sentry/client_spec.rb +++ b/sentry-ruby/spec/sentry/client_spec.rb @@ -181,7 +181,7 @@ def sentry_context it 'returns an event' do event = subject.event_from_message(message) - hash = event.to_hash + hash = event.to_h expect(event).to be_a(Sentry::ErrorEvent) expect(hash[:message]).to eq(message) @@ -197,7 +197,7 @@ def sentry_context t.name = "Thread 1" t.join - hash = event.to_hash + hash = event.to_h thread = hash[:threads][:values][0] expect(thread[:id]).to eq(t.object_id) @@ -225,7 +225,7 @@ def sentry_context it "initializes a correct event for the transaction" do event = subject.event_from_transaction(transaction) - event_hash = event.to_hash + event_hash = event.to_h expect(event_hash[:type]).to eq("transaction") expect(event_hash[:contexts][:trace]).to eq(transaction.get_trace_context) @@ -280,7 +280,7 @@ def sentry_context it 'adds metric summary on transaction if any' do key = [:c, 'incr', 'none', []] transaction.metrics_local_aggregator.add(key, 10) - hash = subject.event_from_transaction(transaction).to_hash + hash = subject.event_from_transaction(transaction).to_h expect(hash[:_metrics_summary]).to eq({ 'c:incr@none' => { count: 1, max: 10.0, min: 10.0, sum: 10.0, tags: {} } @@ -292,7 +292,7 @@ def sentry_context let(:message) { 'This is a message' } let(:exception) { Exception.new(message) } let(:event) { subject.event_from_exception(exception) } - let(:hash) { event.to_hash } + let(:hash) { event.to_h } it "sets the message to the exception's value and type" do expect(hash[:exception][:values][0][:type]).to eq("Exception") @@ -341,7 +341,7 @@ def detailed_message(*) end event = subject.event_from_exception(NonStringMessageError.new) - hash = event.to_hash + hash = event.to_h expect(event).to be_a(Sentry::ErrorEvent) if RUBY_VERSION >= "3.4" @@ -362,7 +362,7 @@ def detailed_message(*) t.name = "Thread 1" t.join - event_hash = event.to_hash + event_hash = event.to_h thread = event_hash[:threads][:values][0] expect(thread[:id]).to eq(t.object_id) @@ -383,7 +383,7 @@ def detailed_message(*) it 'returns an event' do event = subject.event_from_exception(ZeroDivisionError.new("divided by 0")) expect(event).to be_a(Sentry::ErrorEvent) - hash = event.to_hash + hash = event.to_h expect(hash[:exception][:values][0][:type]).to match("ZeroDivisionError") expect(hash[:exception][:values][0][:value]).to match("divided by 0") end @@ -583,7 +583,7 @@ module ExcTag; end context 'when the exception responds to sentry_context' do let(:hash) do event = subject.event_from_exception(ExceptionWithContext.new) - event.to_hash + event.to_h end it "merges the context into event's extra" do @@ -661,7 +661,7 @@ module ExcTag; end it 'has correct custom mechanism when passed' do mech = Sentry::Mechanism.new(type: 'custom', handled: false) event = subject.event_from_exception(exception, mechanism: mech) - hash = event.to_hash + hash = event.to_h mechanism = hash[:exception][:values][0][:mechanism] expect(mechanism).to eq({ type: 'custom', handled: false }) end @@ -676,7 +676,7 @@ module ExcTag; end event = subject.event_from_check_in(slug, status) expect(event).to be_a(Sentry::CheckInEvent) - hash = event.to_hash + hash = event.to_h expect(hash[:monitor_slug]).to eq(slug) expect(hash[:status]).to eq(status) expect(hash[:check_in_id].length).to eq(32) @@ -693,7 +693,7 @@ module ExcTag; end expect(event).to be_a(Sentry::CheckInEvent) - hash = event.to_hash + hash = event.to_h expect(hash[:monitor_slug]).to eq(slug) expect(hash[:status]).to eq(status) expect(hash[:check_in_id]).to eq("xxx-yyy") @@ -712,7 +712,7 @@ module ExcTag; end expect(event).to be_a(Sentry::CheckInEvent) - hash = event.to_hash + hash = event.to_h expect(hash[:monitor_slug]).to eq(slug) expect(hash[:status]).to eq(status) expect(hash[:check_in_id]).to eq("xxx-yyy") diff --git a/sentry-ruby/spec/sentry/cron/monitor_config_spec.rb b/sentry-ruby/spec/sentry/cron/monitor_config_spec.rb index 1c934e8cc..fecb00681 100644 --- a/sentry-ruby/spec/sentry/cron/monitor_config_spec.rb +++ b/sentry-ruby/spec/sentry/cron/monitor_config_spec.rb @@ -45,7 +45,7 @@ end end - describe '#to_hash' do + describe '#to_h' do it 'returns hash with correct attributes for crontab' do subject = described_class.from_crontab( '5 * * * *', @@ -54,7 +54,7 @@ timezone: 'Europe/Vienna' ) - hash = subject.to_hash + hash = subject.to_h expect(hash).to eq({ schedule: { type: :crontab, value: '5 * * * *' }, checkin_margin: 10, @@ -72,7 +72,7 @@ timezone: 'Europe/Vienna' ) - hash = subject.to_hash + hash = subject.to_h expect(hash).to eq({ schedule: { type: :interval, value: 5, unit: :hour }, checkin_margin: 10, diff --git a/sentry-ruby/spec/sentry/cron/monitor_schedule_spec.rb b/sentry-ruby/spec/sentry/cron/monitor_schedule_spec.rb index 909a9b4fa..00d259fc6 100644 --- a/sentry-ruby/spec/sentry/cron/monitor_schedule_spec.rb +++ b/sentry-ruby/spec/sentry/cron/monitor_schedule_spec.rb @@ -11,9 +11,9 @@ end end - describe '#to_hash' do + describe '#to_h' do it 'has correct attributes' do - expect(subject.to_hash).to eq({ type: :crontab, value: subject.value }) + expect(subject.to_h).to eq({ type: :crontab, value: subject.value }) end end end @@ -33,9 +33,9 @@ end end - describe '#to_hash' do + describe '#to_h' do it 'has correct attributes' do - expect(subject.to_hash).to eq({ type: :interval, value: subject.value, unit: subject.unit }) + expect(subject.to_h).to eq({ type: :interval, value: subject.value, unit: subject.unit }) end end end diff --git a/sentry-ruby/spec/sentry/event_spec.rb b/sentry-ruby/spec/sentry/event_spec.rb index 90acb4da8..e384f3673 100644 --- a/sentry-ruby/spec/sentry/event_spec.rb +++ b/sentry-ruby/spec/sentry/event_spec.rb @@ -99,14 +99,14 @@ it "filters out pii data" do scope.apply_to_event(event) - expect(event.to_hash[:request]).to eq( + expect(event.to_h[:request]).to eq( env: { 'SERVER_NAME' => 'localhost', 'SERVER_PORT' => '80' }, headers: { 'Host' => 'localhost', 'X-Request-Id' => 'abcd-1234-abcd-1234' }, method: 'POST', url: 'http://localhost/lol', ) - expect(event.to_hash[:tags][:request_id]).to eq("abcd-1234-abcd-1234") - expect(event.to_hash[:user][:ip_address]).to eq(nil) + expect(event.to_h[:tags][:request_id]).to eq("abcd-1234-abcd-1234") + expect(event.to_h[:user][:ip_address]).to eq(nil) end it "removes ip address headers" do @@ -129,7 +129,7 @@ it "adds correct data" do Sentry.get_current_scope.apply_to_event(event) - expect(event.to_hash[:request]).to eq( + expect(event.to_h[:request]).to eq( data: { 'foo' => 'bar' }, env: { 'SERVER_NAME' => 'localhost', 'SERVER_PORT' => '80', "REMOTE_ADDR" => "192.168.1.1" }, headers: { 'Host' => 'localhost', "X-Forwarded-For" => "1.1.1.1, 2.2.2.2", "X-Request-Id" => "abcd-1234-abcd-1234" }, @@ -139,8 +139,8 @@ cookies: {} ) - expect(event.to_hash[:tags][:request_id]).to eq("abcd-1234-abcd-1234") - expect(event.to_hash[:user][:ip_address]).to eq("2.2.2.2") + expect(event.to_h[:tags][:request_id]).to eq("abcd-1234-abcd-1234") + expect(event.to_h[:user][:ip_address]).to eq("2.2.2.2") end it "doesn't overwrite already set ip address" do @@ -157,7 +157,7 @@ it "calculates the correct ip address" do Sentry.get_current_scope.apply_to_event(event) - expect(event.to_hash[:request]).to eq( + expect(event.to_h[:request]).to eq( data: { "foo"=>"bar" }, env: { 'SERVER_NAME' => 'localhost', 'SERVER_PORT' => '80', "REMOTE_ADDR" => "192.168.1.1" }, headers: { 'Host' => 'localhost', "X-Forwarded-For" => "1.1.1.1, 2.2.2.2", "X-Request-Id" => "abcd-1234-abcd-1234" }, @@ -167,8 +167,8 @@ cookies: {} ) - expect(event.to_hash[:tags][:request_id]).to eq("abcd-1234-abcd-1234") - expect(event.to_hash[:user][:ip_address]).to eq("1.1.1.1") + expect(event.to_h[:tags][:request_id]).to eq("abcd-1234-abcd-1234") + expect(event.to_h[:user][:ip_address]).to eq("1.1.1.1") end end end diff --git a/sentry-ruby/spec/sentry/hub_spec.rb b/sentry-ruby/spec/sentry/hub_spec.rb index 735bc6acd..6e296788d 100644 --- a/sentry-ruby/spec/sentry/hub_spec.rb +++ b/sentry-ruby/spec/sentry/hub_spec.rb @@ -149,7 +149,7 @@ it "takes backtrace option" do event = subject.capture_message(message, backtrace: ["#{__FILE__}:10:in `foo'"]) - event_hash = event.to_hash + event_hash = event.to_h expect(event_hash.dig(:threads, :values, 0, :stacktrace, :frames, 0, :function)).to eq("foo") end @@ -161,7 +161,7 @@ it "assigns default backtrace with caller" do event = subject.capture_message(message) - event_hash = event.to_hash + event_hash = event.to_h expect(event_hash.dig(:threads, :values, 0, :stacktrace, :frames, 0, :function)).to eq("
") end @@ -213,7 +213,7 @@ monitor_config: Sentry::Cron::MonitorConfig.from_crontab("* * * * *") ) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event).to include( monitor_slug: slug, status: :ok, diff --git a/sentry-ruby/spec/sentry/interface_spec.rb b/sentry-ruby/spec/sentry/interface_spec.rb index 2d70cdc9b..b99030b81 100644 --- a/sentry-ruby/spec/sentry/interface_spec.rb +++ b/sentry-ruby/spec/sentry/interface_spec.rb @@ -12,6 +12,6 @@ class TestInterface < Sentry::Interface interface = TestInterface.new interface.some_attr = "test" - expect(interface.to_hash).to eq(some_attr: "test") + expect(interface.to_h).to eq(some_attr: "test") end end diff --git a/sentry-ruby/spec/sentry/interfaces/request_interface_spec.rb b/sentry-ruby/spec/sentry/interfaces/request_interface_spec.rb index a7a2225d0..14dde530f 100644 --- a/sentry-ruby/spec/sentry/interfaces/request_interface_spec.rb +++ b/sentry-ruby/spec/sentry/interfaces/request_interface_spec.rb @@ -63,7 +63,7 @@ let(:additional_headers) { { "HTTP_FOO" => "Tekirda\xC4" } } it "doesn't cause any issue" do - json = JSON.generate(subject.to_hash) + json = JSON.generate(subject.to_h) expect(JSON.parse(json)["headers"]).to include("Foo"=>"Tekirda�") end @@ -194,7 +194,7 @@ def to_s env.merge!(::Rack::RACK_INPUT => StringIO.new("あ")) expect do - JSON.generate(subject.to_hash) + JSON.generate(subject.to_h) end.not_to raise_error end diff --git a/sentry-ruby/spec/sentry/metrics/local_aggregator_spec.rb b/sentry-ruby/spec/sentry/metrics/local_aggregator_spec.rb index 3056808da..8f56cf188 100644 --- a/sentry-ruby/spec/sentry/metrics/local_aggregator_spec.rb +++ b/sentry-ruby/spec/sentry/metrics/local_aggregator_spec.rb @@ -39,9 +39,9 @@ end end - describe '#to_hash' do + describe '#to_h' do it 'returns nil if empty buckets' do - expect(subject.to_hash).to eq(nil) + expect(subject.to_h).to eq(nil) end context 'with filled buckets' do @@ -52,28 +52,28 @@ end it 'has the correct payload keys in the hash' do - expect(subject.to_hash.keys).to eq([ + expect(subject.to_h.keys).to eq([ 'c:incr@second', 's:set@none' ]) end it 'has the tags deserialized correctly with array values' do - expect(subject.to_hash['c:incr@second'][:tags]).to eq({ + expect(subject.to_h['c:incr@second'][:tags]).to eq({ 'foo' => [1, 2], 'bar' => 'baz' }) end it 'has the correct gauge metric values' do - expect(subject.to_hash['c:incr@second']).to include({ + expect(subject.to_h['c:incr@second']).to include({ min: 10.0, max: 20.0, count: 2, sum: 30.0 }) - expect(subject.to_hash['s:set@none']).to include({ + expect(subject.to_h['s:set@none']).to include({ min: 1.0, max: 1.0, count: 1, diff --git a/sentry-ruby/spec/sentry/profiler_spec.rb b/sentry-ruby/spec/sentry/profiler_spec.rb index 883fac025..9b64b77dc 100644 --- a/sentry-ruby/spec/sentry/profiler_spec.rb +++ b/sentry-ruby/spec/sentry/profiler_spec.rb @@ -150,25 +150,25 @@ end end - describe '#to_hash' do + describe '#to_h' do let (:transport) { Sentry.get_current_client.transport } context 'when not sampled' do before { subject.set_initial_sample_decision(false) } it 'returns nil' do - expect(subject.to_hash).to eq({}) + expect(subject.to_h).to eq({}) end it 'records lost event' do expect(transport).to receive(:record_lost_event).with(:sample_rate, 'profile') - subject.to_hash + subject.to_h end end it 'returns nil unless started' do subject.set_initial_sample_decision(true) - expect(subject.to_hash).to eq({}) + expect(subject.to_h).to eq({}) end context 'with empty results' do @@ -186,7 +186,7 @@ it 'records lost event' do expect(transport).to receive(:record_lost_event).with(:insufficient_data, 'profile') - subject.to_hash + subject.to_h end end @@ -206,12 +206,12 @@ end it 'returns empty' do - expect(subject.to_hash).to eq({}) + expect(subject.to_h).to eq({}) end it 'records lost event' do expect(transport).to receive(:record_lost_event).with(:insufficient_data, 'profile') - subject.to_hash + subject.to_h end end @@ -224,7 +224,7 @@ end it 'has correct attributes' do - hash = subject.to_hash + hash = subject.to_h expect(hash[:event_id]).to eq(subject.event_id) expect(hash[:platform]).to eq('ruby') @@ -233,7 +233,7 @@ end it 'has correct frames' do - frames = subject.to_hash[:profile][:frames] + frames = subject.to_h[:profile][:frames] foo_frame = frames.find { |f| f[:function] =~ /foo/ } expect(foo_frame[:function]).to eq('Foo.foo') @@ -269,7 +269,7 @@ end it 'has correct stacks' do - profile = subject.to_hash[:profile] + profile = subject.to_h[:profile] frames = profile[:frames] stacks = profile[:stacks] @@ -283,7 +283,7 @@ end it 'has correct samples' do - profile = subject.to_hash[:profile] + profile = subject.to_h[:profile] num_stacks = profile[:stacks].size samples = profile[:samples] last_elapsed = 0 diff --git a/sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb b/sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb index 21e1786ef..ea69c57dc 100644 --- a/sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb +++ b/sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb @@ -19,7 +19,7 @@ expect { stack.call(env) }.to raise_error(ZeroDivisionError) - event = last_sentry_event.to_hash + event = last_sentry_event.to_h expect(event.dig(:request, :url)).to eq("http://example.org/test") expect(env["sentry.error_event_id"]).to eq(event[:event_id]) last_frame = event.dig(:exception, :values, 0, :stacktrace, :frames).last @@ -32,7 +32,7 @@ expect { stack.call(env) }.to raise_error(ZeroDivisionError) - event = last_sentry_event.to_hash + event = last_sentry_event.to_h mechanism = event.dig(:exception, :values, 0, :mechanism) expect(mechanism).to eq({ type: 'rack', handled: false }) end @@ -50,7 +50,7 @@ event = last_sentry_event expect(env["sentry.error_event_id"]).to eq(event.event_id) - expect(event.to_hash.dig(:request, :url)).to eq("http://example.org/test") + expect(event.to_h.dig(:request, :url)).to eq("http://example.org/test") end it 'captures the exception from sinatra.error' do @@ -65,7 +65,7 @@ end.to change { sentry_events.count }.by(1) event = last_sentry_event - expect(event.to_hash.dig(:request, :url)).to eq("http://example.org/test") + expect(event.to_h.dig(:request, :url)).to eq("http://example.org/test") end it 'sets the transaction and rack env' do @@ -79,7 +79,7 @@ event = last_sentry_event expect(event.transaction).to eq("/test") - expect(event.to_hash.dig(:request, :url)).to eq("http://example.org/test") + expect(event.to_h.dig(:request, :url)).to eq("http://example.org/test") expect(Sentry.get_current_scope.transaction_name).to be_nil expect(Sentry.get_current_scope.rack_env).to eq({}) end @@ -116,7 +116,7 @@ expect { stack.call(env) }.to raise_error(ZeroDivisionError) - event = last_sentry_event.to_hash + event = last_sentry_event.to_h expect(event.dig(:request, :url)).to eq("http://example.org/test") last_frame = event.dig(:exception, :values, 0, :stacktrace, :frames).last expect(last_frame[:vars]).to include({ a: "1", b: "0" }) @@ -140,7 +140,7 @@ def inspect expect { stack.call(env) }.to raise_error(ZeroDivisionError) - event = last_sentry_event.to_hash + event = last_sentry_event.to_h expect(event.dig(:request, :url)).to eq("http://example.org/test") last_frame = event.dig(:exception, :values, 0, :stacktrace, :frames).last expect(last_frame[:vars]).to include({ a: "1", b: "0", f: "[ignored due to error]" }) @@ -158,7 +158,7 @@ def inspect expect { stack.call(env) }.to raise_error(ZeroDivisionError) - event = last_sentry_event.to_hash + event = last_sentry_event.to_h expect(event.dig(:request, :url)).to eq("http://example.org/test") last_frame = event.dig(:exception, :values, 0, :stacktrace, :frames).last expect(last_frame[:vars]).to include({ a: "1", b: "0", long: "*" * 1024 + "..." }) diff --git a/sentry-ruby/spec/sentry/scope_spec.rb b/sentry-ruby/spec/sentry/scope_spec.rb index 4bacae275..374f2e30d 100644 --- a/sentry-ruby/spec/sentry/scope_spec.rb +++ b/sentry-ruby/spec/sentry/scope_spec.rb @@ -47,7 +47,7 @@ copy.set_transaction_name("foo", source: :url) copy.fingerprint << "bar" - expect(subject.breadcrumbs.to_hash).to eq({ values: [] }) + expect(subject.breadcrumbs.to_h).to eq({ values: [] }) expect(subject.contexts[:os].keys).to match_array([:name, :version, :build, :kernel_version, :machine]) expect(subject.contexts.dig(:runtime, :version)).to match(/ruby/) expect(subject.extra).to eq({}) @@ -326,7 +326,7 @@ it "sets the request info the Event" do subject.apply_to_event(event) - expect(event.to_hash.dig(:request, :url)).to eq("http://example.org/test") + expect(event.to_h.dig(:request, :url)).to eq("http://example.org/test") end end end diff --git a/sentry-ruby/spec/sentry/span_spec.rb b/sentry-ruby/spec/sentry/span_spec.rb index 0d1fd225c..2e3f8167f 100644 --- a/sentry-ruby/spec/sentry/span_spec.rb +++ b/sentry-ruby/spec/sentry/span_spec.rb @@ -59,14 +59,14 @@ end end - describe "#to_hash" do + describe "#to_h" do before do subject.set_data("controller", "WelcomeController") subject.set_tag("foo", "bar") end it "returns correct data" do - hash = subject.to_hash + hash = subject.to_h expect(hash[:op]).to eq("sql.query") expect(hash[:description]).to eq("SELECT * FROM users;") @@ -82,7 +82,7 @@ key = [:c, 'incr', 'none', []] subject.metrics_local_aggregator.add(key, 10) - hash = subject.to_hash + hash = subject.to_h expect(hash[:_metrics_summary]).to eq({ 'c:incr@none' => { count: 1, max: 10.0, min: 10.0, sum: 10.0, tags: {} } }) diff --git a/sentry-ruby/spec/sentry/transaction_spec.rb b/sentry-ruby/spec/sentry/transaction_spec.rb index 7cc83aa64..cfdced974 100644 --- a/sentry-ruby/spec/sentry/transaction_spec.rb +++ b/sentry-ruby/spec/sentry/transaction_spec.rb @@ -392,9 +392,9 @@ end end - describe "#to_hash" do + describe "#to_h" do it "returns correct data" do - hash = subject.to_hash + hash = subject.to_h expect(hash[:op]).to eq("sql.query") expect(hash[:description]).to eq("SELECT * FROM users;") @@ -421,7 +421,7 @@ subject.finish expect(events.count).to eq(1) - event = events.last.to_hash + event = events.last.to_h # don't contain itself expect(event[:spans]).to be_empty @@ -431,7 +431,7 @@ subject.finish expect(events.count).to eq(1) - event = events.last.to_hash + event = events.last.to_h expect(event[:transaction]).to eq("foo") end @@ -441,7 +441,7 @@ subject.finish(end_timestamp: timestamp) expect(events.count).to eq(1) - event = events.last.to_hash + event = events.last.to_h expect(event[:timestamp]).to eq(timestamp) end @@ -454,7 +454,7 @@ subject.finish expect(events.count).to eq(1) - event = events.last.to_hash + event = events.last.to_h expect(event[:tags]).to eq({ foo: 'bar', name: "apple" }) end @@ -536,7 +536,7 @@ subject.set_measurement("metric.foo", 0.5, "second") subject.finish - transaction = events.last.to_hash + transaction = events.last.to_h expect(transaction[:measurements]).to eq( { "metric.foo" => { value: 0.5, unit: "second" } } ) diff --git a/sentry-ruby/spec/sentry/transport_spec.rb b/sentry-ruby/spec/sentry/transport_spec.rb index 170aef25b..587b626bd 100644 --- a/sentry-ruby/spec/sentry/transport_spec.rb +++ b/sentry-ruby/spec/sentry/transport_spec.rb @@ -56,7 +56,7 @@ '{"type":"event","content_type":"application/json"}' ) - expect(item).to eq(event.to_hash.to_json) + expect(item).to eq(event.to_h.to_json) end end @@ -91,7 +91,7 @@ '{"type":"transaction","content_type":"application/json"}' ) - expect(item).to eq(event.to_hash.to_json) + expect(item).to eq(event.to_h.to_json) end context "with profiling on transaction" do @@ -247,7 +247,7 @@ 1000.times do |i| event.breadcrumbs.record Sentry::Breadcrumb.new(category: i.to_s, message: "x" * Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES) end - serialized_result = JSON.generate(event.to_hash) + serialized_result = JSON.generate(event.to_h) expect(serialized_result.bytesize).to be > Sentry::Envelope::Item::MAX_SERIALIZED_PAYLOAD_SIZE end @@ -300,7 +300,7 @@ ) single_exception.instance_variable_set(:@stacktrace, new_stacktrace) - serialized_result = JSON.generate(event.to_hash) + serialized_result = JSON.generate(event.to_h) expect(serialized_result.bytesize).to be > Sentry::Envelope::Item::MAX_SERIALIZED_PAYLOAD_SIZE end @@ -410,7 +410,7 @@ 1000.times do |i| event.breadcrumbs.record Sentry::Breadcrumb.new(category: i.to_s, message: "x" * Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES) end - serialized_result = JSON.generate(event.to_hash) + serialized_result = JSON.generate(event.to_h) expect(serialized_result.bytesize).to be > Sentry::Envelope::Item::MAX_SERIALIZED_PAYLOAD_SIZE end diff --git a/sentry-ruby/spec/sentry_spec.rb b/sentry-ruby/spec/sentry_spec.rb index dabdcd07e..123f257a3 100644 --- a/sentry-ruby/spec/sentry_spec.rb +++ b/sentry-ruby/spec/sentry_spec.rb @@ -281,7 +281,7 @@ described_class.capture_exception(e) end - event = last_sentry_event.to_hash + event = last_sentry_event.to_h last_frame = event.dig(:exception, :values, 0, :stacktrace, :frames).last expect(last_frame[:vars]).to eq(nil) end @@ -307,7 +307,7 @@ described_class.capture_exception(e) end - event = last_sentry_event.to_hash + event = last_sentry_event.to_h last_frame = event.dig(:exception, :values, 0, :stacktrace, :frames).last expect(last_frame[:vars]).to include({ a: "1", b: "0" }) end diff --git a/sentry-sidekiq/spec/sentry/sidekiq-scheduler/scheduler_spec.rb b/sentry-sidekiq/spec/sentry/sidekiq-scheduler/scheduler_spec.rb index 02efd1ccc..661042fd8 100644 --- a/sentry-sidekiq/spec/sentry/sidekiq-scheduler/scheduler_spec.rb +++ b/sentry-sidekiq/spec/sentry/sidekiq-scheduler/scheduler_spec.rb @@ -57,7 +57,7 @@ expect(EveryHappyWorker.sentry_monitor_slug).to eq('regularly_happy') expect(EveryHappyWorker.sentry_monitor_config).to be_a(Sentry::Cron::MonitorConfig) expect(EveryHappyWorker.sentry_monitor_config.schedule).to be_a(Sentry::Cron::MonitorSchedule::Interval) - expect(EveryHappyWorker.sentry_monitor_config.schedule.to_hash).to eq({ value: 10, type: :interval, unit: :minute }) + expect(EveryHappyWorker.sentry_monitor_config.schedule.to_h).to eq({ value: 10, type: :interval, unit: :minute }) end it "does not add monitors for a one-off job" do diff --git a/sentry-sidekiq/spec/sentry/sidekiq/error_handler_spec.rb b/sentry-sidekiq/spec/sentry/sidekiq/error_handler_spec.rb index 5e144bf9a..517bbeb60 100644 --- a/sentry-sidekiq/spec/sentry/sidekiq/error_handler_spec.rb +++ b/sentry-sidekiq/spec/sentry/sidekiq/error_handler_spec.rb @@ -41,7 +41,7 @@ processor.fire_event(:startup) end - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:exception][:values][0][:type]).to eq("RuntimeError") expect(event[:exception][:values][0][:value]).to match("Uhoh!") expect(event[:transaction]).to eq "Sidekiq/startup" @@ -53,7 +53,7 @@ subject.call(exception, context) expect(transport.events.count).to eq(1) - event = transport.events.first.to_hash + event = transport.events.first.to_h expect(event[:contexts][:sidekiq]).to eq(context) end @@ -69,7 +69,7 @@ subject.call(exception, aj_context) expect(transport.events.count).to eq(1) - event = transport.events.first.to_hash + event = transport.events.first.to_h expect(event[:contexts][:sidekiq]).to eq(expected_context) end @@ -82,7 +82,7 @@ subject.call(exception, context) expect(transport.events.count).to eq(1) - event = transport.events.first.to_hash + event = transport.events.first.to_h expect(event[:transaction]).to eq("Sidekiq/HardWorker") end end diff --git a/sentry-sidekiq/spec/sentry/sidekiq_spec.rb b/sentry-sidekiq/spec/sentry/sidekiq_spec.rb index 4c788c9ce..a455c110c 100644 --- a/sentry-sidekiq/spec/sentry/sidekiq_spec.rb +++ b/sentry-sidekiq/spec/sentry/sidekiq_spec.rb @@ -54,7 +54,7 @@ it "captures exception raised in the worker" do expect { execute_worker(processor, SadWorker) }.to change { transport.events.size }.by(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:sdk]).to eq({ name: "sentry.ruby.sidekiq", version: described_class::VERSION }) expect(event[:exception][:values][0][:type]).to eq("RuntimeError") expect(event[:exception][:values][0][:value]).to match("I'm sad!") @@ -63,7 +63,7 @@ it "doesn't store the private `_config` context", skip: !WITH_SIDEKIQ_7 do expect { execute_worker(processor, SadWorker) }.to change { transport.events.size }.by(1) - event = transport.events.last.to_hash + event = transport.events.last.to_h expect(event[:contexts][:sidekiq].keys.map(&:to_s)).not_to include("_config") end @@ -268,7 +268,7 @@ def retry_last_failed_job first = transport.events[0] check_in_id = first.check_in_id expect(first).to be_a(Sentry::CheckInEvent) - expect(first.to_hash).to include( + expect(first.to_h).to include( type: 'check_in', check_in_id: check_in_id, monitor_slug: "happyworkerwithcron", @@ -277,7 +277,7 @@ def retry_last_failed_job second = transport.events[1] expect(second).to be_a(Sentry::CheckInEvent) - expect(second.to_hash).to include( + expect(second.to_h).to include( :duration, type: 'check_in', check_in_id: check_in_id, @@ -293,7 +293,7 @@ def retry_last_failed_job first = transport.events[0] check_in_id = first.check_in_id expect(first).to be_a(Sentry::CheckInEvent) - expect(first.to_hash).to include( + expect(first.to_h).to include( type: 'check_in', check_in_id: check_in_id, monitor_slug: "failed_job", @@ -303,7 +303,7 @@ def retry_last_failed_job second = transport.events[1] expect(second).to be_a(Sentry::CheckInEvent) - expect(second.to_hash).to include( + expect(second.to_h).to include( :duration, type: 'check_in', check_in_id: check_in_id,