exis_ray 0.11.0 → 1.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 +4 -4
- data/AGENTS.md +238 -0
- data/CHANGELOG.md +32 -0
- data/CLAUDE.md +9 -184
- data/README.md +26 -22
- data/docs/config/configuracion.md +159 -0
- data/docs/interface/interface.md +129 -0
- data/docs/release/release.md +49 -0
- data/docs/test/testing.md +163 -0
- data/lib/exis_ray/configuration.rb +36 -20
- data/lib/exis_ray/json_formatter.rb +124 -91
- data/lib/exis_ray/log_sanitizer.rb +253 -0
- data/lib/exis_ray/log_subscriber.rb +3 -19
- data/lib/exis_ray/railtie.rb +3 -3
- data/lib/exis_ray/sanitizing_formatter.rb +65 -0
- data/lib/exis_ray/task_monitor.rb +3 -12
- data/lib/exis_ray/version.rb +1 -1
- data/lib/exis_ray.rb +18 -0
- data/skill/SKILL.md +10 -11
- data/skill/references/standard.md +2 -2
- data/skills.yml +6 -24
- data/spec/exis_ray/configuration_spec.rb +6 -18
- data/spec/exis_ray/install_log_formatter_spec.rb +35 -0
- data/spec/exis_ray/json_formatter_spec.rb +139 -26
- data/spec/exis_ray/log_sanitizer_spec.rb +293 -0
- data/spec/exis_ray/log_subscriber_spec.rb +1 -27
- data/spec/exis_ray/sanitizing_formatter_spec.rb +96 -0
- data/spec/exis_ray/task_monitor_spec.rb +0 -15
- metadata +14 -5
- data/.gemini/docs/TELEMETRY_GUIDELINES.md +0 -32
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "action_controller/metal/strong_parameters"
|
|
5
|
+
|
|
6
|
+
RSpec.describe ExisRay::LogSanitizer do
|
|
7
|
+
subject(:sanitizer) { described_class.new(config) }
|
|
8
|
+
|
|
9
|
+
let(:config) { ExisRay::Configuration.new }
|
|
10
|
+
|
|
11
|
+
describe "con el default (sin filtered_keys)" do
|
|
12
|
+
it "tapa claves sensibles en el nivel raíz" do
|
|
13
|
+
result = sanitizer.call({ user: "gabriel", password: "secret" })
|
|
14
|
+
|
|
15
|
+
expect(result).to eq({ user: "gabriel", password: "[FILTERED]" })
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "tapa claves sensibles en hashes anidados" do
|
|
19
|
+
result = sanitizer.call({ db: { host: "localhost", token: "abc123" } })
|
|
20
|
+
|
|
21
|
+
expect(result).to eq({ db: { host: "localhost", token: "[FILTERED]" } })
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "tapa claves sensibles dentro de arrays de hashes" do
|
|
25
|
+
result = sanitizer.call({ users: [{ name: "gabriel", password: "secret" }, { name: "ana", password: "other" }] })
|
|
26
|
+
|
|
27
|
+
expect(result[:users]).to eq([{ name: "gabriel", password: "[FILTERED]" }, { name: "ana", password: "[FILTERED]" }])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "tapa entero el valor de una clave sensible, aunque sea un array" do
|
|
31
|
+
expect(sanitizer.call({ tokens: %w[abc def] })).to eq({ tokens: "[FILTERED]" })
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "no altera valores no sensibles en arrays" do
|
|
35
|
+
expect(sanitizer.call({ tags: %w[admin active] })).to eq({ tags: %w[admin active] })
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "#sensitive? con la lista del servicio (filtered_keys / unfiltered_keys)" do
|
|
40
|
+
it "tapa una clave de filtered_keys sin distinguir mayúsculas" do
|
|
41
|
+
config.filtered_keys = %w[data]
|
|
42
|
+
|
|
43
|
+
expect(sanitizer.call({ data: { x: 1 }, "DATA" => "y" })).to eq({ data: "[FILTERED]", "DATA" => "[FILTERED]" })
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "aplica filtered_keys por nombre exacto, no por 'contiene'" do
|
|
47
|
+
config.filtered_keys = %w[data]
|
|
48
|
+
|
|
49
|
+
expect(sanitizer.call({ metadata: "m", data_id: 5 })).to eq({ metadata: "m", data_id: 5 })
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "no destapa con unfiltered_keys una clave que el servicio pidió tapar" do
|
|
53
|
+
config.filtered_keys = %w[author]
|
|
54
|
+
config.unfiltered_keys = %w[author]
|
|
55
|
+
|
|
56
|
+
expect(sanitizer.call({ author: "x" })).to eq({ author: "[FILTERED]" })
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "destapa con unfiltered_keys sólo la clave exacta" do
|
|
60
|
+
config.unfiltered_keys = %w[author]
|
|
61
|
+
|
|
62
|
+
expect(sanitizer.call({ author: "Ana", author_token: "t" })).to eq({ author: "Ana", author_token: "[FILTERED]" })
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "normaliza las claves configuradas (Symbol, mayúsculas)" do
|
|
66
|
+
config.filtered_keys = [:Data]
|
|
67
|
+
|
|
68
|
+
expect(sanitizer.call({ "data" => "s" })).to eq({ "data" => "[FILTERED]" })
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "decide igual dentro de un string que en un Hash" do
|
|
72
|
+
expect(sanitizer.sanitize_text("author: Ana")).to eq("author: [FILTERED]")
|
|
73
|
+
|
|
74
|
+
config.unfiltered_keys = %w[author]
|
|
75
|
+
expect(described_class.new(config).sanitize_text("author: Ana")).to eq("author: Ana")
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe "#sanitize_text" do
|
|
80
|
+
def leaks?(text, secret)
|
|
81
|
+
sanitizer.sanitize_text(text).include?(secret)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "tapa CLAVE=VALOR, CLAVE: VALOR y CLAVE => VALOR" do
|
|
85
|
+
expect(sanitizer.sanitize_text("LOG_LEVEL=info DB_PASSWORD=abc x=1")).to eq("LOG_LEVEL=info DB_PASSWORD=[FILTERED] x=1")
|
|
86
|
+
# Al principio del string es una asignación entera (un elemento de Env): se tapa hasta el final.
|
|
87
|
+
expect(sanitizer.sanitize_text("DB_PASSWORD=abc LOG_LEVEL=info")).to eq("DB_PASSWORD=[FILTERED]")
|
|
88
|
+
expect(sanitizer.sanitize_text("a.b-token: zz other=1")).to eq("a.b-token: [FILTERED] other=1")
|
|
89
|
+
expect(sanitizer.sanitize_text("api_key => qq y")).to eq("api_key => [FILTERED] y")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "tapa el valor sensible hasta el espacio, aunque se lleve el resto de una query o una coma" do
|
|
93
|
+
expect(sanitizer.sanitize_text("a=1&token=SECRET&b=2 c=3")).to eq("a=1&token=[FILTERED] c=3")
|
|
94
|
+
expect(sanitizer.sanitize_text("token: zz, other=1")).to eq("token: [FILTERED] other=1")
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "tapa la query de una URL con esquema y de un host:puerto" do
|
|
98
|
+
expect(leaks?("GET https://api.x/cb?token=SECRET1", "SECRET1")).to be(false)
|
|
99
|
+
expect(leaks?("redis://localhost:6379/0?password=SECRET2", "SECRET2")).to be(false)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "tapa un par sensible dentro del valor entre comillas de otro" do
|
|
103
|
+
expect(sanitizer.sanitize_text('msg="a token=z" n=1')).to eq('msg="a token=[FILTERED]" n=1')
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it "tapa una clave que empieza con un dígito" do
|
|
107
|
+
expect(sanitizer.sanitize_text("1token=x")).to eq("1token=[FILTERED]")
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "tapa las credenciales de Authorization escritas como texto" do
|
|
111
|
+
expect(sanitizer.sanitize_text("Authorization: Bearer abc.def-ghi")).to eq("Authorization: [FILTERED]")
|
|
112
|
+
expect(sanitizer.sanitize_text("Basic dXNlcjpwYXNz")).to eq("Basic [FILTERED]")
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "tapa la clave de una URL esquema://usuario:clave@host" do
|
|
116
|
+
expect(sanitizer.sanitize_text("postgres://app:S3cr3t@db:5432/x")).to eq("postgres://app:[FILTERED]@db:5432/x")
|
|
117
|
+
expect(sanitizer.sanitize_text("redis://:pw@h:1/0")).to eq("redis://:[FILTERED]@h:1/0")
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "tapa entera una clave de URL con una @ sin codificar" do
|
|
121
|
+
expect(sanitizer.sanitize_text("postgres://app:p@ss@db/x")).to eq("postgres://app:[FILTERED]@db/x")
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it "tapa el inspect de un Hash de Ruby 3.4 con claves Symbol" do
|
|
125
|
+
expect(sanitizer.sanitize_text('{password: "SECRET"}')).to eq("{password: [FILTERED]}")
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "tapa una clave entre comillas (Hash#inspect) o entre corchetes (query)" do
|
|
129
|
+
inspected = { "user" => { "password" => "S3cr3t" } }.inspect
|
|
130
|
+
|
|
131
|
+
expect(sanitizer.sanitize_text("params=#{inspected}")).to eq('params={"user" => {"password" => [FILTERED]}}')
|
|
132
|
+
expect(sanitizer.sanitize_text("POST /login?user[password]=S3cr3t&x=1 HTTP/1.1"))
|
|
133
|
+
.to eq("POST /login?user[password]=[FILTERED] HTTP/1.1")
|
|
134
|
+
expect(sanitizer.sanitize_text("opts={'token' => 'abc'}")).to eq("opts={'token' => [FILTERED]}")
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it "respeta unfiltered_keys también con la clave entre comillas (el password de PPPoE)" do
|
|
138
|
+
config.unfiltered_keys = %w[password]
|
|
139
|
+
|
|
140
|
+
expect(sanitizer.sanitize_text('params={"password" => "pppoe123"} token=t'))
|
|
141
|
+
.to eq('params={"password" => "pppoe123"} token=[FILTERED]')
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it "deja ver el password de PPPoE de una fila de radcheck (viaja como attribute/value)" do
|
|
145
|
+
rad_check = { "username" => "cli1", "attribute" => "Cleartext-Password", "value" => "pppoe123" }
|
|
146
|
+
|
|
147
|
+
expect(sanitizer.call(rad_check)).to eq(rad_check)
|
|
148
|
+
expect(sanitizer.sanitize_text("rad_check=#{rad_check.inspect}")).to eq("rad_check=#{rad_check.inspect}")
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "no altera una línea normal de Rails" do
|
|
152
|
+
line = "Completed 200 OK in 5ms (Views: 1.2ms | ActiveRecord: 0.5ms)"
|
|
153
|
+
|
|
154
|
+
expect(sanitizer.sanitize_text(line)).to eq(line)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
describe "hallazgos del MVF de exis_ray#24" do
|
|
159
|
+
it "no deja que una clave no sensible se coma la sensible que la sigue (F3)" do
|
|
160
|
+
expect(sanitizer.sanitize_text("Auth failed: token: SECRET")).not_to include("SECRET")
|
|
161
|
+
expect(sanitizer.sanitize_text("Error: password = SECRET")).not_to include("SECRET")
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it "no se cae con miles de pares seguidos (F10)" do
|
|
165
|
+
expect { sanitizer.sanitize_text("a=" * 20_000) }.not_to raise_error
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it "tapa el valor sensible entero (F1)" do
|
|
169
|
+
expect(sanitizer.sanitize_text("Authorization: Token abc123def")).not_to include("abc123def")
|
|
170
|
+
expect(sanitizer.sanitize_text("password=ab,cd;ef")).to eq("password=[FILTERED]")
|
|
171
|
+
expect(sanitizer.sanitize_text('auth => {"user" => "SECRET"} next=1')).to eq("auth => [FILTERED] next=1")
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "tapa hasta el final un string que es entero una asignación sensible (un elemento de Env)" do
|
|
175
|
+
env = ["SSL_SECRET=-----BEGIN PRIVATE KEY-----\nMIIEv\n-----END PRIVATE KEY-----", "API_TOKEN=abc def",
|
|
176
|
+
"RAILS_LOG_LEVEL=info"]
|
|
177
|
+
|
|
178
|
+
expect(sanitizer.call({ "Env" => env }))
|
|
179
|
+
.to eq({ "Env" => ["SSL_SECRET=[FILTERED]", "API_TOKEN=[FILTERED]", "RAILS_LOG_LEVEL=info"] })
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
it "no tapa de más un texto que no arranca con una asignación sensible" do
|
|
183
|
+
expect(sanitizer.sanitize_text("login ok token=abc user=ana")).to eq("login ok token=[FILTERED] user=ana")
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it "tapa en el default lo que tapaban bug_bunny y docker-swarm (unión de sus listas)" do
|
|
187
|
+
keys = %w[X-Api-Key api-key credential credentials private_key private-key csrf session_id session-id]
|
|
188
|
+
|
|
189
|
+
keys.each do |key|
|
|
190
|
+
expect(sanitizer.sensitive?(key)).to be(true), key
|
|
191
|
+
expect(sanitizer.sanitize_text("#{key}: v1 n=1")).to eq("#{key}: [FILTERED] n=1"), key
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
it "tapa un Symbol como un string (F2)" do
|
|
196
|
+
expect(sanitizer.call({ note: :"password=SECRET" }).to_s).not_to include("SECRET")
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
it "tapa y recorta un string que no es UTF-8 (F8)" do
|
|
200
|
+
latin = ("\xE9" * 600).dup.force_encoding("ISO-8859-1")
|
|
201
|
+
|
|
202
|
+
result = sanitizer.call({ c: latin, b: ("\xFF" * 600).b })
|
|
203
|
+
|
|
204
|
+
expect(result[:c]).to be_valid_encoding
|
|
205
|
+
expect(result[:c]).to end_with("…[TRUNCATED size=600]")
|
|
206
|
+
expect(result[:b]).to be_valid_encoding
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
it "recorta por el principio un diagnóstico de más de max_traverse_bytes, sin reemplazarlo (F12)" do
|
|
210
|
+
result = sanitizer.call({ "exception.stacktrace" => "app/x.rb:1 token=S #{"x" * 70_000}" })
|
|
211
|
+
|
|
212
|
+
expect(result["exception.stacktrace"]).to start_with("app/x.rb:1 token=[FILTERED]")
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
it "es la misma regla para una clave de Hash que para una clave en texto" do
|
|
216
|
+
config.filtered_keys = %w[data]
|
|
217
|
+
config.unfiltered_keys = %w[author]
|
|
218
|
+
keys = %w[data DATA metadata author author_token password Cleartext-Password value x_api_key auth.user 1token]
|
|
219
|
+
|
|
220
|
+
keys.each do |key|
|
|
221
|
+
masked = !described_class.new(config).sanitize_text("#{key}=v1").include?("v1")
|
|
222
|
+
expect(masked).to eq(described_class.new(config).sensitive?(key)), key
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
describe "#call: recorrido y límites" do
|
|
228
|
+
it "no recorta el mensaje entero (un String en la raíz)" do
|
|
229
|
+
expect(sanitizer.call("x" * 600)).to eq("x" * 600)
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
it "no recorta error_message (la clave legacy de exception.message)" do
|
|
233
|
+
expect(sanitizer.call({ "error_message" => "x" * 600 })).to eq({ "error_message" => "x" * 600 })
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
it "recorta un valor string a max_value_chars" do
|
|
237
|
+
expect(sanitizer.call({ comment: "x" * 600 })).to eq({ comment: "#{"x" * 500}…[TRUNCATED size=600]" })
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it "no recorre una clave sensible con un Hash adentro" do
|
|
241
|
+
expect(sanitizer.call({ auth: { user: "u", provider: "p" } })).to eq({ auth: "[FILTERED]" })
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
it "tapa el JSON embebido en un string y lo devuelve como string" do
|
|
245
|
+
result = sanitizer.call({ payload: '{"password":"SECRET","n":1}' })
|
|
246
|
+
|
|
247
|
+
expect(result).to eq({ payload: '{"password":"[FILTERED]","n":1}' })
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
it "recorre ActionController::Parameters y Struct" do
|
|
251
|
+
params = ActionController::Parameters.new(user: { password: "S" })
|
|
252
|
+
creds = Struct.new(:token).new("S")
|
|
253
|
+
|
|
254
|
+
expect(sanitizer.call({ params: params, creds: creds }))
|
|
255
|
+
.to eq({ params: { "user" => { "password" => "[FILTERED]" } }, creds: { token: "[FILTERED]" } })
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
it "reemplaza entero un valor de más de max_traverse_bytes, sin recorrerlo" do
|
|
259
|
+
expect(sanitizer.call({ comment: "a" * 65_537 })).to eq({ comment: "[TOO_LARGE size=65537]" })
|
|
260
|
+
expect(sanitizer.call({ body: "a" * 65_536 })).to eq({ body: "a" * 65_536 })
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
it "al mensaje entero de más de max_traverse_bytes lo recorta por el principio" do
|
|
264
|
+
expect(sanitizer.call("a" * 65_537)).to eq("#{"a" * 65_536}…[TRUNCATED size=65537]")
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
it "recorta un array a max_array_items" do
|
|
268
|
+
expect(sanitizer.call({ ids: (1..101).to_a })).to eq({ ids: (1..100).to_a + ["[TRUNCATED count=101]"] })
|
|
269
|
+
expect(sanitizer.call({ ids: (1..100).to_a })).to eq({ ids: (1..100).to_a })
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
it "corta lo que pasa de MAX_DEPTH sin escribirlo" do
|
|
273
|
+
deep = (1..25).reduce({ password: "S" }) { |acc, i| { "l#{i}": acc } }
|
|
274
|
+
|
|
275
|
+
json = sanitizer.call(deep).to_json
|
|
276
|
+
expect(json).to include("[TRUNCATED depth]")
|
|
277
|
+
expect(json).not_to include('"S"')
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
it "corta lo que pasa de MAX_NODES" do
|
|
281
|
+
result = sanitizer.call({ items: Array.new(100) { Array.new(101, 1) } }.merge(more: Array.new(100) { [1] }))
|
|
282
|
+
|
|
283
|
+
expect(result.to_json).to include("[TRUNCATED nodes]")
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
it "no muta la entrada" do
|
|
287
|
+
input = { password: "S", n: [1] }.freeze
|
|
288
|
+
|
|
289
|
+
expect { sanitizer.call(input) }.not_to raise_error
|
|
290
|
+
expect(input).to eq({ password: "S", n: [1] })
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
end
|
|
@@ -159,17 +159,7 @@ RSpec.describe ExisRay::LogSubscriber do
|
|
|
159
159
|
expect(data[:"url.path"]).to eq("/users/42")
|
|
160
160
|
end
|
|
161
161
|
|
|
162
|
-
it "emite
|
|
163
|
-
event = build_event(payload: base_payload)
|
|
164
|
-
|
|
165
|
-
data = subscriber.send(:build_payload, event)
|
|
166
|
-
|
|
167
|
-
expect(data[:path]).to eq("/users/42")
|
|
168
|
-
expect(data[:"url.path"]).to eq("/users/42")
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
it "omite path cuando emit_legacy_path_key=false (solo url.path)" do
|
|
172
|
-
allow(ExisRay.configuration).to receive(:emit_legacy_path_key).and_return(false)
|
|
162
|
+
it "no emite el alias viejo path, sólo url.path" do
|
|
173
163
|
event = build_event(payload: base_payload)
|
|
174
164
|
|
|
175
165
|
data = subscriber.send(:build_payload, event)
|
|
@@ -289,22 +279,6 @@ RSpec.describe ExisRay::LogSubscriber do
|
|
|
289
279
|
|
|
290
280
|
data = subscriber.send(:build_payload, event)
|
|
291
281
|
|
|
292
|
-
expect(data[:"exception.type"]).to eq("RuntimeError")
|
|
293
|
-
expect(data[:"exception.message"]).to eq("something went wrong")
|
|
294
|
-
expect(data[:error_class]).to eq("RuntimeError")
|
|
295
|
-
expect(data[:error_message]).to eq("something went wrong")
|
|
296
|
-
end
|
|
297
|
-
|
|
298
|
-
it "omite error_class/error_message cuando emit_legacy_exception_keys=false" do
|
|
299
|
-
allow(ExisRay.configuration).to receive(:emit_legacy_exception_keys).and_return(false)
|
|
300
|
-
|
|
301
|
-
event = build_event(payload: base_payload.merge(
|
|
302
|
-
status: nil,
|
|
303
|
-
exception: ["RuntimeError", "something went wrong"]
|
|
304
|
-
))
|
|
305
|
-
|
|
306
|
-
data = subscriber.send(:build_payload, event)
|
|
307
|
-
|
|
308
282
|
expect(data[:"exception.type"]).to eq("RuntimeError")
|
|
309
283
|
expect(data[:"exception.message"]).to eq("something went wrong")
|
|
310
284
|
expect(data).not_to have_key(:error_class)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "stringio"
|
|
5
|
+
require "active_support/tagged_logging"
|
|
6
|
+
require "active_support/broadcast_logger"
|
|
7
|
+
|
|
8
|
+
RSpec.describe ExisRay::SanitizingFormatter do
|
|
9
|
+
subject(:formatter) { described_class.new(inner) }
|
|
10
|
+
|
|
11
|
+
let(:inner) { proc { |severity, _time, _progname, msg| "#{severity} #{msg}\n" } }
|
|
12
|
+
let(:time) { Time.utc(2026, 12, 1) }
|
|
13
|
+
let(:config) { ExisRay::Configuration.new }
|
|
14
|
+
|
|
15
|
+
before { allow(ExisRay).to receive(:configuration).and_return(config) }
|
|
16
|
+
|
|
17
|
+
def error_with(message, backtrace)
|
|
18
|
+
RuntimeError.new(message).tap { |error| error.set_backtrace(backtrace) }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "#call" do
|
|
22
|
+
it "tapa el mensaje y deja el formato del formatter envuelto" do
|
|
23
|
+
expect(formatter.call("INFO", time, nil, "login token=SECRET")).to eq("INFO login token=[FILTERED]\n")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "escribe el backtrace entero de una excepción" do
|
|
27
|
+
error = error_with("boom", Array.new(40) { |i| "app/x.rb:#{i}" })
|
|
28
|
+
|
|
29
|
+
line = formatter.call("ERROR", time, nil, error)
|
|
30
|
+
|
|
31
|
+
expect(line).to include("boom (RuntimeError)", "app/x.rb:39")
|
|
32
|
+
expect(line).not_to include("TRUNCATED")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "tapa un secreto en el mensaje de una excepción" do
|
|
36
|
+
line = formatter.call("ERROR", time, nil, error_with("auth failed password=SECRET", []))
|
|
37
|
+
|
|
38
|
+
expect(line).not_to include("SECRET")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "tapa un Hash" do
|
|
42
|
+
inspecting = described_class.new(proc { |_s, _t, _p, msg| "#{msg.inspect}\n" })
|
|
43
|
+
|
|
44
|
+
expect(inspecting.call("INFO", time, nil, { password: "S" })).not_to include('"S"')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "recorta la línea que sale, con el prefijo del formatter, en un borde UTF-8 válido (F5)" do
|
|
48
|
+
prefixed = described_class.new(proc { |_s, _t, _p, msg| "#{"P" * 200} #{msg}\n" })
|
|
49
|
+
|
|
50
|
+
line = prefixed.call("INFO", time, nil, "ñ" * 10_000)
|
|
51
|
+
|
|
52
|
+
expect(line).to be_valid_encoding
|
|
53
|
+
expect(line).to end_with("…[TRUNCATED size=#{200 + 1 + 20_000 + 1}]\n")
|
|
54
|
+
expect(line.bytesize).to be <= 8192
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "no falla con un max_line_bytes menor al marcador (F13)" do
|
|
58
|
+
config.max_line_bytes = 32
|
|
59
|
+
|
|
60
|
+
expect(formatter.call("INFO", time, nil, "x" * 100)).to start_with("…[TRUNCATED size=")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "si tapar falla, escribe filter_error y nunca el mensaje" do
|
|
64
|
+
allow(ExisRay::LogSanitizer).to receive(:new).and_raise(RuntimeError)
|
|
65
|
+
|
|
66
|
+
expect(formatter.call("INFO", time, nil, "token=SECRET")).to eq("INFO filter_error=RuntimeError\n")
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe ".install" do
|
|
71
|
+
it "envuelve cada logger de un BroadcastLogger, una sola vez" do
|
|
72
|
+
loggers = [Logger.new(StringIO.new), Logger.new(StringIO.new)]
|
|
73
|
+
broadcast = ActiveSupport::BroadcastLogger.new(*loggers)
|
|
74
|
+
|
|
75
|
+
2.times { described_class.install(broadcast) }
|
|
76
|
+
|
|
77
|
+
loggers.each do |logger|
|
|
78
|
+
expect(logger.formatter).to be_a(described_class)
|
|
79
|
+
expect(logger.formatter.__getobj__).not_to be_a(described_class)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "conserva los tags de TaggedLogging, con y sin bloque, también con un formatter proc" do
|
|
84
|
+
io = StringIO.new
|
|
85
|
+
base = Logger.new(io)
|
|
86
|
+
base.formatter = proc { |_s, _t, _p, msg| "#{msg}\n" }
|
|
87
|
+
logger = ActiveSupport::TaggedLogging.new(base)
|
|
88
|
+
|
|
89
|
+
described_class.install(logger)
|
|
90
|
+
logger.tagged("T1") { logger.info("token=S") }
|
|
91
|
+
logger.tagged("T2").info("x")
|
|
92
|
+
|
|
93
|
+
expect(io.string).to eq("[T1] token=[FILTERED]\n[T2] x\n")
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -102,21 +102,6 @@ RSpec.describe ExisRay::TaskMonitor do
|
|
|
102
102
|
finish_log = captured_logs.find { |lvl, msg| lvl == :error && msg.include?("task_finished") }
|
|
103
103
|
expect(finish_log).not_to be_nil
|
|
104
104
|
expect(finish_log[1]).to include("outcome=failed")
|
|
105
|
-
expect(finish_log[1]).to include("error_class=RuntimeError")
|
|
106
|
-
expect(finish_log[1]).to include("error_message=")
|
|
107
|
-
expect(finish_log[1]).to include("exception.type=RuntimeError")
|
|
108
|
-
expect(finish_log[1]).to include("exception.message=")
|
|
109
|
-
expect(finish_log[1]).to include("exception.stacktrace=")
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
it "omite error_class/error_message cuando emit_legacy_exception_keys=false" do
|
|
113
|
-
allow(ExisRay.configuration).to receive(:emit_legacy_exception_keys).and_return(false)
|
|
114
|
-
|
|
115
|
-
expect do
|
|
116
|
-
described_class.run("task:boom") { raise "kaboom" }
|
|
117
|
-
end.to raise_error(RuntimeError, "kaboom")
|
|
118
|
-
|
|
119
|
-
finish_log = captured_logs.find { |lvl, msg| lvl == :error && msg.include?("task_finished") }
|
|
120
105
|
expect(finish_log[1]).not_to include("error_class=")
|
|
121
106
|
expect(finish_log[1]).not_to include("error_message=")
|
|
122
107
|
expect(finish_log[1]).to include("exception.type=RuntimeError")
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: exis_ray
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gabriel Edera
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-12-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -45,14 +45,18 @@ executables: []
|
|
|
45
45
|
extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
|
47
47
|
files:
|
|
48
|
-
-
|
|
48
|
+
- AGENTS.md
|
|
49
49
|
- CHANGELOG.md
|
|
50
50
|
- CLAUDE.md
|
|
51
51
|
- LICENSE.txt
|
|
52
52
|
- README.md
|
|
53
53
|
- Rakefile
|
|
54
54
|
- docs/behavior/behavior.md
|
|
55
|
+
- docs/config/configuracion.md
|
|
55
56
|
- docs/glossary/glossary.md
|
|
57
|
+
- docs/interface/interface.md
|
|
58
|
+
- docs/release/release.md
|
|
59
|
+
- docs/test/testing.md
|
|
56
60
|
- lib/exis_ray.rb
|
|
57
61
|
- lib/exis_ray/active_resource_instrumentation.rb
|
|
58
62
|
- lib/exis_ray/bug_bunny/consumer_tracing_middleware.rb
|
|
@@ -62,9 +66,11 @@ files:
|
|
|
62
66
|
- lib/exis_ray/faraday_middleware.rb
|
|
63
67
|
- lib/exis_ray/http_middleware.rb
|
|
64
68
|
- lib/exis_ray/json_formatter.rb
|
|
69
|
+
- lib/exis_ray/log_sanitizer.rb
|
|
65
70
|
- lib/exis_ray/log_subscriber.rb
|
|
66
71
|
- lib/exis_ray/railtie.rb
|
|
67
72
|
- lib/exis_ray/reporter.rb
|
|
73
|
+
- lib/exis_ray/sanitizing_formatter.rb
|
|
68
74
|
- lib/exis_ray/sidekiq/client_middleware.rb
|
|
69
75
|
- lib/exis_ray/sidekiq/server_middleware.rb
|
|
70
76
|
- lib/exis_ray/task_monitor.rb
|
|
@@ -78,9 +84,12 @@ files:
|
|
|
78
84
|
- spec/exis_ray/configuration_spec.rb
|
|
79
85
|
- spec/exis_ray/current_spec.rb
|
|
80
86
|
- spec/exis_ray/http_middleware_spec.rb
|
|
87
|
+
- spec/exis_ray/install_log_formatter_spec.rb
|
|
81
88
|
- spec/exis_ray/json_formatter_spec.rb
|
|
89
|
+
- spec/exis_ray/log_sanitizer_spec.rb
|
|
82
90
|
- spec/exis_ray/log_subscriber_spec.rb
|
|
83
91
|
- spec/exis_ray/reporter_spec.rb
|
|
92
|
+
- spec/exis_ray/sanitizing_formatter_spec.rb
|
|
84
93
|
- spec/exis_ray/task_monitor_spec.rb
|
|
85
94
|
- spec/exis_ray/tracer_spec.rb
|
|
86
95
|
- spec/spec_helper.rb
|
|
@@ -90,8 +99,8 @@ licenses:
|
|
|
90
99
|
metadata:
|
|
91
100
|
homepage_uri: https://github.com/gedera/exis_ray
|
|
92
101
|
source_code_uri: https://github.com/gedera/exis_ray
|
|
93
|
-
changelog_uri: https://github.com/gedera/exis_ray/blob/
|
|
94
|
-
documentation_uri: https://github.com/gedera/exis_ray/blob/
|
|
102
|
+
changelog_uri: https://github.com/gedera/exis_ray/blob/v1.0.0/CHANGELOG.md
|
|
103
|
+
documentation_uri: https://github.com/gedera/exis_ray/blob/v1.0.0/skill
|
|
95
104
|
post_install_message:
|
|
96
105
|
rdoc_options: []
|
|
97
106
|
require_paths:
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# OpenTelemetry Implementation Guidelines
|
|
2
|
-
|
|
3
|
-
This document provides expert guidance for aligning code and logs with OpenTelemetry (OTel) standards. Follow these rules for all new instrumentation.
|
|
4
|
-
|
|
5
|
-
## 1. Log Data Model
|
|
6
|
-
- **Body:** Use `body` for the primary log message.
|
|
7
|
-
- **Attributes:** Metadata must be flat Key-Value pairs.
|
|
8
|
-
- **Severity:** `level` maps to `severity_text`.
|
|
9
|
-
|
|
10
|
-
## 2. Semantic Conventions
|
|
11
|
-
When adding attributes, check the official OTel [Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/).
|
|
12
|
-
|
|
13
|
-
### HTTP Attributes
|
|
14
|
-
- `http.request.method`: GET, POST, etc.
|
|
15
|
-
- `http.response.status_code`: 200, 404, etc.
|
|
16
|
-
- `url.path`: The request path.
|
|
17
|
-
- `user_agent.original`: The raw User-Agent string.
|
|
18
|
-
|
|
19
|
-
### Database Attributes
|
|
20
|
-
- `db.system`: postgresql, redis, etc.
|
|
21
|
-
- `db.operation`: select, update, etc.
|
|
22
|
-
- `db.collection.name`: table or collection name.
|
|
23
|
-
|
|
24
|
-
## 3. Metrics & Units
|
|
25
|
-
- Always use the lowest common denominator for units (seconds, bytes).
|
|
26
|
-
- Use `_s` suffix for time duration.
|
|
27
|
-
- Avoid compound strings like `"10ms"`. Use `duration_s=0.01`.
|
|
28
|
-
|
|
29
|
-
## 4. Distributed Tracing
|
|
30
|
-
- **TraceID:** 16-byte array, represented as a 32-char lowercase hex string.
|
|
31
|
-
- **SpanID:** 8-byte array, represented as a 16-char lowercase hex string.
|
|
32
|
-
- **Context Propagation:** Follow W3C Trace Context (traceparent) when possible, or maintain AWS X-Ray compatibility as per project requirements.
|