Skip to content

Commit dce8ef0

Browse files
authored
Support redis-rb 5.0+ (#1963)
* Avoid auto-require on spec_helper so we can control dependency loading order * Make Redis instrumentation work with redis-rb 5.0+ too * Run CI with multiple redis-rb versions * Update changelog
1 parent 52de12e commit dce8ef0

File tree

8 files changed

+100
-42
lines changed

8 files changed

+100
-42
lines changed

.github/workflows/sentry_ruby_test.yml

+61-24
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,71 @@ jobs:
2121
runs-on: ${{ matrix.os }}
2222
strategy:
2323
matrix:
24-
ruby_version: [2.4, 2.5, 2.6, 2.7, '3.0', head, jruby]
24+
ruby_version: [2.4, 2.5, 2.6, 2.7, "3.0", head, jruby]
2525
rack_version: [2.0, 3.0]
26+
redis_rb_version: [4.0]
2627
os: [ubuntu-latest]
2728
include:
28-
- { os: ubuntu-latest, ruby_version: 3.1, rack_version: 0 }
29-
- { os: ubuntu-latest, ruby_version: 3.1, rack_version: 2.0 }
30-
- { os: ubuntu-latest, ruby_version: 3.1, rack_version: 3.0 }
31-
- { os: ubuntu-latest, ruby_version: 3.1, rack_version: 3.0, options: { rubyopt: "--enable-frozen-string-literal --debug=frozen-string-literal" } }
32-
- { os: ubuntu-latest, ruby_version: 3.1, rack_version: 3.0, options: { codecov: 1 } }
29+
- {
30+
os: ubuntu-latest,
31+
ruby_version: 3.1,
32+
rack_version: 0,
33+
redis_rb_version: 5.0,
34+
}
35+
- {
36+
os: ubuntu-latest,
37+
ruby_version: 3.1,
38+
rack_version: 2.0,
39+
redis_rb_version: 5.0,
40+
}
41+
- {
42+
os: ubuntu-latest,
43+
ruby_version: 3.1,
44+
rack_version: 3.0,
45+
redis_rb_version: 5.0,
46+
}
47+
- {
48+
os: ubuntu-latest,
49+
ruby_version: 3.1,
50+
rack_version: 3.0,
51+
redis_rb_version: 5.0,
52+
options:
53+
{
54+
rubyopt: "--enable-frozen-string-literal --debug=frozen-string-literal",
55+
},
56+
}
57+
- {
58+
os: ubuntu-latest,
59+
ruby_version: 3.1,
60+
rack_version: 3.0,
61+
redis_rb_version: 5.0,
62+
options: { codecov: 1 },
63+
}
3364
steps:
34-
- uses: actions/checkout@v1
65+
- uses: actions/checkout@v1
3566

36-
- name: Set up Ruby ${{ matrix.ruby_version }}
37-
uses: ruby/setup-ruby@v1
38-
with:
39-
ruby-version: ${{ matrix.ruby_version }}
67+
- name: Set up Ruby ${{ matrix.ruby_version }}
68+
uses: ruby/setup-ruby@v1
69+
with:
70+
ruby-version: ${{ matrix.ruby_version }}
4071

41-
- name: Run specs
42-
env:
43-
RUBYOPT: ${{ matrix.options.rubyopt }}
44-
RACK_VERSION: ${{ matrix.rack_version }}
45-
run: |
46-
bundle install --jobs 4 --retry 3
47-
bundle exec rake
72+
- name: Start Redis
73+
uses: supercharge/redis-github-action@c169aa53af4cd5d9321e9114669dbd11be08d307
74+
with:
75+
redis-version: 6
4876

49-
- name: Upload Coverage
50-
if: ${{ matrix.options.codecov }}
51-
run: |
52-
curl -Os https://uploader.codecov.io/latest/linux/codecov
53-
chmod +x codecov
54-
./codecov -t ${CODECOV_TOKEN} -R `pwd` -f coverage/coverage.xml
77+
- name: Run specs with Rack ${{ matrix.rack_version }} and redis-rb ${{ matrix.redis_rb_version }}
78+
env:
79+
RUBYOPT: ${{ matrix.options.rubyopt }}
80+
RACK_VERSION: ${{ matrix.rack_version }}
81+
REDIS_RB_VERSION: ${{ matrix.redis_rb_version }}
82+
run: |
83+
bundle install --jobs 4 --retry 3
84+
bundle exec rake
85+
86+
- name: Upload Coverage
87+
if: ${{ matrix.options.codecov }}
88+
run: |
89+
curl -Os https://uploader.codecov.io/latest/linux/codecov
90+
chmod +x codecov
91+
./codecov -t ${CODECOV_TOKEN} -R `pwd` -f coverage/coverage.xml

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
## Unreleased
22

33
### Features
4+
45
- Allow [tags](https://docs.sentry.io/platforms/ruby/enriching-events/tags/) to be passed via the context hash when reporting errors using ActiveSupport::ErrorReporter and Sentry::Rails::ErrorSubscriber in `sentry-rails` [#1932](https://github.com/getsentry/sentry-ruby/pull/1932)
56

7+
### Bug Fixes
8+
9+
- Support redis-rb 5.0+ [#1963](https://github.com/getsentry/sentry-ruby/pull/1963)
10+
- Fixes [#1932](https://github.com/getsentry/sentry-ruby/pull/1932)
11+
612
## 5.7.0
713

814
### Features

sentry-ruby/.rspec

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
--format documentation
22
--color
3-
--require spec_helper

sentry-ruby/Gemfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ rack_version = ENV["RACK_VERSION"]
77
rack_version = "3.0.0" if rack_version.nil?
88
gem "rack", "~> #{Gem::Version.new(rack_version)}" unless rack_version == "0"
99

10+
redis_rb_version = ENV.fetch("REDIS_RB_VERSION", "5.0")
11+
gem "redis", "~> #{redis_rb_version}"
12+
1013
gem "rake", "~> 12.0"
1114
gem "rspec", "~> 3.0"
1215
gem "rspec-retry"
13-
gem "fakeredis"
1416
gem "timecop"
15-
gem 'simplecov'
17+
gem "simplecov"
1618
gem "simplecov-cobertura", "~> 1.4"
1719
gem "rexml"
1820

sentry-ruby/lib/sentry/redis.rb

+25-7
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,37 @@ def server_description
7070
"#{host}:#{port}/#{db}"
7171
end
7272

73-
module Client
73+
module OldClientPatch
7474
def logging(commands, &block)
75-
Sentry::Redis.new(commands, host, port, db).instrument do
76-
super
77-
end
75+
Sentry::Redis.new(commands, host, port, db).instrument { super }
76+
end
77+
end
78+
79+
module GlobalRedisInstrumentation
80+
def call(command, redis_config)
81+
Sentry::Redis
82+
.new([command], redis_config.host, redis_config.port, redis_config.db)
83+
.instrument { super }
84+
end
85+
86+
def call_pipelined(commands, redis_config)
87+
Sentry::Redis
88+
.new(commands, redis_config.host, redis_config.port, redis_config.db)
89+
.instrument { super }
7890
end
7991
end
8092
end
8193
end
8294

8395
if defined?(::Redis::Client)
84-
Sentry.register_patch do
85-
patch = Sentry::Redis::Client
86-
Redis::Client.prepend(patch) unless Redis::Client.ancestors.include?(patch)
96+
if Gem::Version.new(::Redis::VERSION) < Gem::Version.new("5.0")
97+
Sentry.register_patch do
98+
patch = Sentry::Redis::OldClientPatch
99+
unless Redis::Client.ancestors.include?(patch)
100+
Redis::Client.prepend(patch)
101+
end
102+
end
103+
elsif defined?(RedisClient)
104+
RedisClient.register(Sentry::Redis::GlobalRedisInstrumentation)
87105
end
88106
end

sentry-ruby/spec/sentry/breadcrumb/redis_logger_spec.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
require "spec_helper"
22

33
RSpec.describe :redis_logger do
4-
let(:redis) do
5-
Redis.new
6-
end
4+
let(:redis) { Redis.new(host: "127.0.0.1") }
75

86
before do
97
perform_basic_setup do |config|
@@ -59,7 +57,7 @@
5957
let(:result) { redis.info }
6058

6159
it "doesn't cause an error" do
62-
expect(result).to include("uptime_in_days" => 0)
60+
expect(result["uptime_in_days"].to_s).to eq("0")
6361
expect(Sentry.get_current_scope.breadcrumbs.peek).to have_attributes(
6462
category: "db.redis",
6563
data: { commands: [{ command: "INFO", key: nil }], server: "127.0.0.1:6379/0" }

sentry-ruby/spec/sentry/redis_spec.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
require "spec_helper"
22

33
RSpec.describe Sentry::Redis do
4-
let(:redis) do
5-
Redis.new
6-
end
4+
let(:redis) { Redis.new(host: "127.0.0.1") }
75

86
context "with tracing enabled" do
97
before do

sentry-ruby/spec/spec_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require "timecop"
55
require "simplecov"
66
require "rspec/retry"
7-
require "fakeredis/rspec"
7+
require "redis"
88

99
SimpleCov.start do
1010
project_name "sentry-ruby"

0 commit comments

Comments
 (0)