rack-request-object-logger 3.0.3 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f88b6570bfb9f0ce097804e7251033d148625664ed132ce82f9ed451786881b
4
- data.tar.gz: 3c3944e7642717a2e4f11cf8f4f4386fcb0e5f140cfa751ae3484cc66341aafa
3
+ metadata.gz: f2df7642c85cddc3a1947c7d3b7191fcbee553877a19ca47ffd9b3a46a5bc0fa
4
+ data.tar.gz: 571cf74cb5555caf7d620c109e9b037cbf3a6330a44b354e44e5b1fd2c89b3b6
5
5
  SHA512:
6
- metadata.gz: bbba4358191665de50681e94fb9e9af6406facf9388cd2065c9bb03e99c74a5716306efcbc8ea369ef0bbfee77a2159aaafd8e0041a9f5448a479f3c89b4b918
7
- data.tar.gz: 669313528821b1bc40985ae94d6eafe5d209f94c3300f09036c860fdc64c93e48b1bd6946c5f7639a8661263a762bda4dc2e57e274e7dfb16434d3cb55775b0b
6
+ metadata.gz: b43ceb51e1f0db58d96b83988a925e790b9dd5051acd203e980c0b4b3962976669f23518129c4d155619ad25f100f6d3c71cd0ec655657d5d7031370b24a4c0e
7
+ data.tar.gz: 12254a4a8c854a1da0583c5a329e229f5169f8b538023732c693b7a8ca2abc3db7a490c6914c7950946c544e5933930179499e4d1e2d42f9a2b765b9262841b5
@@ -0,0 +1,26 @@
1
+ name: github-actions-rails
2
+
3
+ on:
4
+ pull_request:
5
+ branches: ['*']
6
+ push:
7
+ branches: [master]
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', head, truffleruby, truffleruby-head]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - name: Set up Ruby ${{ matrix.ruby }}
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby }}
21
+ bundler: default
22
+ bundler-cache: true
23
+ - name: Run tests
24
+ env:
25
+ RAILS_ENV: test
26
+ run: bundle exec rake
data/README.md CHANGED
@@ -1,14 +1,12 @@
1
- [![Build Status](http://img.shields.io/travis/istana/rack-request-object-logger.svg?style=flat-square)](https://travis-ci.org/istana/rack-request-object-logger)
1
+ ![example workflow](https://github.com/istana/rack-request-object-logger/actions/workflows/ruby.yml/badge.svg)
2
2
  [![Gem Version](http://img.shields.io/gem/v/rack-request-object-logger.svg?style=flat-square)](https://rubygems.org/gems/rack-request-object-logger)
3
3
  [![License](http://img.shields.io/:license-apache-blue.svg?style=flat-square)](http://www.apache.org/licenses/LICENSE-2.0.html)
4
4
 
5
5
  # rack-request-object-logger
6
6
 
7
- **Human description:** I created this to log all HTTP requests from my Rails application into MySQL database automatically. Then process and search via ElasticSearch.
7
+ The project is a Rack middleware to automatically log a HTTP request to a custom object.
8
8
 
9
- **General concept:** Log HTTP requests via Rack stack to an object. Use any object, because logger uses dependency injection in the constructor. Be independent from Rails.
10
-
11
- Don't be confused with no commits in months or years. Rack middlewares rarely change. They just work.
9
+ There might be no commits in months or years. Rack middlewares rarely change.
12
10
 
13
11
  ## Install gem
14
12
 
@@ -24,9 +22,9 @@ gem 'rack-request-object-logger'
24
22
 
25
23
  ## Rubies Support
26
24
 
27
- Tested with Matz Ruby 2.5, 2.6 and Truffleruby.
25
+ Tested with Matz Ruby 2.7, 3.0, 3.1, 3.2, 3.3, head, and ruffleruby, truffleruby-head.
28
26
 
29
- Should work with Ruby 2.1+, jRuby and Rubinius 3.69+ (is dead!) and Truffleruby.
27
+ Should work also with jRuby, just sqlite3 adapter supports only Rails 7 and tests require a more recent Rails.
30
28
 
31
29
  ## Roadmap
32
30
 
@@ -39,26 +37,13 @@ Bug: I learned at EuRuKo 2018 that my implementation of timings is wrong and not
39
37
  generate a model for storage
40
38
 
41
39
  ```bash
42
- # you need to add 'limit: 6' to application_server_request_start and application_server_request_end
43
- # to have subsecond resolution please see examples/db/migrate/
44
- $ bin/rails g model AnalyticsHttpRequest uid:string data:text status_code:integer application_server_request_start:datetime application_server_request_end:datetime
45
-
46
- ```
47
-
48
- add JSON serialization
49
-
50
- ```ruby
51
- # app/models/analytics_http_request.rb
52
- class AnalyticsHttpRequest < ApplicationRecord
53
- serialize :data, JSON
54
- end
55
-
40
+ $ bin/rails g model AnalyticsRequest uid:string data:jsonb status_code:integer application_server_request_start:datetime application_server_request_end:datetime
56
41
  ```
57
42
 
58
43
  add automatic logging via initializer
59
44
 
60
45
  ```ruby
61
- # config/initializers/rack_middlewares.rb
46
+ # config/initializers/log_requests.rb
62
47
 
63
48
  Rails.application.config.middleware.use(RackRequestObjectLogger, AnalyticsHttpRequest)
64
49
  ```
@@ -79,7 +64,7 @@ I've seen applications sending sensitive data in GET and even POST requests in a
79
64
 
80
65
  ## License & Author
81
66
 
82
- Copyright 2016-2019 Ivan Stana
67
+ Copyright 2016-2024 Ivan Stana
83
68
 
84
69
  Licensed under the Apache License, Version 2.0 (the "License");
85
70
  you may not use this file except in compliance with the License.
data/Rakefile CHANGED
@@ -1,6 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.pattern = 'spec'
6
+ end
5
7
 
6
- task :default => :spec
8
+ RSpec::Core::RakeTask.new(:spec_performance) do |t|
9
+ t.pattern = 'performance'
10
+ end
11
+
12
+ task :default => [:spec, :spec_performance]
@@ -0,0 +1,9 @@
1
+ require Rails.root.join('app', 'models', 'application_record').to_s
2
+ require Rails.root.join('app', 'models', 'analytics_request').to_s
3
+
4
+ Rails.configuration.before_initialize do
5
+ Rails.application.config.middleware.use(
6
+ RackRequestObjectLogger,
7
+ ::AnalyticsRequest
8
+ )
9
+ end
@@ -0,0 +1,14 @@
1
+ class CreateAnalyticsRequests < ActiveRecord::Migration[7.2]
2
+ def change
3
+ create_table :analytics_requests, id: :uuid do |t|
4
+ t.text :uid
5
+ t.json :data
6
+ t.integer :status_code
7
+ t.datetime :application_server_request_start
8
+ t.datetime :application_server_request_end
9
+ t.references :requestable, polymorphic: true, null: true, type: :uuid, index: true
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ class AnalyticsRequest < ::ApplicationRecord
2
+ belongs_to :requestable, polymorphic: true, required: false
3
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class RackRequestObjectLogger
3
- VERSION = "3.0.3"
3
+ VERSION = "4.0.0"
4
4
  end
@@ -17,8 +17,7 @@ class RackRequestObjectLogger
17
17
  logger_object = @model.new
18
18
  logger_object.application_server_request_start = start_time
19
19
  logger_object.application_server_request_end = end_time
20
- request = Rack::Request.new(env)
21
- logger_object.data = request.env.select do |header, value|
20
+ logger_object.data = env.select do |header, value|
22
21
  # don't bother with values other than a string
23
22
  next if !value.is_a?(String)
24
23
  # https://tools.ietf.org/html/rfc3875 CGI 1.1 spec
@@ -38,7 +37,7 @@ class RackRequestObjectLogger
38
37
  ].include?(header) || ['HTTP', 'HTTPS'].include?(header) || header =~ /\AHTTP_\w+\z/ ||
39
38
  ['REQUEST_URI', 'ORIGINAL_FULLPATH', 'ORIGINAL_SCRIPT_NAME'].include?(header)
40
39
  end
41
- logger_object.uid = request.env['action_dispatch.request_id'] || SecureRandom.uuid
40
+ logger_object.uid = env['action_dispatch.request_id'] || SecureRandom.uuid
42
41
  logger_object.status_code = app_result.first
43
42
  logger_object.save
44
43
  app_result
@@ -11,25 +11,31 @@ Gem::Specification.new do |spec|
11
11
  spec.authors = ["Ivan Stana"]
12
12
  spec.email = ["ronon@myrtana.sk"]
13
13
 
14
- spec.summary = %q{Log HTTP requests via Rack stack to an object. You can use any object.}
15
- spec.description = %q{Log HTTP requests via Rack stack to an object. You can use any object, i.e. ActiveRecord model}
16
- spec.homepage = "https://github.com/starmammoth/rack-request-object-logger"
14
+ spec.summary = %q{The project is a Rack middleware to automatically log a HTTP request to a custom object.}
15
+ spec.description = %q{The project is a Rack middleware to automatically log a HTTP request to a custom object.}
16
+ spec.homepage = "https://github.com/istana/rack-request-object-logger"
17
17
  spec.license = "Apache-2.0"
18
18
 
19
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
- f.match(%r{^(test|spec|features)/})
20
+ f.match(%r{^(test|spec|features|performance)/})
21
21
  end
22
- spec.bindir = "exe"
23
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
22
  spec.require_paths = ["lib"]
25
23
 
26
- spec.add_dependency "rack", "> 0", "< 3.0"
24
+ spec.metadata = {
25
+ "bug_tracker_uri" => "https://github.com/istana/rack-request-object-logger/issues",
26
+ "homepage_uri" => "https://github.com/istana/rack-request-object-logger",
27
+ "source_code_uri" => "https://github.com/istana/rack-request-object-logger",
28
+ }
29
+
30
+ spec.add_dependency "rack", "> 0", "< 4.0"
27
31
  spec.add_development_dependency "bundler", "~> 2.0"
28
- spec.add_development_dependency "rake", "~> 12.3"
29
- spec.add_development_dependency "rspec", "~> 3.8"
32
+ spec.add_development_dependency "rake", "~> 13"
33
+ spec.add_development_dependency "rspec", "~> 3.13"
30
34
  spec.add_development_dependency "rspec-benchmark", "~> 0"
31
35
  spec.add_development_dependency "pry", "~> 0"
32
- spec.add_development_dependency "activerecord", '>= 6.0', "< 7.0"
33
- spec.add_development_dependency "sqlite3", "~> 1.4" unless RUBY_PLATFORM == 'java'
34
- spec.add_development_dependency "mysql2", "~> 0.5" unless RUBY_PLATFORM == 'java'
36
+ spec.add_development_dependency "activerecord", '>= 6.0', "< 8.0"
37
+ spec.add_development_dependency "sqlite3", "<= 2.1" unless RUBY_PLATFORM == "java"
35
38
  end
39
+
40
+
41
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-request-object-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Stana
8
- autorequire:
9
- bindir: exe
8
+ autorequire:
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-19 00:00:00.000000000 Z
11
+ date: 2024-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '3.0'
22
+ version: '4.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '3.0'
32
+ version: '4.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -50,28 +50,28 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '12.3'
53
+ version: '13'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '12.3'
60
+ version: '13'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '3.8'
67
+ version: '3.13'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '3.8'
74
+ version: '3.13'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rspec-benchmark
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '6.0'
110
110
  - - "<"
111
111
  - !ruby/object:Gem::Version
112
- version: '7.0'
112
+ version: '8.0'
113
113
  type: :development
114
114
  prerelease: false
115
115
  version_requirements: !ruby/object:Gem::Requirement
@@ -119,46 +119,32 @@ dependencies:
119
119
  version: '6.0'
120
120
  - - "<"
121
121
  - !ruby/object:Gem::Version
122
- version: '7.0'
122
+ version: '8.0'
123
123
  - !ruby/object:Gem::Dependency
124
124
  name: sqlite3
125
125
  requirement: !ruby/object:Gem::Requirement
126
126
  requirements:
127
- - - "~>"
127
+ - - "<="
128
128
  - !ruby/object:Gem::Version
129
- version: '1.4'
129
+ version: '2.1'
130
130
  type: :development
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
- - - "~>"
135
- - !ruby/object:Gem::Version
136
- version: '1.4'
137
- - !ruby/object:Gem::Dependency
138
- name: mysql2
139
- requirement: !ruby/object:Gem::Requirement
140
- requirements:
141
- - - "~>"
142
- - !ruby/object:Gem::Version
143
- version: '0.5'
144
- type: :development
145
- prerelease: false
146
- version_requirements: !ruby/object:Gem::Requirement
147
- requirements:
148
- - - "~>"
134
+ - - "<="
149
135
  - !ruby/object:Gem::Version
150
- version: '0.5'
151
- description: Log HTTP requests via Rack stack to an object. You can use any object,
152
- i.e. ActiveRecord model
136
+ version: '2.1'
137
+ description: The project is a Rack middleware to automatically log a HTTP request
138
+ to a custom object.
153
139
  email:
154
140
  - ronon@myrtana.sk
155
141
  executables: []
156
142
  extensions: []
157
143
  extra_rdoc_files: []
158
144
  files:
145
+ - ".github/workflows/ruby.yml"
159
146
  - ".gitignore"
160
147
  - ".rspec"
161
- - ".travis.yml"
162
148
  - CODE_OF_CONDUCT.md
163
149
  - Gemfile
164
150
  - LICENSE
@@ -166,20 +152,20 @@ files:
166
152
  - Rakefile
167
153
  - bin/console
168
154
  - bin/setup
169
- - examples/rails5/app/models/http_request.rb
170
- - examples/rails5/config/log_http_request.rb
171
- - examples/rails5/db/migrate/20170211004327_create_http_requests.rb
155
+ - examples/rails7/config/initializers/log_http_request.rb
156
+ - examples/rails7/db/migrate/20240917151639_create_analytics_requests.rb
157
+ - examples/rails7/models/analytics_request.rb
172
158
  - lib/rack-request-object-logger.rb
173
159
  - lib/rack-request-object-logger/version.rb
174
- - performance/active_record_model_spec.rb
175
- - performance/in_memory_model_spec.rb
176
- - performance/performance_helper.rb
177
160
  - rack-request-object-logger.gemspec
178
- homepage: https://github.com/starmammoth/rack-request-object-logger
161
+ homepage: https://github.com/istana/rack-request-object-logger
179
162
  licenses:
180
163
  - Apache-2.0
181
- metadata: {}
182
- post_install_message:
164
+ metadata:
165
+ bug_tracker_uri: https://github.com/istana/rack-request-object-logger/issues
166
+ homepage_uri: https://github.com/istana/rack-request-object-logger
167
+ source_code_uri: https://github.com/istana/rack-request-object-logger
168
+ post_install_message:
183
169
  rdoc_options: []
184
170
  require_paths:
185
171
  - lib
@@ -194,8 +180,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
180
  - !ruby/object:Gem::Version
195
181
  version: '0'
196
182
  requirements: []
197
- rubygems_version: 3.0.3
198
- signing_key:
183
+ rubygems_version: 3.5.16
184
+ signing_key:
199
185
  specification_version: 4
200
- summary: Log HTTP requests via Rack stack to an object. You can use any object.
186
+ summary: The project is a Rack middleware to automatically log a HTTP request to a
187
+ custom object.
201
188
  test_files: []
data/.travis.yml DELETED
@@ -1,18 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- services:
4
- - mysql
5
- rvm:
6
- - 2.5.4
7
- - 2.6.3
8
- - truffleruby
9
- before_install:
10
- - gem update --system
11
- - gem install bundler
12
- cache: bundler
13
- matrix:
14
- include:
15
- - rvm: ruby-head
16
- allow_failures:
17
- - rvm: ruby-head
18
- fast_finish: true
@@ -1,3 +0,0 @@
1
- class AnaylticsHttpRequest < ApplicationRecord
2
- serialize :data, JSON
3
- end
@@ -1 +0,0 @@
1
- Rails.application.config.middleware.use "RackRequestObjectLogger", AnalyticsHttpRequest
@@ -1,15 +0,0 @@
1
- class CreateAnalyticsHttpRequests < ActiveRecord::Migration[5.0]
2
- def change
3
- create_table :analytics_http_requests do |t|
4
- t.string :uid
5
- t.text :data
6
- t.integer :status_code
7
- # with limit: 6 we will store nanosecond resolution
8
- # for statistics and performance monitoring sub-second resolution is a must
9
- t.datetime :application_server_request_start, limit: 6
10
- t.datetime :application_server_request_end, limit: 6
11
-
12
- t.timestamps
13
- end
14
- end
15
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
- require_relative 'performance_helper'
3
- require_relative '../spec/spec_data'
4
- require 'active_record'
5
-
6
- RSpec.describe "Performance testing with an ActiveRecord class and SQLite3 database", performance: true do
7
- include RSpec::Benchmark::Matchers
8
- include_context 'spec_data'
9
-
10
- class RequestActiveRecordLog < ActiveRecord::Base
11
- serialize :headers, JSON
12
- end
13
-
14
- class CreateRequestActiveRecordLog < ActiveRecord::Migration[4.2]
15
- def change
16
- create_table :request_active_record_logs do |t|
17
- t.integer :uid
18
- t.text :data
19
- t.time :application_server_request_start
20
- t.time :application_server_request_end
21
- end
22
- end
23
- end
24
-
25
- let(:app) { proc{ [200, {}, ['Hello, world.']] } }
26
- let(:stack) { RackRequestObjectLogger.new(app, RequestActiveRecordLog) }
27
- let(:request) { Rack::MockRequest.new(stack) }
28
-
29
- after { File.unlink 'active_record_performance.sqlite3' }
30
-
31
- it 'much fast. wow' do
32
- set_headers(rails5_puma_headers)
33
-
34
- ActiveRecord::Base.establish_connection(
35
- adapter: 'sqlite3',
36
- database: 'active_record_performance.sqlite3'
37
- )
38
- CreateRequestActiveRecordLog.migrate(:up)
39
- expect { request.get('http://localhost:4000/doge') }.to perform_at_least(500).ips
40
- end
41
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
- require_relative 'performance_helper'
3
- require_relative '../spec/spec_data'
4
-
5
- RSpec.describe "Performance testing with a dummy class", performance: true do
6
- include RSpec::Benchmark::Matchers
7
- include_context 'spec_data'
8
-
9
- let(:app) { proc{ [200, {}, ['Hello, world.']] } }
10
- let(:stack) { RackRequestObjectLogger.new(app, RequestDummyLog) }
11
- let(:request) { Rack::MockRequest.new(stack) }
12
-
13
- let(:logger_object) { RequestDummyLog.new }
14
- before { allow(RequestDummyLog).to receive(:new).and_return(logger_object) }
15
-
16
- it 'much fast. wow' do
17
- set_headers(rails5_puma_headers)
18
- expect { request.get('http://localhost:4000/doge') }.to perform_at_least(5000).ips
19
- end
20
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'bundler/setup'
3
- require 'rspec-benchmark'
4
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
5
- require "rack-request-object-logger"