paul_bunyan 1.6.0 → 2.1.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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +7 -0
  3. data/Dockerfile +10 -15
  4. data/Jenkinsfile +34 -6
  5. data/Rakefile +4 -2
  6. data/docker-compose.override.yml.example +2 -2
  7. data/gemfiles/rails_6.1.gemfile +7 -0
  8. data/gemfiles/rails_6.1.gemfile.lock +185 -0
  9. data/gemfiles/rails_7.0.gemfile +7 -0
  10. data/gemfiles/rails_7.0.gemfile.lock +184 -0
  11. data/lib/paul_bunyan/json_formatter.rb +7 -7
  12. data/lib/paul_bunyan/log_relayer.rb +25 -9
  13. data/lib/paul_bunyan/metadata_logging.rb +6 -6
  14. data/lib/paul_bunyan/railtie/log_subscriber.rb +3 -1
  15. data/lib/paul_bunyan/railtie.rb +0 -1
  16. data/lib/paul_bunyan/version.rb +1 -1
  17. data/paul_bunyan.gemspec +2 -2
  18. data/spec/dummy/app/models/application_record.rb +3 -0
  19. data/spec/dummy/app/models/widget.rb +2 -0
  20. data/spec/dummy/config/application.rb +2 -3
  21. data/spec/dummy/config/environments/development.rb +0 -14
  22. data/spec/dummy/db/migrate/20230301183442_create_widgets.rb +10 -0
  23. data/spec/dummy/db/schema.rb +21 -0
  24. data/spec/lib/paul_bunyan/log_relayer_spec.rb +14 -10
  25. data/spec/lib/paul_bunyan/metadata_logging_spec.rb +6 -6
  26. data/spec/lib/paul_bunyan/railtie/log_subscriber_spec.rb +6 -2
  27. data/spec/lib/paul_bunyan/railtie_spec.rb +4 -4
  28. metadata +26 -26
  29. data/.travis.yml +0 -21
  30. data/lib/paul_bunyan/rails_ext/active_support_logger.rb +0 -11
  31. data/lib/paul_bunyan/rails_ext/instrumentation.rb +0 -41
  32. data/lib/paul_bunyan/rails_ext/rack_logger.rb +0 -24
  33. data/lib/paul_bunyan/rails_ext.rb +0 -8
  34. data/spec/dummy/config/initializers/assets.rb +0 -11
  35. data/spec/gemfiles/52.gemfile +0 -5
  36. data/spec/gemfiles/60.gemfile +0 -5
  37. data/spec/lib/paul_bunyan/rails_ext/instrumentation_spec.rb +0 -103
@@ -0,0 +1,2 @@
1
+ class Widget < ApplicationRecord
2
+ end
@@ -19,9 +19,8 @@ module Dummy
19
19
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
20
  # config.i18n.default_locale = :de
21
21
 
22
- # Do not swallow errors in after_commit/after_rollback callbacks.
23
- if Rails.version > '4.2' && Rails.version < '5.0'
24
- config.active_record.raise_in_transactional_callbacks = true
22
+ if Rails.version < '6.0'
23
+ config.active_record.sqlite3.represent_boolean_as_integer = true
25
24
  end
26
25
  end
27
26
  end
@@ -22,20 +22,6 @@ Rails.application.configure do
22
22
  # Raise an error on page load if there are pending migrations.
23
23
  config.active_record.migration_error = :page_load
24
24
 
25
- # Debug mode disables concatenation and preprocessing of assets.
26
- # This option may cause significant delays in view rendering with a large
27
- # number of complex assets.
28
- config.assets.debug = true
29
-
30
- # Asset digests allow you to set far-future HTTP expiration dates on all assets,
31
- # yet still be able to expire them through the digest params.
32
- config.assets.digest = true
33
-
34
- # Adds additional error checking when serving assets at runtime.
35
- # Checks for improperly declared sprockets dependencies.
36
- # Raises helpful error messages.
37
- config.assets.raise_runtime_errors = true
38
-
39
25
  # Raises error for missing translations
40
26
  # config.action_view.raise_on_missing_translations = true
41
27
  end
@@ -0,0 +1,10 @@
1
+ class CreateWidgets < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :widgets do |t|
4
+ t.string :name
5
+ t.integer :quantity
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,21 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema[7.0].define(version: 2023_03_01_183442) do
14
+ create_table "widgets", force: :cascade do |t|
15
+ t.string "name"
16
+ t.integer "quantity"
17
+ t.datetime "created_at", null: false
18
+ t.datetime "updated_at", null: false
19
+ end
20
+
21
+ end
@@ -337,6 +337,10 @@ describe PaulBunyan::LogRelayer do
337
337
  end
338
338
  end
339
339
 
340
+ # The funny `, **({})` bit can be removed once we don't test on ruby 2.7
341
+ # It ensures that the spec considers the arg to be a hash arg and not a kwarg
342
+ # on ruby < 3.0. The methods treat actual hashes and kwargs identically so
343
+ # it doesn't really matter which one it passes through as
340
344
  context 'logging metadata' do
341
345
  let(:my_metadata) { {foo: 'bar'} }
342
346
 
@@ -350,7 +354,7 @@ describe PaulBunyan::LogRelayer do
350
354
  it 'delegates to all child loggers that support it' do
351
355
  expect(primary).to receive(:add_metadata).with(my_metadata)
352
356
  expect(secondary).to_not receive(:add_metadata)
353
- double_relayer.add_metadata(my_metadata)
357
+ double_relayer.add_metadata(my_metadata, **({}))
354
358
  end
355
359
  end
356
360
 
@@ -376,29 +380,29 @@ describe PaulBunyan::LogRelayer do
376
380
  it 'delegates to all child loggers' do
377
381
  expect(primary).to receive(:remove_metadata).with(my_metadata)
378
382
  expect(secondary).to_not receive(:remove_metadata)
379
- double_relayer.remove_metadata(my_metadata)
383
+ double_relayer.remove_metadata(my_metadata, **({}))
380
384
  end
381
385
  end
382
386
 
383
387
  describe '#with_metadata' do
384
388
  before do
385
- allow(single_relayer).to receive(:add_metadata).with(my_metadata)
386
- allow(single_relayer).to receive(:remove_metadata).with(my_metadata)
389
+ allow(single_relayer).to receive(:add_metadata).with(my_metadata, **({}))
390
+ allow(single_relayer).to receive(:remove_metadata).with(my_metadata, **({}))
387
391
  end
388
392
 
389
393
  it 'must call #add_metadata with the supplied hash' do
390
- expect(single_relayer).to receive(:add_metadata).with(my_metadata)
391
- expect { |b| single_relayer.with_metadata(my_metadata, &b) }.to yield_control
394
+ expect(single_relayer).to receive(:add_metadata).with(my_metadata, **({}))
395
+ expect { |b| single_relayer.with_metadata(my_metadata, **({}), &b) }.to yield_control
392
396
  end
393
397
 
394
398
  it 'must call #remove_metadata with the supplied hash' do
395
- expect(single_relayer).to receive(:remove_metadata).with(my_metadata)
396
- expect { |b| single_relayer.with_metadata(my_metadata, &b) }.to yield_control
399
+ expect(single_relayer).to receive(:remove_metadata).with(my_metadata, **({}))
400
+ expect { |b| single_relayer.with_metadata(my_metadata, **({}), &b) }.to yield_control
397
401
  end
398
402
 
399
403
  it 'must call #remove_metadata when the block raises an exception' do
400
- expect(single_relayer).to receive(:remove_metadata).with(my_metadata)
401
- expect { single_relayer.with_metadata(my_metadata) do
404
+ expect(single_relayer).to receive(:remove_metadata).with(my_metadata, **({}))
405
+ expect { single_relayer.with_metadata(my_metadata, **({})) do
402
406
  fail StandardError, ':('
403
407
  end
404
408
  }.to raise_error(StandardError)
@@ -16,15 +16,15 @@ describe PaulBunyan::MetadataLogging do
16
16
  end
17
17
 
18
18
  it 'must delegate with_metadata to the formatter' do
19
- expect(formatter).to receive(:with_metadata).with(foo: 'bar').and_yield
20
- subject.with_metadata(foo: 'bar') do |logger|
19
+ expect(formatter).to receive(:with_metadata).with({hash: 123}, foo: 'bar').and_yield
20
+ subject.with_metadata({hash: 123}, foo: 'bar') do |logger|
21
21
  expect(subject).to eq logger
22
22
  end
23
23
  end
24
24
 
25
25
  it 'must delegate add_metadata to the formatter' do
26
- expect(formatter).to receive(:add_metadata).with(foo: 'bar')
27
- subject.add_metadata(foo: 'bar')
26
+ expect(formatter).to receive(:add_metadata).with({hash: 123}, foo: 'bar')
27
+ subject.add_metadata({hash: 123}, foo: 'bar')
28
28
  end
29
29
 
30
30
  it 'must delegate current_metadata to the formatter' do
@@ -33,8 +33,8 @@ describe PaulBunyan::MetadataLogging do
33
33
  end
34
34
 
35
35
  it 'must delegate remove_metadata to the formatter' do
36
- expect(formatter).to receive(:remove_metadata).with(foo: 'bar')
37
- subject.remove_metadata(foo: 'bar')
36
+ expect(formatter).to receive(:remove_metadata).with({hash: 123}, foo: 'bar')
37
+ subject.remove_metadata({hash: 123}, foo: 'bar')
38
38
  end
39
39
 
40
40
  context '#flush' do
@@ -61,6 +61,11 @@ module PaulBunyan
61
61
  end
62
62
 
63
63
  describe '#process_action(event)' do
64
+ let(:request) {
65
+ req = instance_double("ActionDispatch::Request", ip: "127.0.0.1", env: {
66
+ "action_dispatch.request_id" => "dfa6f7b5-8400-4572-a2f7-80504ed9d09a"
67
+ })
68
+ }
64
69
  let(:event) {
65
70
  ActiveSupport::Notifications::Event.new(
66
71
  'process_action.action_controller',
@@ -74,8 +79,7 @@ module PaulBunyan
74
79
  :format => :html,
75
80
  :method => "GET",
76
81
  :path => "/foos/42",
77
- :request_id => "dfa6f7b5-8400-4572-a2f7-80504ed9d09a",
78
- :ip => '127.0.0.1',
82
+ :request => request,
79
83
  :status => 200,
80
84
  :view_runtime => 220.038,
81
85
  :db_runtime => 10.177,
@@ -32,10 +32,10 @@ module PaulBunyan
32
32
  end
33
33
 
34
34
  it 'must leave the ActionController::LogSubscriber subscription to deep_munge.action_controller in place' do
35
- # I don't expect that we'll ever care to unsubcribe the logger
36
- # non-event so we'll use it as a check to ensure we don't
37
- # clobber all of the listeners, only the ones we care about
38
- expect(subscriber_classes_for('logger.action_controller')).
35
+ # We do not currently support fragment cache logging so we'll use it as
36
+ # a check to ensure we don't clobber all of the listeners, only the
37
+ # ones we care about
38
+ expect(subscriber_classes_for('write_fragment.action_controller')).
39
39
  to include ActionController::LogSubscriber
40
40
  end
41
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paul_bunyan
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duane Johnson
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-04-01 00:00:00.000000000 Z
14
+ date: 2023-03-06 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: request_store
@@ -28,21 +28,21 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: bundler
31
+ name: appraisal
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - ">="
34
+ - - "~>"
35
35
  - !ruby/object:Gem::Version
36
- version: '0'
36
+ version: 2.4.0
37
37
  type: :development
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - ">="
41
+ - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: '0'
43
+ version: 2.4.0
44
44
  - !ruby/object:Gem::Dependency
45
- name: rake
45
+ name: bundler
46
46
  requirement: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - ">="
@@ -56,7 +56,7 @@ dependencies:
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  - !ruby/object:Gem::Dependency
59
- name: rspec
59
+ name: rake
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - ">="
@@ -70,7 +70,7 @@ dependencies:
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
72
  - !ruby/object:Gem::Dependency
73
- name: wwtd
73
+ name: rspec
74
74
  requirement: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - ">="
@@ -89,14 +89,14 @@ dependencies:
89
89
  requirements:
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
- version: '5.2'
92
+ version: '6.1'
93
93
  type: :development
94
94
  prerelease: false
95
95
  version_requirements: !ruby/object:Gem::Requirement
96
96
  requirements:
97
97
  - - ">="
98
98
  - !ruby/object:Gem::Version
99
- version: '5.2'
99
+ version: '6.1'
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: sqlite3
102
102
  requirement: !ruby/object:Gem::Requirement
@@ -140,7 +140,7 @@ extra_rdoc_files: []
140
140
  files:
141
141
  - ".dockerignore"
142
142
  - ".gitignore"
143
- - ".travis.yml"
143
+ - Appraisals
144
144
  - Dockerfile
145
145
  - Gemfile
146
146
  - Guardfile
@@ -153,15 +153,15 @@ files:
153
153
  - docker-compose.override.yml.example
154
154
  - docker-compose.yml
155
155
  - examples/host_middleware.rb
156
+ - gemfiles/rails_6.1.gemfile
157
+ - gemfiles/rails_6.1.gemfile.lock
158
+ - gemfiles/rails_7.0.gemfile
159
+ - gemfiles/rails_7.0.gemfile.lock
156
160
  - lib/paul_bunyan.rb
157
161
  - lib/paul_bunyan/json_formatter.rb
158
162
  - lib/paul_bunyan/level.rb
159
163
  - lib/paul_bunyan/log_relayer.rb
160
164
  - lib/paul_bunyan/metadata_logging.rb
161
- - lib/paul_bunyan/rails_ext.rb
162
- - lib/paul_bunyan/rails_ext/active_support_logger.rb
163
- - lib/paul_bunyan/rails_ext/instrumentation.rb
164
- - lib/paul_bunyan/rails_ext/rack_logger.rb
165
165
  - lib/paul_bunyan/railtie.rb
166
166
  - lib/paul_bunyan/railtie/log_subscriber.rb
167
167
  - lib/paul_bunyan/tagged_logging.rb
@@ -179,7 +179,9 @@ files:
179
179
  - spec/dummy/app/helpers/application_helper.rb
180
180
  - spec/dummy/app/mailers/.keep
181
181
  - spec/dummy/app/models/.keep
182
+ - spec/dummy/app/models/application_record.rb
182
183
  - spec/dummy/app/models/concerns/.keep
184
+ - spec/dummy/app/models/widget.rb
183
185
  - spec/dummy/app/views/layouts/application.html.erb
184
186
  - spec/dummy/bin/bundle
185
187
  - spec/dummy/bin/rails
@@ -193,7 +195,6 @@ files:
193
195
  - spec/dummy/config/environments/development.rb
194
196
  - spec/dummy/config/environments/production.rb
195
197
  - spec/dummy/config/environments/test.rb
196
- - spec/dummy/config/initializers/assets.rb
197
198
  - spec/dummy/config/initializers/backtrace_silencers.rb
198
199
  - spec/dummy/config/initializers/cookies_serializer.rb
199
200
  - spec/dummy/config/initializers/filter_parameter_logging.rb
@@ -205,19 +206,18 @@ files:
205
206
  - spec/dummy/config/locales/en.yml
206
207
  - spec/dummy/config/routes.rb
207
208
  - spec/dummy/config/secrets.yml
209
+ - spec/dummy/db/migrate/20230301183442_create_widgets.rb
210
+ - spec/dummy/db/schema.rb
208
211
  - spec/dummy/lib/assets/.keep
209
212
  - spec/dummy/log/.keep
210
213
  - spec/dummy/public/404.html
211
214
  - spec/dummy/public/422.html
212
215
  - spec/dummy/public/500.html
213
216
  - spec/dummy/public/favicon.ico
214
- - spec/gemfiles/52.gemfile
215
- - spec/gemfiles/60.gemfile
216
217
  - spec/lib/paul_bunyan/json_formatter_spec.rb
217
218
  - spec/lib/paul_bunyan/level_spec.rb
218
219
  - spec/lib/paul_bunyan/log_relayer_spec.rb
219
220
  - spec/lib/paul_bunyan/metadata_logging_spec.rb
220
- - spec/lib/paul_bunyan/rails_ext/instrumentation_spec.rb
221
221
  - spec/lib/paul_bunyan/railtie/log_subscriber_spec.rb
222
222
  - spec/lib/paul_bunyan/railtie_spec.rb
223
223
  - spec/lib/paul_bunyan/tagged_logging_spec.rb
@@ -243,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
243
  - !ruby/object:Gem::Version
244
244
  version: '0'
245
245
  requirements: []
246
- rubygems_version: 3.0.3
246
+ rubygems_version: 3.1.6
247
247
  signing_key:
248
248
  specification_version: 4
249
249
  summary: Logging for all the things
@@ -258,7 +258,9 @@ test_files:
258
258
  - spec/dummy/app/helpers/application_helper.rb
259
259
  - spec/dummy/app/mailers/.keep
260
260
  - spec/dummy/app/models/.keep
261
+ - spec/dummy/app/models/application_record.rb
261
262
  - spec/dummy/app/models/concerns/.keep
263
+ - spec/dummy/app/models/widget.rb
262
264
  - spec/dummy/app/views/layouts/application.html.erb
263
265
  - spec/dummy/bin/bundle
264
266
  - spec/dummy/bin/rails
@@ -272,7 +274,6 @@ test_files:
272
274
  - spec/dummy/config/environments/development.rb
273
275
  - spec/dummy/config/environments/production.rb
274
276
  - spec/dummy/config/environments/test.rb
275
- - spec/dummy/config/initializers/assets.rb
276
277
  - spec/dummy/config/initializers/backtrace_silencers.rb
277
278
  - spec/dummy/config/initializers/cookies_serializer.rb
278
279
  - spec/dummy/config/initializers/filter_parameter_logging.rb
@@ -284,19 +285,18 @@ test_files:
284
285
  - spec/dummy/config/locales/en.yml
285
286
  - spec/dummy/config/routes.rb
286
287
  - spec/dummy/config/secrets.yml
288
+ - spec/dummy/db/migrate/20230301183442_create_widgets.rb
289
+ - spec/dummy/db/schema.rb
287
290
  - spec/dummy/lib/assets/.keep
288
291
  - spec/dummy/log/.keep
289
292
  - spec/dummy/public/404.html
290
293
  - spec/dummy/public/422.html
291
294
  - spec/dummy/public/500.html
292
295
  - spec/dummy/public/favicon.ico
293
- - spec/gemfiles/52.gemfile
294
- - spec/gemfiles/60.gemfile
295
296
  - spec/lib/paul_bunyan/json_formatter_spec.rb
296
297
  - spec/lib/paul_bunyan/level_spec.rb
297
298
  - spec/lib/paul_bunyan/log_relayer_spec.rb
298
299
  - spec/lib/paul_bunyan/metadata_logging_spec.rb
299
- - spec/lib/paul_bunyan/rails_ext/instrumentation_spec.rb
300
300
  - spec/lib/paul_bunyan/railtie/log_subscriber_spec.rb
301
301
  - spec/lib/paul_bunyan/railtie_spec.rb
302
302
  - spec/lib/paul_bunyan/tagged_logging_spec.rb
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.4
4
- - 2.5
5
- - 2.6
6
- matrix:
7
- exclude:
8
- - rvm: 2.4
9
- gemfile: spec/gemfiles/60.gemfile
10
- fast_finish: true
11
- # WWTD doesn't support allow_failures... yet
12
- # allow_failures:
13
- # - rvm: ruby-head
14
- gemfile:
15
- - spec/gemfiles/52.gemfile
16
- - spec/gemfiles/60.gemfile
17
- script: bundle exec rspec
18
- notifications:
19
- email:
20
- on_success: never
21
- on_failure: never
@@ -1,11 +0,0 @@
1
- require 'active_support/logger'
2
-
3
- # Sad hax but ActiveRecord insists on using this method for console sessions
4
- # and everything uses it in development causing us to get double log lines :-(
5
- module ActiveSupport
6
- class Logger
7
- def self.broadcast(_)
8
- Module.new
9
- end
10
- end
11
- end
@@ -1,41 +0,0 @@
1
- require 'action_controller/metal/instrumentation'
2
-
3
- module ActionController
4
- module Instrumentation
5
- def process_action(*args)
6
- raw_payload = base_payload.merge(custom_payload)
7
-
8
- ActiveSupport::Notifications.instrument('start_processing.action_controller', raw_payload.dup)
9
-
10
- ActiveSupport::Notifications.instrument('process_action.action_controller', raw_payload) do |payload|
11
- begin
12
- result = super
13
- payload[:status] = response.status
14
- result
15
- ensure
16
- append_info_to_payload(payload)
17
- end
18
- end
19
- end
20
-
21
- private
22
-
23
- def base_payload
24
- {
25
- controller: self.class.name,
26
- action: self.action_name,
27
- params: request.filtered_parameters,
28
- format: request.format.try(:ref),
29
- method: request.request_method,
30
- path: (request.filtered_path rescue 'unknown'),
31
- }
32
- end
33
-
34
- def custom_payload
35
- {
36
- request_id: request.env['action_dispatch.request_id'],
37
- ip: request.ip,
38
- }
39
- end
40
- end
41
- end
@@ -1,24 +0,0 @@
1
- require 'rails/rack/logger'
2
-
3
- module Rails
4
- module Rack
5
- class Logger
6
-
7
- # This was copied directly from the rails source and had
8
- # the logging lines removed. N.B. this may break in future
9
- # versions of rails.
10
- def call_app(request, env)
11
- instrumenter = ActiveSupport::Notifications.instrumenter
12
- instrumenter.start 'request.action_dispatch', request: request
13
- resp = @app.call(env)
14
- resp[2] = ::Rack::BodyProxy.new(resp[2]) { finish(request) }
15
- resp
16
- rescue
17
- finish(request)
18
- raise
19
- ensure
20
- ActiveSupport::LogSubscriber.flush_all!
21
- end
22
- end
23
- end
24
- end
@@ -1,8 +0,0 @@
1
- module PaulBunyan
2
- module RailsExt
3
- end
4
- end
5
-
6
- require 'paul_bunyan/rails_ext/rack_logger'
7
- require 'paul_bunyan/rails_ext/instrumentation'
8
- require 'paul_bunyan/rails_ext/active_support_logger'
@@ -1,11 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Version of your assets, change this if you want to expire all your assets.
4
- Rails.application.config.assets.version = '1.0'
5
-
6
- # Add additional assets to the asset load path
7
- # Rails.application.config.assets.paths << Emoji.images_path
8
-
9
- # Precompile additional assets.
10
- # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
11
- # Rails.application.config.assets.precompile += %w( search.js )
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '../../'
4
-
5
- gem 'rails', '~> 5.2.0'
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '../../'
4
-
5
- gem 'rails', '~> 6.0.0'
@@ -1,103 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ActionController::Base do
4
- let(:request_id) { '5ab8b021-71bf-40f9-97cc-136f7b626a66' }
5
-
6
- around :each do |example|
7
- begin
8
- original_logger = PaulBunyan.logger.primary_logger
9
- null_logger = Logger.new('/dev/null')
10
- PaulBunyan.add_logger(null_logger)
11
- PaulBunyan.remove_logger(original_logger)
12
-
13
- example.run
14
- ensure
15
- PaulBunyan.add_logger(original_logger)
16
- PaulBunyan.remove_logger(null_logger)
17
- end
18
- end
19
-
20
- before :each do
21
- subject.request = build_request({
22
- 'action_dispatch.request_id' => request_id,
23
- 'REMOTE_ADDR' => '127.0.0.1',
24
- })
25
- subject.response = ActionDispatch::TestResponse.new
26
-
27
- def subject.index(*args)
28
- head :ok
29
- end
30
- end
31
-
32
-
33
- describe '.process_action(*args)' do
34
- context 'active support notification events' do
35
- before do
36
- allow(ActiveSupport::Notifications).to receive(:instrument)
37
- end
38
-
39
- it 'must emit a start_processing event in the action_controller namespace' do
40
- subject.send(:process_action, :index)
41
- expect(ActiveSupport::Notifications).to have_received(:instrument).
42
- with('start_processing.action_controller', anything).once
43
- end
44
-
45
- it 'must emit a process_action event in the action_controller namespace' do
46
- subject.send(:process_action, :index)
47
- expect(ActiveSupport::Notifications).to have_received(:instrument).
48
- with('process_action.action_controller', anything).once
49
- end
50
- end
51
-
52
- it 'must include the original rails payload keys in the event payload' do
53
- calling_index do |*args|
54
- payload = args.last
55
- expect(payload.keys).to include(
56
- *[:controller, :action, :params, :format, :method, :path]
57
- )
58
- end
59
- end
60
-
61
- it 'must add the request id to the notification payload hash' do
62
- calling_index do |*args|
63
- payload = args.last
64
- expect(payload).to include request_id: request_id
65
- end
66
- end
67
-
68
- it 'must add the request ip address to the notification payload' do
69
- calling_index do |*args|
70
- payload = args.last
71
- expect(payload).to include ip: '127.0.0.1'
72
- end
73
- end
74
-
75
- context 'with sensitive info in the query params' do
76
- before do
77
- subject.request = build_request({
78
- 'action_dispatch.parameter_filter' => [:password, :baz],
79
- 'PATH_INFO' => '/somewhere',
80
- 'QUERY_STRING' => 'password=foo&bar=baz&baz=qux',
81
- })
82
- end
83
-
84
- it 'filters the sensitive params' do
85
- calling_index do |*args|
86
- payload = args.last
87
- expect(payload).to include path: '/somewhere?password=[FILTERED]&bar=baz&baz=[FILTERED]'
88
- end
89
- end
90
- end
91
- end
92
-
93
- def build_request(attrs)
94
- factory_method = (Rails.version >= '5.0' ? :create : :new)
95
- ActionDispatch::TestRequest.send(factory_method, attrs)
96
- end
97
-
98
- def calling_index(&block)
99
- with_subscription_to('process_action.action_controller', block) do
100
- subject.send(:process_action, :index)
101
- end
102
- end
103
- end