diff --git a/CHANGELOG.md b/CHANGELOG.md index 08776100e..998ee8358 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 ac2d31fb1..0f5bbc1c5 100644 --- a/sentry-delayed_job/spec/sentry/delayed_job_spec.rb +++ b/sentry-delayed_job/spec/sentry/delayed_job_spec.rb @@ -44,7 +44,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 }) @@ -66,7 +66,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 }) @@ -75,7 +75,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 @@ -91,7 +91,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") @@ -107,7 +107,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({}) @@ -121,7 +121,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({}) @@ -226,7 +226,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") @@ -253,7 +253,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 ed43ba7a3..4788d3b31 100644 --- a/sentry-rails/spec/sentry/rails/activejob_spec.rb +++ b/sentry-rails/spec/sentry/rails/activejob_spec.rb @@ -252,7 +252,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") @@ -295,7 +295,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", @@ -304,7 +304,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, @@ -323,7 +323,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", @@ -333,7 +333,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 b156eaf59..12afe6af3 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 @@ -128,7 +128,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 0334531f6..f17bb3076 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 @@ -132,7 +132,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 a751e1366..1db0415a6 100644 --- a/sentry-rails/spec/sentry/rails/controller_methods_spec.rb +++ b/sentry-rails/spec/sentry/rails/controller_methods_spec.rb @@ -35,7 +35,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 @@ -47,8 +47,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 674615f3a..de83bcbdb 100644 --- a/sentry-rails/spec/sentry/rails/event_spec.rb +++ b/sentry-rails/spec/sentry/rails/event_spec.rb @@ -6,7 +6,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 @@ -25,7 +25,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 f147e1b8e..bb1337573 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 @@ -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(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 aa2473312..d803294a1 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 @@ -18,7 +18,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 aa29b82d2..d26bcdb2e 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 @@ -28,7 +28,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) @@ -65,7 +65,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) @@ -84,7 +84,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) @@ -102,7 +102,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) @@ -129,7 +129,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 5d34db1e3..2c0a13cf5 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 @@ -23,7 +23,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 @@ -38,7 +38,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 287bd8acc..f1667a712 100644 --- a/sentry-rails/spec/sentry/rails/tracing_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing_spec.rb @@ -24,8 +24,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)) @@ -62,7 +62,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") @@ -206,7 +206,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 2a4739b6f..efb431852 100644 --- a/sentry-resque/spec/sentry/resque_spec.rb +++ b/sentry-resque/spec/sentry/resque_spec.rb @@ -64,7 +64,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" }) @@ -86,7 +86,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 }) @@ -95,7 +95,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 @@ -107,7 +107,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") @@ -121,7 +121,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({}) @@ -133,7 +133,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({}) @@ -159,7 +159,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") @@ -173,7 +173,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") @@ -199,7 +199,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") @@ -264,7 +264,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") @@ -289,7 +289,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 e77b84f4e..6f73dca87 100644 --- a/sentry-resque/spec/sentry/tracing_spec.rb +++ b/sentry-resque/spec/sentry/tracing_spec.rb @@ -33,10 +33,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") @@ -51,10 +51,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") @@ -76,7 +76,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 7a10872b5..4e76fe473 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 68b8c709c..568f33fb3 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 97777a1c9..d965485cb 100644 --- a/sentry-ruby/lib/sentry/event.rb +++ b/sentry-ruby/lib/sentry/event.rb @@ -115,16 +115,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 66d0b379a..d9409607c 100644 --- a/sentry-ruby/lib/sentry/hub.rb +++ b/sentry-ruby/lib/sentry/hub.rb @@ -83,7 +83,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 d35491206..d00bbfa16 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 eadf01188..19e4b2357 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] @@ -64,7 +64,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 5edac90c5..dfd0db7be 100644 --- a/sentry-ruby/lib/sentry/interfaces/stacktrace_builder.rb +++ b/sentry-ruby/lib/sentry/interfaces/stacktrace_builder.rb @@ -67,7 +67,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 949a9aecb..3ebe0dc83 100644 --- a/sentry-ruby/lib/sentry/profiler.rb +++ b/sentry-ruby/lib/sentry/profiler.rb @@ -73,7 +73,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 061b7b1e0..66f5f0bf0 100644 --- a/sentry-ruby/lib/sentry/span.rb +++ b/sentry-ruby/lib/sentry/span.rb @@ -161,7 +161,7 @@ def to_baggage end # @return [Hash] - def to_hash + def to_h hash = { trace_id: @trace_id, span_id: @span_id, @@ -301,7 +301,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 456b49e74..753bce57d 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 d2e39dc1f..a18d0dec0 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 3b7b7a23d..9f1fb8b50 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 04a76fe3c..bb0ffb629 100644 --- a/sentry-ruby/spec/sentry/breadcrumb_buffer_spec.rb +++ b/sentry-ruby/spec/sentry/breadcrumb_buffer_spec.rb @@ -55,13 +55,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 66c2d1112..564853bf5 100644 --- a/sentry-ruby/spec/sentry/breadcrumb_spec.rb +++ b/sentry-ruby/spec/sentry/breadcrumb_spec.rb @@ -54,7 +54,7 @@ end end - describe "#to_hash" do + describe "#to_h" do let(:problematic_crumb) do # circular reference a = [] @@ -70,7 +70,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") @@ -78,7 +78,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 bd1debcf2..89e5bf68f 100644 --- a/sentry-ruby/spec/sentry/client_spec.rb +++ b/sentry-ruby/spec/sentry/client_spec.rb @@ -179,7 +179,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) @@ -195,7 +195,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) @@ -223,7 +223,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) @@ -278,7 +278,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: {} } @@ -290,7 +290,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") @@ -339,7 +339,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) expect(hash[:exception][:values][0][:value]).to eq("{:foo=>\"bar\"}") end @@ -355,7 +355,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) @@ -376,7 +376,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 @@ -576,7 +576,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 @@ -654,7 +654,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 @@ -669,7 +669,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) @@ -686,7 +686,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") @@ -705,7 +705,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 68bbbe95a..e591acd5a 100644 --- a/sentry-ruby/spec/sentry/cron/monitor_config_spec.rb +++ b/sentry-ruby/spec/sentry/cron/monitor_config_spec.rb @@ -43,7 +43,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 * * * *', @@ -52,7 +52,7 @@ timezone: 'Europe/Vienna' ) - hash = subject.to_hash + hash = subject.to_h expect(hash).to eq({ schedule: { type: :crontab, value: '5 * * * *' }, checkin_margin: 10, @@ -70,7 +70,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 8e1b422d1..61ea9b3e9 100644 --- a/sentry-ruby/spec/sentry/cron/monitor_schedule_spec.rb +++ b/sentry-ruby/spec/sentry/cron/monitor_schedule_spec.rb @@ -9,9 +9,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 @@ -31,9 +31,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 a5ca457e7..560a06f14 100644 --- a/sentry-ruby/spec/sentry/event_spec.rb +++ b/sentry-ruby/spec/sentry/event_spec.rb @@ -97,14 +97,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 @@ -127,7 +127,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" }, @@ -137,8 +137,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 context "with config.trusted_proxies = [\"2.2.2.2\"]" do @@ -149,7 +149,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" }, @@ -159,8 +159,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 6d06595aa..4fd655294 100644 --- a/sentry-ruby/spec/sentry/hub_spec.rb +++ b/sentry-ruby/spec/sentry/hub_spec.rb @@ -147,7 +147,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 @@ -159,7 +159,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 @@ -211,7 +211,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 7d95d5263..2ce477898 100644 --- a/sentry-ruby/spec/sentry/interface_spec.rb +++ b/sentry-ruby/spec/sentry/interface_spec.rb @@ -10,6 +10,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 580a610d3..827f02d16 100644 --- a/sentry-ruby/spec/sentry/interfaces/request_interface_spec.rb +++ b/sentry-ruby/spec/sentry/interfaces/request_interface_spec.rb @@ -61,7 +61,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 @@ -192,7 +192,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 5c5ab0583..893f07be7 100644 --- a/sentry-ruby/spec/sentry/metrics/local_aggregator_spec.rb +++ b/sentry-ruby/spec/sentry/metrics/local_aggregator_spec.rb @@ -37,9 +37,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 @@ -50,28 +50,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 215e739be..ec7aa166d 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 @@ -180,12 +180,12 @@ it 'returns empty' do expect(StackProf).to receive(:results).and_call_original - 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 @@ -205,12 +205,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 @@ -223,7 +223,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') @@ -232,7 +232,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') @@ -268,7 +268,7 @@ end it 'has correct stacks' do - profile = subject.to_hash[:profile] + profile = subject.to_h[:profile] frames = profile[:frames] stacks = profile[:stacks] @@ -282,7 +282,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 e03984cdf..8cbd68178 100644 --- a/sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb +++ b/sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb @@ -18,7 +18,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 @@ -31,7 +31,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 @@ -49,7 +49,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 @@ -64,7 +64,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 @@ -78,7 +78,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 @@ -115,7 +115,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" }) @@ -139,7 +139,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]" }) @@ -157,7 +157,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 651c995d1..634e9d19a 100644 --- a/sentry-ruby/spec/sentry/scope_spec.rb +++ b/sentry-ruby/spec/sentry/scope_spec.rb @@ -45,7 +45,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({}) @@ -318,7 +318,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 0bc187eec..cd199c8b8 100644 --- a/sentry-ruby/spec/sentry/span_spec.rb +++ b/sentry-ruby/spec/sentry/span_spec.rb @@ -54,14 +54,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;") @@ -77,7 +77,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 6dafc1371..0cfa754fd 100644 --- a/sentry-ruby/spec/sentry/transaction_spec.rb +++ b/sentry-ruby/spec/sentry/transaction_spec.rb @@ -390,9 +390,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;") @@ -419,7 +419,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 @@ -429,7 +429,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 @@ -439,7 +439,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 @@ -452,7 +452,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 @@ -532,7 +532,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 2a61109a1..bedb10ac3 100644 --- a/sentry-ruby/spec/sentry/transport_spec.rb +++ b/sentry-ruby/spec/sentry/transport_spec.rb @@ -54,7 +54,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 @@ -89,7 +89,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 @@ -212,7 +212,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 @@ -265,7 +265,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 @@ -375,7 +375,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 0e30d150e..7ecfad0b0 100644 --- a/sentry-ruby/spec/sentry_spec.rb +++ b/sentry-ruby/spec/sentry_spec.rb @@ -279,7 +279,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 @@ -305,7 +305,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 879e34a55..e8db5ca06 100644 --- a/sentry-sidekiq/spec/sentry/sidekiq-scheduler/scheduler_spec.rb +++ b/sentry-sidekiq/spec/sentry/sidekiq-scheduler/scheduler_spec.rb @@ -55,7 +55,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 15053609e..62dfaf78b 100644 --- a/sentry-sidekiq/spec/sentry/sidekiq/error_handler_spec.rb +++ b/sentry-sidekiq/spec/sentry/sidekiq/error_handler_spec.rb @@ -39,7 +39,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" @@ -51,7 +51,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 @@ -67,7 +67,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 @@ -80,7 +80,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 2e7cfb99a..8d430ffff 100644 --- a/sentry-sidekiq/spec/sentry/sidekiq_spec.rb +++ b/sentry-sidekiq/spec/sentry/sidekiq_spec.rb @@ -52,7 +52,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!") @@ -61,7 +61,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 @@ -266,7 +266,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", @@ -275,7 +275,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, @@ -291,7 +291,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", @@ -301,7 +301,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,