Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WIP 6.0 major #2352

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Unreleased (6.0.0)

### 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

### Features
Expand Down
9 changes: 6 additions & 3 deletions sentry-delayed_job/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions sentry-delayed_job/spec/sentry/delayed_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -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 })

Expand All @@ -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

Expand All @@ -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")
Expand All @@ -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({})
Expand All @@ -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({})
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
18 changes: 7 additions & 11 deletions sentry-rails/lib/sentry/rails/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
54 changes: 5 additions & 49 deletions sentry-rails/spec/sentry/rails/activejob_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -298,7 +254,7 @@ def perform(event, hint)
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")
Expand Down Expand Up @@ -337,7 +293,7 @@ def perform(event, hint)
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",
Expand All @@ -346,7 +302,7 @@ def perform(event, hint)

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,
Expand All @@ -365,7 +321,7 @@ def perform(event, hint)
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",
Expand All @@ -375,7 +331,7 @@ def perform(event, hint)

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions sentry-rails/spec/sentry/rails/controller_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
4 changes: 2 additions & 2 deletions sentry-rails/spec/sentry/rails/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
Loading
Loading