redis-rails-instrumentation 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f77ad22f3ab95a646a40999de5e772ac9eca1107
4
- data.tar.gz: 0ae988ec9866cb2443aee39a0c2d4d046fa0c499
2
+ SHA256:
3
+ metadata.gz: b0066f547a9c55c043c785fc3d811ade63174793c6c15e46609dc3fe7ce34a9c
4
+ data.tar.gz: a2b8dd463d10f4352b4957c4d266f906d7c3b424e722a6216b3231e810cb0428
5
5
  SHA512:
6
- metadata.gz: bb535484b3e4870dc4ed2f784fc443264924df4a324dceedf2a888b4d8ff436357f2da65af48a605032fa8671877672f12c10d276669acc8df8b1b4c7ffafc94
7
- data.tar.gz: 7511ba14bc0345597d7da545e84dbad4bc895ea16595c362b8788cccb5cd5d03218c48bf87518a7f19760a8ff42c6c9a320d09ce8710f040a05838bbffc5b055
6
+ metadata.gz: 2c045781ddca460be310dbe70b445207499fb0b93571fbfd31814112cacdb33ab5cb0388dc900eafa301f025668d235d7db2a4fa665feb4c5282bb5ce84e4077
7
+ data.tar.gz: d09c1414b73011e358410ed9baf6f0543ea78db2ab3f03c7e576fcd75194c10f9228298aeec516acf0aacfa131242516245bfcde8361d2196a27d0c50dd06879
@@ -0,0 +1,25 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ name: >-
8
+ Test (${{ matrix.ruby }})
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ ruby:
14
+ - "3.1"
15
+ - "3.2"
16
+ - "3.3"
17
+ - "3.4"
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - uses: supercharge/redis-github-action@1.8.0
21
+ - uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler-cache: true
25
+ - run: bundle exec rake
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
- # Redis Rails Instrumentation [![Build Status](https://travis-ci.org/lautis/redis-rails-instrumentation.svg?branch=master)](https://travis-ci.org/lautis/redis-rails-instrumentation)
1
+ # Redis Rails Instrumentation
2
2
 
3
3
  Railtie to include Redis commands in Rails logging.
4
4
 
5
+ Version 2.0 and newer only supports redis-rb 5.x. If you need older version, please use 1.0.1.
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -0,0 +1,21 @@
1
+ class Redis
2
+ module Rails
3
+ module Middleware
4
+ def connect(redis_config)
5
+ ActiveSupport::Notifications.instrument("connect.redis") { super }
6
+ end
7
+
8
+ def call(command, redis_config)
9
+ ActiveSupport::Notifications.instrument('command.redis', commands: [command]) do
10
+ super
11
+ end
12
+ end
13
+
14
+ def call_pipelined(commands, redis_config)
15
+ ActiveSupport::Notifications.instrument('command.redis', commands: commands) do
16
+ super
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,7 +1,7 @@
1
1
  class Redis
2
2
  module Rails
3
3
  module Instrumentation
4
- VERSION = "1.0.0".freeze
4
+ VERSION = "2.0.0".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -1,5 +1,5 @@
1
1
  require 'redis'
2
- require 'redis/rails/instrumentation/logging'
2
+ require 'redis/rails/instrumentation/middleware'
3
3
  require 'redis/rails/instrumentation/version'
4
4
  require 'active_support'
5
5
  require 'sweet_notifications'
@@ -17,7 +17,7 @@ class Redis
17
17
 
18
18
  output = cmds.map do |name, *args|
19
19
  if !args.empty?
20
- "[ #{name.to_s.upcase} #{args.join(' ')} ]"
20
+ "[ #{name.to_s.upcase} #{format_arguments(args)} ]"
21
21
  else
22
22
  "[ #{name.to_s.upcase} ]"
23
23
  end
@@ -25,9 +25,21 @@ class Redis
25
25
 
26
26
  debug message(event, 'Redis', output)
27
27
  end
28
+
29
+ private
30
+
31
+ def format_arguments(args)
32
+ args.map do |arg|
33
+ if arg.respond_to?(:encoding) && arg.encoding == Encoding::ASCII_8BIT
34
+ '<BINARY DATA>'
35
+ else
36
+ arg
37
+ end
38
+ end.join(' ')
39
+ end
28
40
  end
29
41
  end
30
42
  end
31
43
  end
32
44
 
33
- Redis::Client.send(:prepend, Redis::Rails::Instrumentation::Logging)
45
+ RedisClient.register(Redis::Rails::Middleware)
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(/^(test|spec|features)\//)
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'redis', '>= 3.0', '< 5'
21
+ spec.add_dependency 'redis', '>= 5', '< 6'
22
22
  spec.add_dependency 'activesupport', '>= 3.0'
23
23
  spec.add_dependency 'sweet_notifications', '~> 1.0'
24
- spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'bundler', '>= 1.6'
25
25
  spec.add_development_dependency 'rake'
26
26
  spec.add_development_dependency 'rspec', '~> 3.0'
27
27
  spec.required_ruby_version = '>= 2.0.0'
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'redis'
3
+ require 'base64'
3
4
 
4
5
  class Redis
5
6
  module Rails
@@ -26,9 +27,9 @@ class Redis
26
27
  it 'logs pipelined commands to a single line' do
27
28
  @logger.level = Logger::DEBUG
28
29
  Instrumentation::Railtie.run_initializers
29
- redis.pipelined do
30
- redis.get('test1')
31
- redis.get('test2')
30
+ redis.pipelined do |pipeline|
31
+ pipeline.get('test1')
32
+ pipeline.get('test2')
32
33
  end
33
34
  expect(@logger.logged(:debug)[0])
34
35
  .to match(/Redis \(\d+\.\d+ms\) \[ GET test1 \] \[ GET test2 \]/)
@@ -42,6 +43,14 @@ class Redis
42
43
  .to match(/Redis \(\d+\.\d+ms\) \[ GET test \]/)
43
44
  end
44
45
 
46
+ it 'truncates binary data' do
47
+ @logger.level = Logger::DEBUG
48
+ Instrumentation::Railtie.run_initializers
49
+ redis.set('test', Base64.decode64("R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="))
50
+ expect(@logger.logged(:debug)[0])
51
+ .to match(/Redis \(\d+\.\d+ms\) \[ SET test <BINARY DATA> \]/)
52
+ end
53
+
45
54
  it 'omits debug logging in production' do
46
55
  @logger.level = Logger::ERROR
47
56
  Instrumentation::Railtie.run_initializers
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-rails-instrumentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ville Lautanala
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2017-01-18 00:00:00.000000000 Z
10
+ date: 2025-07-10 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: redis
@@ -16,20 +15,20 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '3.0'
18
+ version: '5'
20
19
  - - "<"
21
20
  - !ruby/object:Gem::Version
22
- version: '5'
21
+ version: '6'
23
22
  type: :runtime
24
23
  prerelease: false
25
24
  version_requirements: !ruby/object:Gem::Requirement
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- version: '3.0'
28
+ version: '5'
30
29
  - - "<"
31
30
  - !ruby/object:Gem::Version
32
- version: '5'
31
+ version: '6'
33
32
  - !ruby/object:Gem::Dependency
34
33
  name: activesupport
35
34
  requirement: !ruby/object:Gem::Requirement
@@ -62,14 +61,14 @@ dependencies:
62
61
  name: bundler
63
62
  requirement: !ruby/object:Gem::Requirement
64
63
  requirements:
65
- - - "~>"
64
+ - - ">="
66
65
  - !ruby/object:Gem::Version
67
66
  version: '1.6'
68
67
  type: :development
69
68
  prerelease: false
70
69
  version_requirements: !ruby/object:Gem::Requirement
71
70
  requirements:
72
- - - "~>"
71
+ - - ">="
73
72
  - !ruby/object:Gem::Version
74
73
  version: '1.6'
75
74
  - !ruby/object:Gem::Dependency
@@ -107,16 +106,16 @@ executables: []
107
106
  extensions: []
108
107
  extra_rdoc_files: []
109
108
  files:
109
+ - ".github/workflows/ci.yml"
110
110
  - ".gitignore"
111
111
  - ".rubocop.yml"
112
- - ".travis.yml"
113
112
  - Gemfile
114
113
  - LICENSE.txt
115
114
  - README.md
116
115
  - Rakefile
117
116
  - lib/redis-rails-instrumentation.rb
118
117
  - lib/redis/rails/instrumentation.rb
119
- - lib/redis/rails/instrumentation/logging.rb
118
+ - lib/redis/rails/instrumentation/middleware.rb
120
119
  - lib/redis/rails/instrumentation/version.rb
121
120
  - redis-rails-instrumentation.gemspec
122
121
  - spec/redis/rails/instrumentation_spec.rb
@@ -125,7 +124,6 @@ homepage: https://github.com/lautis/redis-rails-instrumentation
125
124
  licenses:
126
125
  - MIT
127
126
  metadata: {}
128
- post_install_message:
129
127
  rdoc_options: []
130
128
  require_paths:
131
129
  - lib
@@ -140,9 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
138
  - !ruby/object:Gem::Version
141
139
  version: '0'
142
140
  requirements: []
143
- rubyforge_project:
144
- rubygems_version: 2.6.8
145
- signing_key:
141
+ rubygems_version: 3.6.2
146
142
  specification_version: 4
147
143
  summary: Railtie to include Redis commands in Rails logging.
148
144
  test_files:
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- cache: bundler
4
- rvm:
5
- - 2.1.10
6
- - 2.2.6
7
- - 2.3.3
8
- - 2.4.0
9
- - jruby-9.1.7.0
10
- services:
11
- - redis-server
@@ -1,15 +0,0 @@
1
- class Redis
2
- module Rails
3
- module Instrumentation
4
- # Logging monkeypatch for Redis to emit ActiveSupport::Notification events
5
- module Logging
6
- def logging(commands, &block)
7
- ActiveSupport::Notifications.instrument('command.redis',
8
- commands: commands) do
9
- return super(commands, &block)
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end