Skip to content

Commit 42342c5

Browse files
committed
fixed all integration test issues
1 parent c3738e9 commit 42342c5

21 files changed

Lines changed: 414 additions & 161 deletions

File tree

.cspell/project-words.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Healthcheck
1919
Honeybadger
2020
hotwire
2121
hrefs
22+
kamal
2223
klass
2324
kwargs
2425
lightningcss

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.4.2
1+
3.4.5

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [0.1.0] - 2025-09-07
99

10-
Initial release.
10+
Initial beta release.

Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ unless ENV["RUBY_VERSION"]
1111
ruby File.read(File.expand_path(".ruby-version", __dir__)).strip
1212
end
1313

14-
gem "rails", "~> #{ENV["RAILS_VERSION"] || "7.2.2.1"}", require: false
14+
# Use a stable Rails for gem development/test environment.
15+
# Rails version for the generated test app is controlled by RAILS_VERSION in rails_tests.
16+
gem "rails", "~> 8.0.2.1", require: false
1517

1618
# Add these gems to silence Ruby 3.4+ warnings
1719
gem "bigdecimal"

Gemfile.lock

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,45 @@ PATH
1010
GEM
1111
remote: https://rubygems.org/
1212
specs:
13-
actioncable (7.2.2.1)
14-
actionpack (= 7.2.2.1)
15-
activesupport (= 7.2.2.1)
13+
actioncable (8.0.2.1)
14+
actionpack (= 8.0.2.1)
15+
activesupport (= 8.0.2.1)
1616
nio4r (~> 2.0)
1717
websocket-driver (>= 0.6.1)
1818
zeitwerk (~> 2.6)
19-
actionmailbox (7.2.2.1)
20-
actionpack (= 7.2.2.1)
21-
activejob (= 7.2.2.1)
22-
activerecord (= 7.2.2.1)
23-
activestorage (= 7.2.2.1)
24-
activesupport (= 7.2.2.1)
19+
actionmailbox (8.0.2.1)
20+
actionpack (= 8.0.2.1)
21+
activejob (= 8.0.2.1)
22+
activerecord (= 8.0.2.1)
23+
activestorage (= 8.0.2.1)
24+
activesupport (= 8.0.2.1)
2525
mail (>= 2.8.0)
26-
actionmailer (7.2.2.1)
27-
actionpack (= 7.2.2.1)
28-
actionview (= 7.2.2.1)
29-
activejob (= 7.2.2.1)
30-
activesupport (= 7.2.2.1)
26+
actionmailer (8.0.2.1)
27+
actionpack (= 8.0.2.1)
28+
actionview (= 8.0.2.1)
29+
activejob (= 8.0.2.1)
30+
activesupport (= 8.0.2.1)
3131
mail (>= 2.8.0)
3232
rails-dom-testing (~> 2.2)
33-
actionpack (7.2.2.1)
34-
actionview (= 7.2.2.1)
35-
activesupport (= 7.2.2.1)
33+
actionpack (8.0.2.1)
34+
actionview (= 8.0.2.1)
35+
activesupport (= 8.0.2.1)
3636
nokogiri (>= 1.8.5)
37-
racc
38-
rack (>= 2.2.4, < 3.2)
37+
rack (>= 2.2.4)
3938
rack-session (>= 1.0.1)
4039
rack-test (>= 0.6.3)
4140
rails-dom-testing (~> 2.2)
4241
rails-html-sanitizer (~> 1.6)
4342
useragent (~> 0.16)
44-
actiontext (7.2.2.1)
45-
actionpack (= 7.2.2.1)
46-
activerecord (= 7.2.2.1)
47-
activestorage (= 7.2.2.1)
48-
activesupport (= 7.2.2.1)
43+
actiontext (8.0.2.1)
44+
actionpack (= 8.0.2.1)
45+
activerecord (= 8.0.2.1)
46+
activestorage (= 8.0.2.1)
47+
activesupport (= 8.0.2.1)
4948
globalid (>= 0.6.0)
5049
nokogiri (>= 1.8.5)
51-
actionview (7.2.2.1)
52-
activesupport (= 7.2.2.1)
50+
actionview (8.0.2.1)
51+
activesupport (= 8.0.2.1)
5352
builder (~> 3.1)
5453
erubi (~> 1.11)
5554
rails-dom-testing (~> 2.2)
@@ -59,22 +58,22 @@ GEM
5958
activemodel (>= 4.1)
6059
case_transform (>= 0.2)
6160
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
62-
activejob (7.2.2.1)
63-
activesupport (= 7.2.2.1)
61+
activejob (8.0.2.1)
62+
activesupport (= 8.0.2.1)
6463
globalid (>= 0.3.6)
65-
activemodel (7.2.2.1)
66-
activesupport (= 7.2.2.1)
67-
activerecord (7.2.2.1)
68-
activemodel (= 7.2.2.1)
69-
activesupport (= 7.2.2.1)
64+
activemodel (8.0.2.1)
65+
activesupport (= 8.0.2.1)
66+
activerecord (8.0.2.1)
67+
activemodel (= 8.0.2.1)
68+
activesupport (= 8.0.2.1)
7069
timeout (>= 0.4.0)
71-
activestorage (7.2.2.1)
72-
actionpack (= 7.2.2.1)
73-
activejob (= 7.2.2.1)
74-
activerecord (= 7.2.2.1)
75-
activesupport (= 7.2.2.1)
70+
activestorage (8.0.2.1)
71+
actionpack (= 8.0.2.1)
72+
activejob (= 8.0.2.1)
73+
activerecord (= 8.0.2.1)
74+
activesupport (= 8.0.2.1)
7675
marcel (~> 1.0)
77-
activesupport (7.2.2.1)
76+
activesupport (8.0.2.1)
7877
base64
7978
benchmark (>= 0.3)
8079
bigdecimal
@@ -86,6 +85,7 @@ GEM
8685
minitest (>= 5.1)
8786
securerandom (>= 0.3)
8887
tzinfo (~> 2.0, >= 2.0.5)
88+
uri (>= 0.13.1)
8989
addressable (2.8.7)
9090
public_suffix (>= 2.0.2, < 7.0)
9191
ahoy_matey (5.4.0)
@@ -225,38 +225,38 @@ GEM
225225
stringio
226226
public_suffix (6.0.1)
227227
racc (1.8.1)
228-
rack (3.1.11)
228+
rack (3.1.16)
229229
rack-session (2.1.1)
230230
base64 (>= 0.1.0)
231231
rack (>= 3.0.0)
232232
rack-test (2.2.0)
233233
rack (>= 1.3)
234234
rackup (2.2.1)
235235
rack (>= 3)
236-
rails (7.2.2.1)
237-
actioncable (= 7.2.2.1)
238-
actionmailbox (= 7.2.2.1)
239-
actionmailer (= 7.2.2.1)
240-
actionpack (= 7.2.2.1)
241-
actiontext (= 7.2.2.1)
242-
actionview (= 7.2.2.1)
243-
activejob (= 7.2.2.1)
244-
activemodel (= 7.2.2.1)
245-
activerecord (= 7.2.2.1)
246-
activestorage (= 7.2.2.1)
247-
activesupport (= 7.2.2.1)
236+
rails (8.0.2.1)
237+
actioncable (= 8.0.2.1)
238+
actionmailbox (= 8.0.2.1)
239+
actionmailer (= 8.0.2.1)
240+
actionpack (= 8.0.2.1)
241+
actiontext (= 8.0.2.1)
242+
actionview (= 8.0.2.1)
243+
activejob (= 8.0.2.1)
244+
activemodel (= 8.0.2.1)
245+
activerecord (= 8.0.2.1)
246+
activestorage (= 8.0.2.1)
247+
activesupport (= 8.0.2.1)
248248
bundler (>= 1.15.0)
249-
railties (= 7.2.2.1)
249+
railties (= 8.0.2.1)
250250
rails-dom-testing (2.2.0)
251251
activesupport (>= 5.0.0)
252252
minitest
253253
nokogiri (>= 1.6)
254254
rails-html-sanitizer (1.6.2)
255255
loofah (~> 2.21)
256256
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
257-
railties (7.2.2.1)
258-
actionpack (= 7.2.2.1)
259-
activesupport (= 7.2.2.1)
257+
railties (8.0.2.1)
258+
actionpack (= 8.0.2.1)
259+
activesupport (= 8.0.2.1)
260260
irb (~> 1.13)
261261
rackup (>= 1.0.0)
262262
rake (>= 12.2)
@@ -402,6 +402,7 @@ GEM
402402
unicode-display_width (3.1.4)
403403
unicode-emoji (~> 4.0, >= 4.0.4)
404404
unicode-emoji (4.0.4)
405+
uri (1.0.3)
405406
useragent (0.16.11)
406407
websocket-driver (0.7.7)
407408
base64
@@ -428,7 +429,7 @@ PLATFORMS
428429

429430
DEPENDENCIES
430431
active_model_serializers (~> 0.10.13)
431-
ahoy_matey (~> 5.2)
432+
ahoy_matey (>= 4.1, < 6.0)
432433
amazing_print
433434
bigdecimal
434435
bugsnag (~> 6.26)
@@ -445,7 +446,7 @@ DEPENDENCIES
445446
minitest-reporters (~> 1.6)
446447
mutex_m
447448
ostruct
448-
rails (~> 7.2.2.1)
449+
rails (~> 8.0.2.1)
449450
redcarpet
450451
rollbar (~> 3.4)
451452
rubocop
@@ -466,7 +467,7 @@ DEPENDENCIES
466467
yard-sorbet
467468

468469
RUBY VERSION
469-
ruby 3.4.2p28
470+
ruby 3.4.5p51
470471

471472
BUNDLED WITH
472-
2.6.5
473+
2.7.1

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,29 @@ Please see the [documentation](https://logstruct.com/docs/configuration/) for co
4848

4949
### Important Notes on Integration
5050

51-
Once initialized, the gem automatically includes its modules into the appropriate base classes:
51+
Once initialized (and enabled), the gem automatically includes its modules into the appropriate base classes:
5252

53-
- `ActiveSupport::TaggedLogging` is patched to support both Hashes and Strings
53+
- `ActiveSupport::TaggedLogging` is patched to support both Hashes and Strings (only when LogStruct is enabled)
5454
- `ActionMailer::Base` includes error handling and event logging modules
5555
- We configure `Lograge` for request logging
5656
- A Rack middleware is inserted to catch and log errors, including security violations (IP spoofing, CSRF, blocked hosts, etc.)
5757
- Structured logging is set up for ActiveJob, Sidekiq, Shrine, etc.
5858
- Rails `config.filter_parameters` are merged into LogStruct's filters and then cleared (to avoid double filtering). Configure sensitive keys via `LogStruct.config.filters`.
5959
- When `RAILS_LOG_TO_STDOUT` is set, we log to STDOUT only. Otherwise, we log to STDOUT by default without adding a file appender to avoid duplicate logs.
6060

61+
### Development behavior
62+
63+
- Disabled by default in development. Enable explicitly via `LOGSTRUCT_ENABLED=true` or `LogStruct.configure { |c| c.enabled = true }`.
64+
- When enabled in development, LogStruct now defaults to production‑style JSON output so you can preview exactly what will be shipped in prod.
65+
- You can opt back into the colorful human formatter with:
66+
67+
```ruby
68+
LogStruct.configure do |c|
69+
c.integrations.prefer_json_in_development = false
70+
c.integrations.enable_color_output = true
71+
end
72+
```
73+
6174
## Documentation
6275

6376
Please see the [documentation](https://logstruct.com/docs) for more details. (All code examples are type-checked and tested, and it's harder to keep a README up to date.)

Rakefile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "bundler/gem_tasks"
4+
require "rake/file_utils"
45
require "rake/testtask"
56
require "fileutils"
67

@@ -16,12 +17,5 @@ end
1617
# Load Sorbet tasks
1718
Dir.glob("tasks/*.rake").each { |r| load r }
1819

19-
# Rails application integration tests
20-
desc "Run Rails integration tests"
21-
task :rails_tests do
22-
script_path = File.expand_path("scripts/rails_tests.sh", __dir__)
23-
system(script_path) || abort("Rails tests failed")
24-
end
25-
2620
# Default task runs tests and type checking
2721
task default: [:test, "sorbet:typecheck"]

lib/log_struct.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
require "log_struct/concerns/configuration"
1313
require "log_struct/concerns/logging"
1414

15-
# Monkey-patch ActiveSupport::TaggedLogging::Formatter to support hash input/output
16-
require "log_struct/monkey_patches/active_support/tagged_logging/formatter"
17-
1815
# Require integrations
1916
require "log_struct/integrations"
2017

lib/log_struct/config_struct/integrations.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ class Integrations < T::Struct
6464
# Default: true
6565
prop :enable_color_output, T::Boolean, default: true
6666

67+
# Prefer production-style JSON output in development when LogStruct is enabled.
68+
# This makes it easy to preview exactly what production logs will look like
69+
# when you opt-in to LogStruct locally (via LOGSTRUCT_ENABLED=true or config).
70+
# Default: true
71+
prop :prefer_json_in_development, T::Boolean, default: true
72+
6773
# Color configuration for JSON output
6874
# Default: nil (uses SemanticLogger defaults)
6975
prop :color_map, T.nilable(T::Hash[Symbol, Symbol]), default: nil

lib/log_struct/integrations/lograge.rb

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,30 @@ def configure_lograge(logstruct_config)
3838
# The struct is converted to JSON by our Formatter (after filtering, etc.)
3939
config.lograge.formatter = T.let(
4040
lambda do |data|
41+
# Coerce common fields to expected types
42+
status = ((s = data[:status]) && s.respond_to?(:to_i)) ? s.to_i : s
43+
duration = ((d = data[:duration]) && d.respond_to?(:to_f)) ? d.to_f : d
44+
view = ((v = data[:view]) && v.respond_to?(:to_f)) ? v.to_f : v
45+
db = ((b = data[:db]) && b.respond_to?(:to_f)) ? b.to_f : b
46+
47+
params = data[:params]
48+
params = params.deep_symbolize_keys if params&.respond_to?(:deep_symbolize_keys)
49+
4150
# Convert the data hash to a Log::Request struct
4251
Log::Request.new(
4352
source: Source::Rails,
4453
event: Event::Request,
4554
timestamp: Time.now,
46-
http_method: data[:method],
47-
path: data[:path],
48-
format: data[:format],
49-
controller: data[:controller],
50-
action: data[:action],
51-
status: data[:status],
52-
duration: data[:duration],
53-
view: data[:view],
54-
db: data[:db],
55-
params: data[:params]
55+
http_method: data[:method]&.to_s,
56+
path: data[:path]&.to_s,
57+
format: data[:format]&.to_s,
58+
controller: data[:controller]&.to_s,
59+
action: data[:action]&.to_s,
60+
status: status,
61+
duration: duration,
62+
view: view,
63+
db: db,
64+
params: params
5665
)
5766
end,
5867
T.proc.params(hash: T::Hash[Symbol, T.untyped]).returns(Log::Request)

0 commit comments

Comments
 (0)