Skip to content

Commit 6b35110

Browse files
authored
Make sentry-sidekiq compatible with Sidekiq 7 (#1930)
* Make sentry-sidekiq compatible with Sidekiq 7 * Update changelog
1 parent ca597ad commit 6b35110

File tree

6 files changed

+83
-28
lines changed

6 files changed

+83
-28
lines changed

.github/workflows/sentry_sidekiq_test.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
runs-on: ${{ matrix.os }}
2222
strategy:
2323
matrix:
24-
sidekiq_version: [5.0, 6.0]
24+
sidekiq_version: ['5.0', '6.0', '7.0']
2525
ruby_version: [2.4, 2.5, 2.6, 2.7, '3.0', '3.1', head, jruby]
2626
os: [ubuntu-latest]
2727
include:
@@ -30,6 +30,14 @@ jobs:
3030
exclude:
3131
- ruby_version: 2.4
3232
sidekiq_version: 6.0
33+
- ruby_version: 2.4
34+
sidekiq_version: 7.0
35+
- ruby_version: 2.5
36+
sidekiq_version: 7.0
37+
- ruby_version: 2.6
38+
sidekiq_version: 7.0
39+
- ruby_version: jruby
40+
sidekiq_version: 7.0
3341
steps:
3442
- uses: actions/checkout@v1
3543

@@ -41,7 +49,7 @@ jobs:
4149
- name: Start Redis
4250
uses: supercharge/[email protected]
4351
with:
44-
redis-version: 5
52+
redis-version: ${{ matrix.sidekiq_version == '7.0' && 6 || 5 }}
4553

4654
- name: Run specs with Sidekiq ${{ matrix.sidekiq_version }}
4755
env:

CHANGELOG.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,32 @@
44

55
- Allow users to configure their asset-skipping pattern [#1915](https://github.com/getsentry/sentry-ruby/pull/1915)
66

7-
Users can now configure their own pattern to skip asset requests' transactions
7+
Users can now configure their own pattern to skip asset requests' transactions
8+
9+
```rb
10+
Sentry.init do |config|
11+
config.rails.assets_regexp = /my_regexp/
12+
end
13+
```
814

9-
```rb
10-
Sentry.init do |config|
11-
config.rails.assets_regexp = /my_regexp/
12-
end
13-
```
1415
- Use `Sentry.with_child_span` in redis and net/http instead of `span.start_child` [#1920](https://github.com/getsentry/sentry-ruby/pull/1920)
15-
- This might change the nesting of some spans and make it more accurate
16-
- Followup fix to set the sentry-trace header in the correct place [#1922](https://github.com/getsentry/sentry-ruby/pull/1922)
16+
- This might change the nesting of some spans and make it more accurate
17+
- Followup fix to set the sentry-trace header in the correct place [#1922](https://github.com/getsentry/sentry-ruby/pull/1922)
1718

1819
- Use `Exception#detailed_message` when generating exception message if applicable [#1924](https://github.com/getsentry/sentry-ruby/pull/1924)
20+
- Make `sentry-sidekiq` compatible with Sidekiq 7 [#1930](https://github.com/getsentry/sentry-ruby/pull/1930)
1921

2022
### Bug Fixes
2123

2224
- `Sentry::BackgroundWorker` will release `ActiveRecord` connection pool only when the `ActiveRecord` connection is established
2325
- Remove bad encoding arguments in redis span descriptions [#1914](https://github.com/getsentry/sentry-ruby/pull/1914)
24-
- Fixes [#1911](https://github.com/getsentry/sentry-ruby/issues/1911)
26+
- Fixes [#1911](https://github.com/getsentry/sentry-ruby/issues/1911)
2527
- Add missing `initialized?` checks to `sentry-rails` [#1919](https://github.com/getsentry/sentry-ruby/pull/1919)
26-
- Fixes [#1885](https://github.com/getsentry/sentry-ruby/issues/1885)
28+
- Fixes [#1885](https://github.com/getsentry/sentry-ruby/issues/1885)
2729
- Update Tracing Span's op names [#1923](https://github.com/getsentry/sentry-ruby/pull/1923)
2830
29-
Currently, Ruby integrations' Span op names aren't aligned with the core specification's convention, so we decided to update them altogether in this PR.
30-
**If you rely on Span op names for fine-grained event filtering, this may affect the data your app sends to Sentry.**
31+
Currently, Ruby integrations' Span op names aren't aligned with the core specification's convention, so we decided to update them altogether in this PR.
32+
**If you rely on Span op names for fine-grained event filtering, this may affect the data your app sends to Sentry.**
3133

3234
### Refactoring
3335

sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module Sentry
44
module Sidekiq
55
class ErrorHandler
6+
WITH_SIDEKIQ_7 = ::Gem::Version.new(::Sidekiq::VERSION) >= ::Gem::Version.new("7.0")
7+
68
def call(ex, context)
79
return unless Sentry.initialized?
810

@@ -40,7 +42,13 @@ def retry_limit(context)
4042
when Integer
4143
limit
4244
when TrueClass
43-
::Sidekiq.options[:max_retries] || 25
45+
max_retries =
46+
if WITH_SIDEKIQ_7
47+
::Sidekiq.default_configuration[:max_retries]
48+
else
49+
::Sidekiq.options[:max_retries]
50+
end
51+
max_retries || 25
4452
else
4553
0
4654
end

sentry-sidekiq/spec/sentry/sidekiq/error_handler_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@
3030
end
3131

3232
it "captures exceptions raised during events" do
33-
Sidekiq.options[:lifecycle_events][:startup] = [proc { raise "Uhoh!" }]
34-
processor.fire_event(:startup)
33+
if WITH_SIDEKIQ_7
34+
config = Sidekiq.instance_variable_get(:@config)
35+
config[:lifecycle_events][:startup] = [proc { raise "Uhoh!" }]
36+
Sidekiq::Embedded.new(config).fire_event(:startup)
37+
else
38+
Sidekiq.options[:lifecycle_events][:startup] = [proc { raise "Uhoh!" }]
39+
processor.fire_event(:startup)
40+
end
3541

3642
event = transport.events.last.to_hash
3743
expect(Sentry::Event.get_message_from_exception(event)).to match("RuntimeError: Uhoh!")

sentry-sidekiq/spec/sentry/sidekiq_spec.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,17 @@
3636
end
3737

3838
it "registers error handlers and middlewares" do
39-
expect(Sidekiq.error_handlers).to include(described_class::ErrorHandler)
40-
expect(Sidekiq.server_middleware.entries.first.klass).to eq(described_class::SentryContextServerMiddleware)
41-
expect(Sidekiq.client_middleware.entries.first.klass).to eq(described_class::SentryContextClientMiddleware)
39+
if WITH_SIDEKIQ_7
40+
config = Sidekiq.instance_variable_get(:@config)
41+
42+
expect(config.error_handlers).to include(described_class::ErrorHandler)
43+
expect(config.server_middleware.entries.map(&:klass)).to include(described_class::SentryContextServerMiddleware)
44+
expect(config.client_middleware.entries.map(&:klass)).to include(described_class::SentryContextClientMiddleware)
45+
else
46+
expect(Sidekiq.error_handlers).to include(described_class::ErrorHandler)
47+
expect(Sidekiq.server_middleware.entries.first.klass).to eq(described_class::SentryContextServerMiddleware)
48+
expect(Sidekiq.client_middleware.entries.first.klass).to eq(described_class::SentryContextClientMiddleware)
49+
end
4250
end
4351

4452
it "captues exception raised in the worker" do
@@ -163,7 +171,11 @@ def retry_last_failed_job
163171

164172
context "when Sidekiq.options[:max_retries] is set" do
165173
it "respects the set limit" do
166-
Sidekiq.options[:max_retries] = 5
174+
if WITH_SIDEKIQ_7
175+
Sidekiq.default_configuration[:max_retries] = 5
176+
else
177+
Sidekiq.options[:max_retries] = 5
178+
end
167179

168180
execute_worker(processor, SadWorker)
169181
expect(transport.events.count).to eq(0)

sentry-sidekiq/spec/spec_helper.rb

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44

55
# this enables sidekiq's server mode
66
require "sidekiq/cli"
7-
# require "support/test_sidekiq_app/app"
7+
8+
WITH_SIDEKIQ_7 = Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("7.0")
9+
WITH_SIDEKIQ_6 = Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("6.0") && !WITH_SIDEKIQ_7
10+
11+
if WITH_SIDEKIQ_7
12+
require "sidekiq/embedded"
13+
end
814

915
require "sentry-ruby"
1016

@@ -47,7 +53,17 @@
4753
end
4854

4955
config.before :all do
50-
Sidekiq.logger = Logger.new(nil)
56+
silence_sidekiq
57+
end
58+
end
59+
60+
def silence_sidekiq
61+
logger = Logger.new(nil)
62+
63+
if WITH_SIDEKIQ_7
64+
Sidekiq.instance_variable_get(:@config).logger = logger
65+
else
66+
Sidekiq.logger = logger
5167
end
5268
end
5369

@@ -142,15 +158,18 @@ def perform; end
142158
end
143159

144160
def new_processor
145-
options =
146-
if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("6.0")
161+
manager =
162+
case
163+
when WITH_SIDEKIQ_7
164+
capsule = Sidekiq.instance_variable_get(:@config).default_capsule
165+
Sidekiq::Manager.new(capsule)
166+
when WITH_SIDEKIQ_6
147167
Sidekiq[:queue] = ['default']
148-
Sidekiq
168+
Sidekiq::Manager.new(Sidekiq)
149169
else
150-
{ queues: ['default'] }
170+
Sidekiq::Manager.new({ queues: ['default'] })
151171
end
152172

153-
manager = Sidekiq::Manager.new(options)
154173
manager.workers.first
155174
end
156175

0 commit comments

Comments
 (0)