Skip to content

WIP 6.0 major #2352

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
9 changes: 6 additions & 3 deletions sentry-delayed_job/Gemfile
Original file line number Diff line number Diff line change
@@ -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

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

54 changes: 5 additions & 49 deletions sentry-rails/spec/sentry/rails/activejob_spec.rb
Original file line number Diff line number Diff line change
@@ -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
@@ -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")
@@ -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",
@@ -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,
@@ -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",
@@ -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,
Original file line number Diff line number Diff line change
@@ -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")
Original file line number Diff line number Diff line change
@@ -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")
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
@@ -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
4 changes: 2 additions & 2 deletions sentry-rails/spec/sentry/rails/event_spec.rb
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -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)

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

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

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

Loading