logstruct 0.2.0 → 0.2.1
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/log_struct/integrations/lograge.rb +41 -0
- data/lib/log_struct/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 23182266ea1c9f53e0b824a8b806207b92255ed6a6d2755cf67c8f3d35680d19
|
|
4
|
+
data.tar.gz: 4d684c903461a10aa875314f6dac3fca9978ac190ce0616c3f6d34076c3b8ba7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4a3dc3b56efac2d68703b77210006852059188425e612f537be307e7740da79781600dc4147d955c52c0e65a39978d476fefd0a796b07b7fe5ee170d2ce5b07a
|
|
7
|
+
data.tar.gz: bb328f655eda7dbcfb2ace155586966bfc47a4a60df88dcb7aa2e355b5213f0e76623d52e83906063a5aaff63039c8937c59bdd373c783faa7013a7c860acfac
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.2.1] - 2026-10-18
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **Lograge**: With `config.exceptions_app = routes`, a request whose action raises has one request line, the action's: the error page's controller no longer logs a second line as `GET /500`. When the error comes before any action (a routing error) or after it (in a middleware), the error page's line has the request's own method and path instead of `GET /404` (#28)
|
|
13
|
+
|
|
8
14
|
## [0.2.0] - 2026-10-18
|
|
9
15
|
|
|
10
16
|
### Changed
|
|
@@ -36,6 +36,20 @@ module LogStruct
|
|
|
36
36
|
T::Array[Symbol]
|
|
37
37
|
)
|
|
38
38
|
|
|
39
|
+
# With config.exceptions_app = routes, Rails renders an error page by sending the request through the app again
|
|
40
|
+
# as GET /<status>, and keeps the request's own method and path in these headers
|
|
41
|
+
ORIGINAL_METHOD_HEADER = "action_dispatch.original_request_method"
|
|
42
|
+
ORIGINAL_PATH_HEADER = "action_dispatch.original_path"
|
|
43
|
+
# Set when the request's action logged a line with its error, so the error page for it logs none
|
|
44
|
+
ACTION_ERROR_LOGGED_HEADER = "logstruct.action_error_logged"
|
|
45
|
+
|
|
46
|
+
# A Proc, not a Method: sorbet-runtime replaces a method with sig checks on its first call, so a Method taken
|
|
47
|
+
# before then isn't equal to one taken after, and setup couldn't tell it had added the test already
|
|
48
|
+
IGNORE_REPEATED_ERROR_PAGE = T.let(
|
|
49
|
+
->(event) { Lograge.repeated_error_page?(event) },
|
|
50
|
+
T.proc.params(event: ActiveSupport::Notifications::Event).returns(T::Boolean)
|
|
51
|
+
)
|
|
52
|
+
|
|
39
53
|
class << self
|
|
40
54
|
extend T::Sig
|
|
41
55
|
|
|
@@ -77,6 +91,9 @@ module LogStruct
|
|
|
77
91
|
Integrations::Lograge.unsubscribe_rails_request_lines unless app.config.lograge.keep_original_rails_log
|
|
78
92
|
end
|
|
79
93
|
end
|
|
94
|
+
|
|
95
|
+
# Lograge.setup adds the app's own ignore tests to the same list
|
|
96
|
+
::Lograge.ignore(IGNORE_REPEATED_ERROR_PAGE) unless ::Lograge.ignore_tests.include?(IGNORE_REPEATED_ERROR_PAGE)
|
|
80
97
|
end
|
|
81
98
|
|
|
82
99
|
# Rails' "Processing by", "Completed 200 OK" and "Rendered" lines, which the request line replaces
|
|
@@ -98,6 +115,7 @@ module LogStruct
|
|
|
98
115
|
:source_ip
|
|
99
116
|
).compact
|
|
100
117
|
add_request_address(event.payload[:request], options)
|
|
118
|
+
add_error_page_request(event, options)
|
|
101
119
|
|
|
102
120
|
if event.payload[:params].present?
|
|
103
121
|
options[:params] = event.payload[:params].except("controller", "action")
|
|
@@ -127,6 +145,29 @@ module LogStruct
|
|
|
127
145
|
end
|
|
128
146
|
end
|
|
129
147
|
|
|
148
|
+
# An error page's line has the method and path of the request it's for, not GET /500
|
|
149
|
+
sig { params(event: ActiveSupport::Notifications::Event, options: T::Hash[Symbol, T.untyped]).void }
|
|
150
|
+
def add_error_page_request(event, options)
|
|
151
|
+
request = event.payload[:request]
|
|
152
|
+
return unless request.is_a?(::ActionDispatch::Request)
|
|
153
|
+
|
|
154
|
+
if request.has_header?(ORIGINAL_PATH_HEADER)
|
|
155
|
+
options[:method] = request.get_header(ORIGINAL_METHOD_HEADER)
|
|
156
|
+
options[:path] = "#{request.script_name}#{request.get_header(ORIGINAL_PATH_HEADER)}"
|
|
157
|
+
elsif event.payload[:exception]
|
|
158
|
+
request.set_header(ACTION_ERROR_LOGGED_HEADER, true)
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# The error page for an error its action's line logged would log the request a second time. A request whose
|
|
163
|
+
# error came before any action (a routing error) or after it (in a middleware) keeps its error page's line.
|
|
164
|
+
sig { params(event: ActiveSupport::Notifications::Event).returns(T::Boolean) }
|
|
165
|
+
def repeated_error_page?(event)
|
|
166
|
+
request = event.payload[:request]
|
|
167
|
+
request.is_a?(::ActionDispatch::Request) && request.has_header?(ORIGINAL_PATH_HEADER) &&
|
|
168
|
+
request.get_header(ACTION_ERROR_LOGGED_HEADER) == true
|
|
169
|
+
end
|
|
170
|
+
|
|
130
171
|
# Process headers from the event payload
|
|
131
172
|
sig { params(event: ActiveSupport::Notifications::Event, options: T::Hash[Symbol, T.untyped]).void }
|
|
132
173
|
def process_headers(event, options)
|
data/lib/log_struct/version.rb
CHANGED