From 52032f3ce9358652224bf38e689754d1568e1809 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Fri, 26 Apr 2024 20:04:34 +0800 Subject: [PATCH 1/4] Drop `async` configuration (#1894) --- CHANGELOG.md | 6 + sentry-rails/lib/sentry/rails/active_job.rb | 18 +-- .../spec/sentry/rails/activejob_spec.rb | 44 ------ .../spec/sentry/send_event_job_spec.rb | 105 ------------- sentry-ruby/examples/crons/README.md | 2 +- sentry-ruby/lib/sentry/background_worker.rb | 5 +- sentry-ruby/lib/sentry/client.rb | 37 +---- sentry-ruby/lib/sentry/configuration.rb | 24 --- sentry-ruby/lib/sentry/transport.rb | 5 +- .../spec/sentry/background_worker_spec.rb | 16 -- .../spec/sentry/client/event_sending_spec.rb | 142 +----------------- sentry-ruby/spec/sentry/configuration_spec.rb | 13 -- .../http_transport_rate_limiting_spec.rb | 2 +- .../sentry/transport/http_transport_spec.rb | 2 +- .../transport/spotlight_transport_spec.rb | 2 +- sentry-ruby/spec/sentry/transport_spec.rb | 18 --- 16 files changed, 28 insertions(+), 413 deletions(-) delete mode 100644 sentry-rails/spec/sentry/send_event_job_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d2360ffd..da6450a14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased (6.0.0) + +### Breaking Changes + +- Remove `config.async` [#1894](https://github.com/getsentry/sentry-ruby/pull/1894) + ## Unreleased ### Features diff --git a/sentry-rails/lib/sentry/rails/active_job.rb b/sentry-rails/lib/sentry/rails/active_job.rb index 953af632b..994a394ce 100644 --- a/sentry-rails/lib/sentry/rails/active_job.rb +++ b/sentry-rails/lib/sentry/rails/active_job.rb @@ -26,17 +26,13 @@ def record(job, &block) Sentry.with_scope do |scope| begin scope.set_transaction_name(job.class.name, source: :task) - transaction = - if job.is_a?(::Sentry::SendEventJob) - nil - else - Sentry.start_transaction( - name: scope.transaction_name, - source: scope.transaction_source, - op: OP_NAME, - origin: SPAN_ORIGIN - ) - end + + transaction = Sentry.start_transaction( + name: scope.transaction_name, + source: scope.transaction_source, + op: OP_NAME, + origin: SPAN_ORIGIN + ) scope.set_span(transaction) if transaction diff --git a/sentry-rails/spec/sentry/rails/activejob_spec.rb b/sentry-rails/spec/sentry/rails/activejob_spec.rb index cf986d937..380230605 100644 --- a/sentry-rails/spec/sentry/rails/activejob_spec.rb +++ b/sentry-rails/spec/sentry/rails/activejob_spec.rb @@ -234,50 +234,6 @@ def perform event = transport.events.last.to_json_compatible expect(event.dig("exception", "values", 0, "type")).to eq("ZeroDivisionError") end - - context "and in user-defined reporting job too" do - before do - Sentry.configuration.async = lambda do |event, hint| - UserDefinedReportingJob.perform_now(event, hint) - end - end - - class UserDefinedReportingJob < ActiveJob::Base - def perform(event, hint) - Post.find(0) - rescue - raise ActiveJob::DeserializationError - end - end - - it "doesn't cause infinite loop because of excluded exceptions" do - expect do - DeserializationErrorJob.perform_now - end.to raise_error(ActiveJob::DeserializationError, /divided by 0/) - end - end - - context "and in customized SentryJob too" do - before do - class CustomSentryJob < ::Sentry::SendEventJob - def perform(event, hint) - raise "Not excluded exception" - rescue - raise ActiveJob::DeserializationError - end - end - - Sentry.configuration.async = lambda do |event, hint| - CustomSentryJob.perform_now(event, hint) - end - end - - it "doesn't cause infinite loop" do - expect do - DeserializationErrorJob.perform_now - end.to raise_error(ActiveJob::DeserializationError, /divided by 0/) - end - end end context 'using rescue_from' do diff --git a/sentry-rails/spec/sentry/send_event_job_spec.rb b/sentry-rails/spec/sentry/send_event_job_spec.rb deleted file mode 100644 index 00f89b2ed..000000000 --- a/sentry-rails/spec/sentry/send_event_job_spec.rb +++ /dev/null @@ -1,105 +0,0 @@ -# frozen_string_literal: true - -require "active_job" -require "spec_helper" - -RSpec.describe "Sentry::SendEventJob" do - let(:event) do - Sentry.get_current_client.event_from_message("test message") - end - let(:transport) do - Sentry.get_current_client.transport - end - - context "when ActiveJob is not loaded" do - before do - TempActiveJob = ActiveJob - Object.send(:remove_const, "ActiveJob") - reload_send_event_job - end - - after do - ActiveJob = TempActiveJob - reload_send_event_job - end - - it "gets defined as a blank class" do - expect(Sentry::SendEventJob.superclass).to eq(Object) - end - end - - context "when ActiveJob is loaded" do - after do - reload_send_event_job - end - - it "reports events to Sentry" do - make_basic_app - - Sentry.configuration.before_send = lambda do |event, hint| - event.tags[:hint] = hint - event - end - - Sentry::SendEventJob.perform_now(event, { foo: "bar" }) - - expect(transport.events.count).to eq(1) - event = transport.events.first - expect(event.message).to eq("test message") - expect(event.tags[:hint][:foo]).to eq("bar") - end - - it "doesn't create a new transaction" do - make_basic_app do |config| - config.traces_sample_rate = 1.0 - end - - Sentry::SendEventJob.perform_now(event) - - expect(transport.events.count).to eq(1) - event = transport.events.first - expect(event.type).to eq("event") - end - - context "when ApplicationJob is not defined" do - before do - make_basic_app - end - it "uses ActiveJob::Base as the parent class" do - expect(Sentry::SendEventJob.superclass).to eq(ActiveJob::Base) - end - end - - context "when ApplicationJob is defined" do - before do - class ApplicationJob < ActiveJob::Base; end - reload_send_event_job - make_basic_app - end - - after do - Object.send(:remove_const, "ApplicationJob") - end - - it "uses ApplicationJob as the parent class" do - expect(Sentry::SendEventJob.superclass).to eq(ApplicationJob) - end - end - - context "when ApplicationJob is defined but it's something else" do - before do - class ApplicationJob; end - reload_send_event_job - make_basic_app - end - - after do - Object.send(:remove_const, "ApplicationJob") - end - - it "uses ActiveJob::Base as the parent class" do - expect(Sentry::SendEventJob.superclass).to eq(ActiveJob::Base) - end - end - end -end diff --git a/sentry-ruby/examples/crons/README.md b/sentry-ruby/examples/crons/README.md index 7430bde64..ec2951b36 100644 --- a/sentry-ruby/examples/crons/README.md +++ b/sentry-ruby/examples/crons/README.md @@ -1,7 +1,7 @@ # sentry-ruby Crons example Crons monitoring allows you to track that certain that should be performed -on a certain schedule are indeed performed on time and without errors. See +on a certain schedule are indeed performed on time and without errors. See [documentation](https://docs.sentry.io/platforms/ruby/crons/) for more details. This example project has a few rake tasks that manually send monitor check-ins diff --git a/sentry-ruby/lib/sentry/background_worker.rb b/sentry-ruby/lib/sentry/background_worker.rb index ee5b94305..1ee429d76 100644 --- a/sentry-ruby/lib/sentry/background_worker.rb +++ b/sentry-ruby/lib/sentry/background_worker.rb @@ -24,10 +24,7 @@ def initialize(configuration) @shutdown_callback = nil @executor = - if configuration.async - log_debug("config.async is set, BackgroundWorker is disabled") - Concurrent::ImmediateExecutor.new - elsif @number_of_threads == 0 + if @number_of_threads == 0 log_debug("config.background_worker_threads is set to 0, all events will be sent synchronously") Concurrent::ImmediateExecutor.new else diff --git a/sentry-ruby/lib/sentry/client.rb b/sentry-ruby/lib/sentry/client.rb index 9d48ee301..d60a1c214 100644 --- a/sentry-ruby/lib/sentry/client.rb +++ b/sentry-ruby/lib/sentry/client.rb @@ -53,8 +53,7 @@ def capture_event(event, scope, hint = {}) return end - event_type = event.is_a?(Event) ? event.type : event["type"] - data_category = Envelope::Item.data_category(event_type) + data_category = Envelope::Item.data_category(event.type) is_transaction = event.is_a?(TransactionEvent) spans_before = is_transaction ? event.spans.size : 0 @@ -71,9 +70,7 @@ def capture_event(event, scope, hint = {}) transport.record_lost_event(:event_processor, "span", num: spans_delta) if spans_delta > 0 end - if async_block = configuration.async - dispatch_async_event(async_block, event, hint) - elsif configuration.background_worker_threads != 0 && hint.fetch(:background, true) + if configuration.background_worker_threads != 0 && hint.fetch(:background, true) unless dispatch_background_event(event, hint) transport.record_lost_event(:queue_overflow, data_category) transport.record_lost_event(:queue_overflow, "span", num: spans_before + 1) if is_transaction @@ -176,11 +173,10 @@ def event_from_transaction(transaction) # @!macro send_event def send_event(event, hint = nil) - event_type = event.is_a?(Event) ? event.type : event["type"] - data_category = Envelope::Item.data_category(event_type) + data_category = Envelope::Item.data_category(event.type) spans_before = event.is_a?(TransactionEvent) ? event.spans.size : 0 - if event_type != TransactionEvent::TYPE && configuration.before_send + if event.type != TransactionEvent::TYPE && configuration.before_send event = configuration.before_send.call(event, hint) if event.nil? @@ -190,7 +186,7 @@ def send_event(event, hint = nil) end end - if event_type == TransactionEvent::TYPE && configuration.before_send_transaction + if event.type == TransactionEvent::TYPE && configuration.before_send_transaction event = configuration.before_send_transaction.call(event, hint) if event.nil? @@ -271,28 +267,5 @@ def dispatch_background_event(event, hint) send_event(event, hint) end end - - def dispatch_async_event(async_block, event, hint) - # We have to convert to a JSON-like hash, because background job - # processors (esp ActiveJob) may not like weird types in the event hash - - event_hash = - begin - event.to_json_compatible - rescue => e - log_error("Converting #{event.type} (#{event.event_id}) to JSON compatible hash failed", e, debug: configuration.debug) - return - end - - if async_block.arity == 2 - hint = JSON.parse(JSON.generate(hint)) - async_block.call(event_hash, hint) - else - async_block.call(event_hash) - end - rescue => e - log_error("Async #{event_hash["type"]} sending failed", e, debug: configuration.debug) - send_event(event, hint) - end end end diff --git a/sentry-ruby/lib/sentry/configuration.rb b/sentry-ruby/lib/sentry/configuration.rb index b13c81c49..53231134d 100644 --- a/sentry-ruby/lib/sentry/configuration.rb +++ b/sentry-ruby/lib/sentry/configuration.rb @@ -28,13 +28,6 @@ class Configuration # @return [Regexp, nil] attr_accessor :app_dirs_pattern - # Provide an object that responds to `call` to send events asynchronously. - # E.g.: lambda { |event| Thread.new { Sentry.send_event(event) } } - # - # @deprecated It will be removed in the next major release. Please read https://github.com/getsentry/sentry-ruby/issues/1522 for more information - # @return [Proc, nil] - attr_reader :async - # to send events in a non-blocking way, sentry-ruby has its own background worker # by default, the worker holds a thread pool that has [the number of processors] threads # but you can configure it with this configuration option @@ -76,7 +69,6 @@ class Configuration # @example # config.before_send = lambda do |event, hint| # # skip ZeroDivisionError exceptions - # # note: hint[:exception] would be a String if you use async callback # if hint[:exception].is_a?(ZeroDivisionError) # nil # else @@ -429,22 +421,6 @@ def release=(value) @release = value end - def async=(value) - check_callable!("async", value) - - log_warn <<~MSG - - sentry-ruby now sends events asynchronously by default with its background worker (supported since 4.1.0). - The `config.async` callback has become redundant while continuing to cause issues. - (The problems of `async` are detailed in https://github.com/getsentry/sentry-ruby/issues/1522) - - Therefore, we encourage you to remove it and let the background worker take care of async job sending. - It's deprecation is planned in the next major release (6.0), which is scheduled around the 3rd quarter of 2022. - MSG - - @async = value - end - def breadcrumbs_logger=(logger) loggers = if logger.is_a?(Array) diff --git a/sentry-ruby/lib/sentry/transport.rb b/sentry-ruby/lib/sentry/transport.rb index d446387f2..406d5101b 100644 --- a/sentry-ruby/lib/sentry/transport.rb +++ b/sentry-ruby/lib/sentry/transport.rb @@ -127,10 +127,7 @@ def envelope_from_event(event) sent_at: Sentry.utc_now.iso8601 } - if event.is_a?(Event) && event.dynamic_sampling_context - envelope_headers[:trace] = event.dynamic_sampling_context - end - + envelope_headers[:trace] = event.dynamic_sampling_context if event.dynamic_sampling_context envelope = Envelope.new(envelope_headers) envelope.add_item( diff --git a/sentry-ruby/spec/sentry/background_worker_spec.rb b/sentry-ruby/spec/sentry/background_worker_spec.rb index 9e15b43ec..d5b28b905 100644 --- a/sentry-ruby/spec/sentry/background_worker_spec.rb +++ b/sentry-ruby/spec/sentry/background_worker_spec.rb @@ -12,22 +12,6 @@ end describe "#initialize" do - context "when config.async is set" do - before do - configuration.async = proc { } - end - - it "initializes a background_worker with ImmediateExecutor" do - worker = described_class.new(configuration) - - expect(string_io.string).to match( - /config.async is set, BackgroundWorker is disabled/ - ) - - expect(worker.instance_variable_get(:@executor)).to be_a(Concurrent::ImmediateExecutor) - end - end - context "when config.background_worker_threads is set" do it "initializes a background worker with correct number of threads and queue size" do configuration.background_worker_threads = 4 diff --git a/sentry-ruby/spec/sentry/client/event_sending_spec.rb b/sentry-ruby/spec/sentry/client/event_sending_spec.rb index 86b4b6c67..222ee3a7b 100644 --- a/sentry-ruby/spec/sentry/client/event_sending_spec.rb +++ b/sentry-ruby/spec/sentry/client/event_sending_spec.rb @@ -58,84 +58,6 @@ end end - context 'with config.async set' do - let(:async_block) do - lambda do |event| - client.send_event(event) - end - end - - around do |example| - prior_async = configuration.async - configuration.async = async_block - example.run - configuration.async = prior_async - end - - it "executes the given block" do - expect(async_block).to receive(:call).and_call_original - - returned = client.capture_event(event, scope) - - expect(returned).to be_a(Sentry::ErrorEvent) - expect(client.transport.events.first).to eq(event.to_json_compatible) - end - - it "doesn't call the async block if not allow sending events" do - allow(configuration).to receive(:sending_allowed?).and_return(false) - - expect(async_block).not_to receive(:call) - - returned = client.capture_event(event, scope) - - expect(returned).to eq(nil) - end - - context "with to json conversion failed" do - let(:logger) { ::Logger.new(string_io) } - let(:string_io) { StringIO.new } - let(:event) { client.event_from_message("Bad data '\x80\xF8'") } - - it "does not mask the exception" do - configuration.logger = logger - - client.capture_event(event, scope) - - expect(string_io.string).to include("Converting event (#{event.event_id}) to JSON compatible hash failed: source sequence is illegal/malformed utf-8") - end - end - - context "with nil as value (the legacy way to disable it)" do - let(:async_block) { nil } - - it "doesn't cause any issue" do - returned = client.capture_event(event, scope, { background: false }) - - expect(returned).to be_a(Sentry::ErrorEvent) - expect(client.transport.events.first).to eq(event) - end - end - - context "with 2 arity block" do - let(:async_block) do - lambda do |event, hint| - event["tags"]["hint"] = hint - client.send_event(event) - end - end - - it "serializes hint and supplies it as the second argument" do - expect(configuration.async).to receive(:call).and_call_original - - returned = client.capture_event(event, scope, { foo: "bar" }) - - expect(returned).to be_a(Sentry::ErrorEvent) - event = client.transport.events.first - expect(event.dig("tags", "hint")).to eq({ "foo" => "bar" }) - end - end - end - context "with background_worker enabled (default)" do before do Sentry.background_worker = Sentry::BackgroundWorker.new(configuration) @@ -222,22 +144,12 @@ it "applies before_send callback before sending the event" do configuration.before_send = lambda do |event, _hint| - if event.is_a?(Sentry::Event) - event.tags[:called] = true - else - event["tags"]["called"] = true - end - + event.tags[:called] = true event end client.send_event(event) - - if event.is_a?(Sentry::Event) - expect(event.tags[:called]).to eq(true) - else - expect(event["tags"]["called"]).to eq(true) - end + expect(event.tags[:called]).to eq(true) end it "doesn't apply before_send_transaction to Event" do @@ -254,10 +166,6 @@ let(:event) { event_object } end - it_behaves_like "Event in send_event" do - let(:event) { event_object.to_json_compatible } - end - shared_examples "TransactionEvent in send_event" do it "sends data through the transport" do client.send_event(event) @@ -273,32 +181,18 @@ it "applies before_send_transaction callback before sending the event" do configuration.before_send_transaction = lambda do |event, _hint| - if event.is_a?(Sentry::TransactionEvent) - event.tags[:called] = true - else - event["tags"]["called"] = true - end - + event.tags[:called] = true event end client.send_event(event) - - if event.is_a?(Sentry::Event) - expect(event.tags[:called]).to eq(true) - else - expect(event["tags"]["called"]).to eq(true) - end + expect(event.tags[:called]).to eq(true) end end it_behaves_like "TransactionEvent in send_event" do let(:event) { transaction_event } end - - it_behaves_like "TransactionEvent in send_event" do - let(:event) { transaction_event.to_json_compatible } - end end describe "integrated error handling testing with HTTPTransport" do @@ -318,12 +212,6 @@ let(:event) { client.event_from_message(message) } describe "#capture_event" do - around do |example| - prior_async = configuration.async - example.run - configuration.async = prior_async - end - context "when scope.apply_to_event returns nil" do before do scope.add_event_processor do |event, hint| @@ -457,28 +345,6 @@ expect(client.transport).to have_recorded_lost_event(:network_error, 'span', num: 6) end end - - context "when config.async causes error" do - before do - expect(client).to receive(:send_event) - end - - it "swallows Redis related error and send the event synchronizely" do - configuration.async = ->(_, _) { raise Redis::ConnectionError } - - client.capture_event(event, scope) - - expect(string_io.string).to match(/Async event sending failed: Redis::ConnectionError/) - end - - it "swallows and logs the exception" do - configuration.async = ->(_, _) { raise TypeError } - - client.capture_event(event, scope) - - expect(string_io.string).to match(/Async event sending failed: TypeError/) - end - end end describe "#send_event" do diff --git a/sentry-ruby/spec/sentry/configuration_spec.rb b/sentry-ruby/spec/sentry/configuration_spec.rb index afd78625b..7102d8685 100644 --- a/sentry-ruby/spec/sentry/configuration_spec.rb +++ b/sentry-ruby/spec/sentry/configuration_spec.rb @@ -361,24 +361,11 @@ end end - context 'configuring for async' do - it 'should be configurable to send events async' do - subject.async = ->(_e) { :ok } - expect(subject.async.call('event')).to eq(:ok) - end - end - it 'raises error when setting release to anything other than String' do subject.release = "foo" expect { subject.release = 42 }.to raise_error(ArgumentError, "expect the argument to be a String or NilClass, got Integer (42)") end - it 'raises error when setting async to anything other than callable or nil' do - subject.async = -> { } - subject.async = nil - expect { subject.async = true }.to raise_error(ArgumentError, "async must be callable (or nil to disable)") - end - it 'raises error when setting before_send to anything other than callable or nil' do subject.before_send = -> { } subject.before_send = nil diff --git a/sentry-ruby/spec/sentry/transport/http_transport_rate_limiting_spec.rb b/sentry-ruby/spec/sentry/transport/http_transport_rate_limiting_spec.rb index 30dc42bbb..adba3ca82 100644 --- a/sentry-ruby/spec/sentry/transport/http_transport_rate_limiting_spec.rb +++ b/sentry-ruby/spec/sentry/transport/http_transport_rate_limiting_spec.rb @@ -16,7 +16,7 @@ let(:configuration) { Sentry.configuration } let(:client) { Sentry.get_current_client } let(:data) do - subject.envelope_from_event(client.event_from_message("foobarbaz").to_hash).to_s + subject.envelope_from_event(client.event_from_message("foobarbaz")).to_s end subject { Sentry::HTTPTransport.new(configuration) } diff --git a/sentry-ruby/spec/sentry/transport/http_transport_spec.rb b/sentry-ruby/spec/sentry/transport/http_transport_spec.rb index a0973ef75..a517b2a39 100644 --- a/sentry-ruby/spec/sentry/transport/http_transport_spec.rb +++ b/sentry-ruby/spec/sentry/transport/http_transport_spec.rb @@ -16,7 +16,7 @@ let(:event) { client.event_from_message("foobarbaz") } let(:fake_time) { Time.now } let(:data) do - subject.serialize_envelope(subject.envelope_from_event(event.to_hash)).first + subject.serialize_envelope(subject.envelope_from_event(event)).first end subject { client.transport } diff --git a/sentry-ruby/spec/sentry/transport/spotlight_transport_spec.rb b/sentry-ruby/spec/sentry/transport/spotlight_transport_spec.rb index fc095efeb..c5f034c97 100644 --- a/sentry-ruby/spec/sentry/transport/spotlight_transport_spec.rb +++ b/sentry-ruby/spec/sentry/transport/spotlight_transport_spec.rb @@ -20,7 +20,7 @@ let(:client) { Sentry::Client.new(configuration) } let(:event) { client.event_from_message("foobarbaz") } let(:data) do - subject.serialize_envelope(subject.envelope_from_event(event.to_hash)).first + subject.serialize_envelope(subject.envelope_from_event(event)).first end subject { described_class.new(configuration) } diff --git a/sentry-ruby/spec/sentry/transport_spec.rb b/sentry-ruby/spec/sentry/transport_spec.rb index 059a8109b..170aef25b 100644 --- a/sentry-ruby/spec/sentry/transport_spec.rb +++ b/sentry-ruby/spec/sentry/transport_spec.rb @@ -422,18 +422,6 @@ expect(io.string).to match(/Sending envelope with items \[event\]/) end - context "when the event hash has string keys" do - let(:envelope) { subject.envelope_from_event(event.to_json_compatible) } - - it "deletes the event's breadcrumbs and sends it" do - expect(subject).to receive(:send_data) - - subject.send_envelope(envelope) - - expect(io.string).to match(/Sending envelope with items \[event\]/) - end - end - context "if it's still oversized" do before do 1000.times do |i| @@ -503,12 +491,6 @@ expect(subject.send_event(event)).to eq(event) end - it "sends Event hash" do - expect(subject).not_to receive(:failed_send) - - expect(subject.send_event(event.to_json_compatible)).to eq(event.to_json_compatible) - end - it "logs correct message" do expect(subject.send_event(event)).to eq(event) From d7522f9883aeabc34375c2794429ef7a2990cfa9 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Mon, 29 Jul 2024 13:33:44 +0100 Subject: [PATCH 2/4] Migrate from to_hash to to_h (#2351) * Migrate from to_hash to to_h As @solnic pointed out in https://github.com/getsentry/sentry-ruby/pull/2350#discussion_r1686820195 `to_hash` has special meaning in Ruby and could be called implicitly in contexts like double splatting argument. So we should switch to `to_h` to avoid potential issues. --- CHANGELOG.md | 1 + .../spec/sentry/delayed_job_spec.rb | 16 ++++++------ .../spec/sentry/rails/activejob_spec.rb | 10 +++---- .../breadcrumbs/active_support_logger_spec.rb | 2 +- .../monotonic_active_support_logger_spec.rb | 2 +- .../sentry/rails/controller_methods_spec.rb | 6 ++--- sentry-rails/spec/sentry/rails/event_spec.rb | 4 +-- .../action_controller_subscriber_spec.rb | 2 +- .../tracing/action_view_subscriber_spec.rb | 2 +- .../tracing/active_record_subscriber_spec.rb | 10 +++---- .../tracing/active_storage_subscriber_spec.rb | 4 +-- .../spec/sentry/rails/tracing_spec.rb | 8 +++--- sentry-resque/spec/sentry/resque_spec.rb | 22 ++++++++-------- sentry-resque/spec/sentry/tracing_spec.rb | 10 +++---- sentry-ruby/lib/sentry/breadcrumb.rb | 2 +- sentry-ruby/lib/sentry/breadcrumb_buffer.rb | 4 +-- sentry-ruby/lib/sentry/check_in_event.rb | 4 +-- sentry-ruby/lib/sentry/cron/monitor_config.rb | 4 +-- .../lib/sentry/cron/monitor_schedule.rb | 4 +-- sentry-ruby/lib/sentry/error_event.rb | 6 ++--- sentry-ruby/lib/sentry/event.rb | 8 +++--- sentry-ruby/lib/sentry/hub.rb | 2 +- sentry-ruby/lib/sentry/interface.rb | 2 +- .../lib/sentry/interfaces/exception.rb | 4 +-- .../lib/sentry/interfaces/single_exception.rb | 6 ++--- .../lib/sentry/interfaces/stacktrace.rb | 6 ++--- .../sentry/interfaces/stacktrace_builder.rb | 2 +- sentry-ruby/lib/sentry/interfaces/threads.rb | 4 +-- .../lib/sentry/metrics/local_aggregator.rb | 2 +- sentry-ruby/lib/sentry/profiler.rb | 2 +- sentry-ruby/lib/sentry/span.rb | 4 +-- sentry-ruby/lib/sentry/transaction.rb | 2 +- sentry-ruby/lib/sentry/transaction_event.rb | 8 +++--- sentry-ruby/lib/sentry/transport.rb | 2 +- .../spec/sentry/breadcrumb_buffer_spec.rb | 4 +-- sentry-ruby/spec/sentry/breadcrumb_spec.rb | 6 ++--- sentry-ruby/spec/sentry/client_spec.rb | 26 +++++++++---------- .../spec/sentry/cron/monitor_config_spec.rb | 6 ++--- .../spec/sentry/cron/monitor_schedule_spec.rb | 8 +++--- sentry-ruby/spec/sentry/event_spec.rb | 18 ++++++------- sentry-ruby/spec/sentry/hub_spec.rb | 6 ++--- sentry-ruby/spec/sentry/interface_spec.rb | 2 +- .../interfaces/request_interface_spec.rb | 4 +-- .../sentry/metrics/local_aggregator_spec.rb | 12 ++++----- sentry-ruby/spec/sentry/profiler_spec.rb | 22 ++++++++-------- .../sentry/rack/capture_exceptions_spec.rb | 16 ++++++------ sentry-ruby/spec/sentry/scope_spec.rb | 4 +-- sentry-ruby/spec/sentry/span_spec.rb | 6 ++--- sentry-ruby/spec/sentry/transaction_spec.rb | 14 +++++----- sentry-ruby/spec/sentry/transport_spec.rb | 10 +++---- sentry-ruby/spec/sentry_spec.rb | 4 +-- .../sidekiq-scheduler/scheduler_spec.rb | 2 +- .../spec/sentry/sidekiq/error_handler_spec.rb | 8 +++--- sentry-sidekiq/spec/sentry/sidekiq_spec.rb | 12 ++++----- 54 files changed, 184 insertions(+), 183 deletions(-) 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, From 7d6edaf3a9887cf4ca8c8b209e557e1bf2646b19 Mon Sep 17 00:00:00 2001 From: Neel Shah Date: Thu, 31 Oct 2024 14:36:13 +0100 Subject: [PATCH 3/4] Fix specs after rebase --- .../tracing/active_support_subscriber_spec.rb | 16 +++++++------- .../spec/sentry/rails/tracing_spec.rb | 4 ++-- sentry-ruby/lib/sentry/rspec.rb | 2 +- sentry-ruby/lib/sentry/vernier/profiler.rb | 2 +- sentry-ruby/spec/sentry/event_spec.rb | 2 +- sentry-ruby/spec/sentry/profiler_spec.rb | 2 +- .../spec/sentry/vernier/profiler_spec.rb | 22 +++++++++---------- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/sentry-rails/spec/sentry/rails/tracing/active_support_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/tracing/active_support_subscriber_spec.rb index c276063da..0d77fd193 100644 --- a/sentry-rails/spec/sentry/rails/tracing/active_support_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing/active_support_subscriber_spec.rb @@ -23,7 +23,7 @@ transaction.finish expect(transport.events.count).to eq(1) - cache_transaction = transport.events.first.to_hash + cache_transaction = transport.events.first.to_h expect(cache_transaction[:type]).to eq("transaction") expect(cache_transaction[:spans].count).to eq(1) @@ -45,7 +45,7 @@ expect(Rails.cache.read("my_cache_key")).to eq(1) expect(transport.events.count).to eq(1) - cache_transaction = transport.events.first.to_hash + cache_transaction = transport.events.first.to_h expect(cache_transaction[:type]).to eq("transaction") expect(cache_transaction[:spans].count).to eq(1) expect(cache_transaction[:spans][0][:op]).to eq("cache.put") @@ -64,7 +64,7 @@ transaction.finish expect(transport.events.count).to eq(1) - cache_transaction = transport.events.first.to_hash + cache_transaction = transport.events.first.to_h expect(cache_transaction[:type]).to eq("transaction") expect(cache_transaction[:spans].count).to eq(1) expect(cache_transaction[:spans][0][:op]).to eq("cache.put") @@ -79,7 +79,7 @@ transaction.finish expect(transport.events.count).to eq(1) - cache_transaction = transport.events.first.to_hash + cache_transaction = transport.events.first.to_h expect(cache_transaction[:type]).to eq("transaction") expect(cache_transaction[:spans].count).to eq(1) expect(cache_transaction[:spans][0][:op]).to eq("cache.get") @@ -95,7 +95,7 @@ transaction.finish expect(transport.events.count).to eq(1) - cache_transaction = transport.events.first.to_hash + cache_transaction = transport.events.first.to_h expect(cache_transaction[:type]).to eq("transaction") expect(cache_transaction[:spans].count).to eq(1) expect(cache_transaction[:spans][0][:op]).to eq("cache.get") @@ -112,7 +112,7 @@ transaction.finish expect(transport.events.count).to eq(1) - cache_transaction = transport.events.first.to_hash + cache_transaction = transport.events.first.to_h expect(cache_transaction[:type]).to eq("transaction") expect(cache_transaction[:spans].count).to eq(2) expect(cache_transaction[:spans][1][:op]).to eq("cache.flush") @@ -130,7 +130,7 @@ transaction.finish expect(transport.events.count).to eq(1) - cache_transaction = transport.events.first.to_hash + cache_transaction = transport.events.first.to_h expect(cache_transaction[:type]).to eq("transaction") expect(cache_transaction[:spans].count).to eq(2) expect(cache_transaction[:spans][0][:op]).to eq("cache.get") @@ -152,7 +152,7 @@ transaction.finish expect(transport.events.count).to eq(1) - cache_transaction = transport.events.first.to_hash + cache_transaction = transport.events.first.to_h expect(cache_transaction[:type]).to eq("transaction") expect(cache_transaction[:spans].count).to eq(1) expect(cache_transaction[:spans][0][:op]).to eq("cache.remove") diff --git a/sentry-rails/spec/sentry/rails/tracing_spec.rb b/sentry-rails/spec/sentry/rails/tracing_spec.rb index 40d0b9efe..5fa8184c7 100644 --- a/sentry-rails/spec/sentry/rails/tracing_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing_spec.rb @@ -117,7 +117,7 @@ it "does not record sensitive params" do get "/posts?foo=bar&password=42&secret=baz" - transaction = transport.events.last.to_hash + transaction = transport.events.last.to_h params = transaction[:spans][0][:data][:params] expect(params["foo"]).to eq("bar") @@ -139,7 +139,7 @@ it "records all params" do get "/posts?foo=bar&password=42&secret=baz" - transaction = transport.events.last.to_hash + transaction = transport.events.last.to_h params = transaction[:spans][0][:data][:params] expect(params["foo"]).to eq("bar") diff --git a/sentry-ruby/lib/sentry/rspec.rb b/sentry-ruby/lib/sentry/rspec.rb index 9c7c49730..5eb0e2b4e 100644 --- a/sentry-ruby/lib/sentry/rspec.rb +++ b/sentry-ruby/lib/sentry/rspec.rb @@ -70,7 +70,7 @@ def find_matched_event(event_message, sentry_events) end def dump_events(sentry_events) - sentry_events.map(&Kernel.method(:Hash)).map do |hash| + sentry_events.map(&:to_h).map do |hash| hash.select { |k, _| [:message, :contexts, :tags, :exception].include?(k) } end.map do |hash| JSON.pretty_generate(hash) diff --git a/sentry-ruby/lib/sentry/vernier/profiler.rb b/sentry-ruby/lib/sentry/vernier/profiler.rb index 6ee6b6ced..8d8298dff 100644 --- a/sentry-ruby/lib/sentry/vernier/profiler.rb +++ b/sentry-ruby/lib/sentry/vernier/profiler.rb @@ -88,7 +88,7 @@ def active_thread_id Thread.current.object_id end - def to_hash + def to_h return EMPTY_RESULT unless @started unless @sampled diff --git a/sentry-ruby/spec/sentry/event_spec.rb b/sentry-ruby/spec/sentry/event_spec.rb index e384f3673..af0d3468e 100644 --- a/sentry-ruby/spec/sentry/event_spec.rb +++ b/sentry-ruby/spec/sentry/event_spec.rb @@ -146,7 +146,7 @@ it "doesn't overwrite already set ip address" do Sentry.set_user({ ip_address: "3.3.3.3" }) Sentry.get_current_scope.apply_to_event(event) - expect(event.to_hash[:user][:ip_address]).to eq("3.3.3.3") + expect(event.to_h[:user][:ip_address]).to eq("3.3.3.3") end context "with config.trusted_proxies = [\"2.2.2.2\"]" do diff --git a/sentry-ruby/spec/sentry/profiler_spec.rb b/sentry-ruby/spec/sentry/profiler_spec.rb index 9b64b77dc..281040a76 100644 --- a/sentry-ruby/spec/sentry/profiler_spec.rb +++ b/sentry-ruby/spec/sentry/profiler_spec.rb @@ -181,7 +181,7 @@ end it 'returns empty' do - expect(subject.to_hash).to eq({}) + expect(subject.to_h).to eq({}) end it 'records lost event' do diff --git a/sentry-ruby/spec/sentry/vernier/profiler_spec.rb b/sentry-ruby/spec/sentry/vernier/profiler_spec.rb index 46a696fee..563cf6a43 100644 --- a/sentry-ruby/spec/sentry/vernier/profiler_spec.rb +++ b/sentry-ruby/spec/sentry/vernier/profiler_spec.rb @@ -149,7 +149,7 @@ end end - describe "#to_hash" do + describe "#to_h" do let (:transport) { Sentry.get_current_client.transport } @@ -160,7 +160,7 @@ profiler.start profiler.set_initial_sample_decision(false) - expect(profiler.to_hash).to eq({}) + expect(profiler.to_h).to eq({}) end end @@ -169,9 +169,9 @@ profiler.set_initial_sample_decision(true) end - describe '#to_hash' do + describe '#to_h' do it "returns empty hash if not started" do - expect(profiler.to_hash).to eq({}) + expect(profiler.to_h).to eq({}) end context 'with single-thread profiled code' do @@ -182,7 +182,7 @@ end it 'has correct frames' do - frames = profiler.to_hash[:profile][:frames] + frames = profiler.to_h[:profile][:frames] foo_frame = frames.find { |f| f[:function] =~ /foo/ } @@ -195,7 +195,7 @@ end it 'has correct stacks' do - profile = profiler.to_hash[:profile] + profile = profiler.to_h[:profile] frames = profile[:frames] stacks = profile[:stacks] @@ -213,7 +213,7 @@ end it 'has correct samples' do - profile = profiler.to_hash[:profile] + profile = profiler.to_h[:profile] samples = profile[:samples] last_elapsed = 0 @@ -252,7 +252,7 @@ end it "has correct thread metadata" do - thread_metadata = profiler.to_hash[:profile][:thread_metadata] + thread_metadata = profiler.to_h[:profile][:thread_metadata] main_thread = thread_metadata.values.find { |metadata| metadata[:name].include?("rspec") } thread1 = thread_metadata.values.find { |metadata| metadata[:name] == "thread-bar-0" } @@ -268,7 +268,7 @@ end it 'has correct frames', when: { ruby_version?: [:>=, "3.3"] } do - frames = profiler.to_hash[:profile][:frames] + frames = profiler.to_h[:profile][:frames] foo_frame = frames.find { |f| f[:function] =~ /foo/ } @@ -281,7 +281,7 @@ end it 'has correct stacks', when: { ruby_version?: [:>=, "3.3"] } do - profile = profiler.to_hash[:profile] + profile = profiler.to_h[:profile] frames = profile[:frames] stacks = profile[:stacks] @@ -299,7 +299,7 @@ end it 'has correct samples' do - profile = profiler.to_hash[:profile] + profile = profiler.to_h[:profile] samples = profile[:samples] samples.group_by { |sample| sample[:thread_id] }.each do |thread_id, thread_samples| From 913c75edc2c8ee1202c60ddbc83cd541c9504ecf Mon Sep 17 00:00:00 2001 From: Neel Shah Date: Thu, 31 Oct 2024 15:03:36 +0100 Subject: [PATCH 4/4] Don't test jruby delayed_job with rails 7.1 --- sentry-delayed_job/Gemfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sentry-delayed_job/Gemfile b/sentry-delayed_job/Gemfile index 48e80fbdc..087eb9b09 100644 --- a/sentry-delayed_job/Gemfile +++ b/sentry-delayed_job/Gemfile @@ -14,11 +14,14 @@ gem "psych", "5.1.0" gem "delayed_job" gem "delayed_job_active_record" -gem "rails", "> 5.0.0" +if RUBY_PLATFORM == "java" + gem "rails", "> 5.0.0", "< 7.1.0" +else + gem "rails", "> 5.0.0" +end platform :jruby do - # See https://github.com/jruby/activerecord-jdbc-adapter/issues/1139 - gem "activerecord-jdbcmysql-adapter", github: "jruby/activerecord-jdbc-adapter" + gem "activerecord-jdbcmysql-adapter" gem "jdbc-sqlite3" end