bug_bunny 4.9.1 → 4.10.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/lib/bug_bunny/consumer.rb +19 -8
- data/lib/bug_bunny/controller.rb +6 -1
- data/lib/bug_bunny/middleware/raise_error.rb +8 -0
- data/lib/bug_bunny/producer.rb +9 -2
- data/lib/bug_bunny/remote_error.rb +55 -0
- data/lib/bug_bunny/resource.rb +12 -0
- data/lib/bug_bunny/version.rb +1 -1
- data/lib/bug_bunny.rb +1 -0
- data/skills.lock +1 -1
- data/spec/integration/resource_spec.rb +44 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af9746f85e544f059873513a7ace9b478acb6664b9053bb90d1963afb1d72848
|
|
4
|
+
data.tar.gz: 32854fb9e2a67f8e5cb537550d957704443d95183d22d5305b48c3207edaf05b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 90169fb942803e87f47cf1af2fb2b4cb4d66112aaf4ab6632bb6a8d5031383e1fc0105a4cf2449eed847822509a71c1e4695c8cacb9907889c286cc5cfefe70b
|
|
7
|
+
data.tar.gz: 39262e92b89fb583769bcfaa8a17972584b0aaeda9f197ff3cf7cf4c45941ca0ee0b3aa154e8073d4004f5213bb1852aa16cc6c6f809951b2bcf3c76b85fa66d
|
data/lib/bug_bunny/consumer.rb
CHANGED
|
@@ -176,7 +176,7 @@ module BugBunny
|
|
|
176
176
|
|
|
177
177
|
safe_log(:info, 'consumer.message_received', method: http_method, path: path,
|
|
178
178
|
routing_key: delivery_info.routing_key, **otel_fields)
|
|
179
|
-
safe_log(:
|
|
179
|
+
safe_log(:info, 'consumer.message_received_body', body: body&.truncate(500), body_size: body&.size || 0)
|
|
180
180
|
|
|
181
181
|
# ===================================================================
|
|
182
182
|
# 3. Ruteo Declarativo
|
|
@@ -256,7 +256,7 @@ module BugBunny
|
|
|
256
256
|
rescue StandardError => e
|
|
257
257
|
safe_log(:error, 'consumer.execution_error', duration_s: duration_s(start_time), **exception_metadata(e))
|
|
258
258
|
safe_log(:debug, 'consumer.execution_error_backtrace', backtrace: e.backtrace.first(5).join(' | '))
|
|
259
|
-
handle_fatal_error(properties, 500, 'Internal Server Error', e.message)
|
|
259
|
+
handle_fatal_error(properties, 500, 'Internal Server Error', e.message, e)
|
|
260
260
|
session.channel.reject(delivery_info.delivery_tag, false)
|
|
261
261
|
end
|
|
262
262
|
|
|
@@ -267,7 +267,12 @@ module BugBunny
|
|
|
267
267
|
# @param correlation_id [String] ID para correlacionar la respuesta con la petición original.
|
|
268
268
|
# @return [void]
|
|
269
269
|
def reply(payload, reply_to, correlation_id)
|
|
270
|
-
safe_log(:
|
|
270
|
+
safe_log(:info, 'consumer.rpc_reply',
|
|
271
|
+
reply_to: reply_to,
|
|
272
|
+
messaging_message_id: correlation_id,
|
|
273
|
+
response_status: payload[:status],
|
|
274
|
+
response_body: payload[:body]&.to_json&.truncate(500),
|
|
275
|
+
response_body_size: payload[:body]&.to_json&.size || 0)
|
|
271
276
|
otel_headers = BugBunny::OTel.messaging_headers(
|
|
272
277
|
operation: 'publish',
|
|
273
278
|
destination: '',
|
|
@@ -287,14 +292,20 @@ module BugBunny
|
|
|
287
292
|
# Maneja errores fatales asegurando que el cliente reciba una respuesta.
|
|
288
293
|
# Evita que el cliente RPC se quede esperando hasta el timeout.
|
|
289
294
|
#
|
|
295
|
+
# @param properties [Bunny::MessageProperties] Headers y propiedades AMQP.
|
|
296
|
+
# @param status [Integer] Código de estado HTTP.
|
|
297
|
+
# @param error_title [String] Título del error.
|
|
298
|
+
# @param detail [String] Detalle del error.
|
|
299
|
+
# @param exception [StandardError, nil] Excepción original (para status 500).
|
|
290
300
|
# @api private
|
|
291
|
-
def handle_fatal_error(properties, status, error_title, detail)
|
|
301
|
+
def handle_fatal_error(properties, status, error_title, detail, exception = nil)
|
|
292
302
|
return unless properties.reply_to
|
|
293
303
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
304
|
+
body = { error: error_title, detail: detail }
|
|
305
|
+
|
|
306
|
+
body[:bug_bunny_exception] = BugBunny::RemoteError.serialize(exception) if status == 500 && exception
|
|
307
|
+
|
|
308
|
+
error_payload = { status: status, body: body }
|
|
298
309
|
reply(error_payload, properties.reply_to, properties.correlation_id)
|
|
299
310
|
end
|
|
300
311
|
|
data/lib/bug_bunny/controller.rb
CHANGED
|
@@ -224,7 +224,12 @@ module BugBunny
|
|
|
224
224
|
{
|
|
225
225
|
status: 500,
|
|
226
226
|
headers: response_headers,
|
|
227
|
-
body: {
|
|
227
|
+
body: {
|
|
228
|
+
error: 'Internal Server Error',
|
|
229
|
+
detail: exception.message,
|
|
230
|
+
type: exception.class.name,
|
|
231
|
+
bug_bunny_exception: BugBunny::RemoteError.serialize(exception)
|
|
232
|
+
}
|
|
228
233
|
}
|
|
229
234
|
end
|
|
230
235
|
|
|
@@ -50,6 +50,14 @@ module BugBunny
|
|
|
50
50
|
# Pasamos el body crudo; UnprocessableEntity lo procesará en exception.rb
|
|
51
51
|
raise BugBunny::UnprocessableEntity, body
|
|
52
52
|
when 500..599
|
|
53
|
+
if body.is_a?(Hash) && body['bug_bunny_exception']
|
|
54
|
+
exception_data = body['bug_bunny_exception']
|
|
55
|
+
raise BugBunny::RemoteError.new(
|
|
56
|
+
exception_data['class'],
|
|
57
|
+
exception_data['message'],
|
|
58
|
+
exception_data['backtrace'] || []
|
|
59
|
+
)
|
|
60
|
+
end
|
|
53
61
|
raise BugBunny::InternalServerError, format_error_message(body)
|
|
54
62
|
else
|
|
55
63
|
handle_unknown_error(status, body)
|
data/lib/bug_bunny/producer.rb
CHANGED
|
@@ -89,7 +89,9 @@ module BugBunny
|
|
|
89
89
|
BugBunny.configuration.on_rpc_reply&.call(result[:headers])
|
|
90
90
|
|
|
91
91
|
safe_log(:debug, 'producer.rpc_response_received',
|
|
92
|
-
messaging_system: 'rabbitmq', messaging_operation: 'receive', messaging_message_id: cid
|
|
92
|
+
messaging_system: 'rabbitmq', messaging_operation: 'receive', messaging_message_id: cid,
|
|
93
|
+
response_body: result[:body]&.truncate(500),
|
|
94
|
+
response_headers: result[:headers]&.to_json&.truncate(300))
|
|
93
95
|
|
|
94
96
|
parse_response(result[:body])
|
|
95
97
|
ensure
|
|
@@ -125,7 +127,12 @@ module BugBunny
|
|
|
125
127
|
safe_log(:info, 'producer.publish', method: verb, path: target, **otel_fields)
|
|
126
128
|
safe_log(:debug, 'producer.publish_detail', messaging_destination_name: request.exchange,
|
|
127
129
|
exchange_opts: final_x_opts)
|
|
128
|
-
|
|
130
|
+
return unless payload.is_a?(String)
|
|
131
|
+
|
|
132
|
+
safe_log(:info, 'producer.publish_payload',
|
|
133
|
+
payload: payload.truncate(500),
|
|
134
|
+
payload_class: payload.class.name,
|
|
135
|
+
body_size: request.body.nil? ? 0 : request.body.size)
|
|
129
136
|
end
|
|
130
137
|
|
|
131
138
|
# Serializa el mensaje para su transporte.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BugBunny
|
|
4
|
+
# Error 500 especial que propagationa información de una excepción remota.
|
|
5
|
+
#
|
|
6
|
+
# Cuando un controller levanta una excepción no manejada en el worker, esta clase
|
|
7
|
+
# permite al llamador RPC acceder a:
|
|
8
|
+
# - La clase original de la excepción (ej: ActiveRecord::RecordNotFound)
|
|
9
|
+
# - El mensaje original
|
|
10
|
+
# - El backtrace completo para debugging
|
|
11
|
+
#
|
|
12
|
+
# Mantiene compatibilidad hacia atrás: si la respuesta no contiene
|
|
13
|
+
# bug_bunny_exception, se comporta como un InternalServerError común.
|
|
14
|
+
class RemoteError < ServerError
|
|
15
|
+
# @return [String] La clase de la excepción remota (ej: 'ActiveRecord::RecordNotFound').
|
|
16
|
+
attr_reader :original_class
|
|
17
|
+
|
|
18
|
+
# @return [String] El mensaje original de la excepción.
|
|
19
|
+
attr_reader :original_message
|
|
20
|
+
|
|
21
|
+
# @return [Array<String>] El backtrace original de la excepción.
|
|
22
|
+
attr_reader :original_backtrace
|
|
23
|
+
|
|
24
|
+
# Serializa una excepción para transmitirse como parte de la respuesta.
|
|
25
|
+
#
|
|
26
|
+
# @param exception [StandardError] La excepción a serializar.
|
|
27
|
+
# @param max_lines [Integer] Máximo de líneas del backtrace (default 25).
|
|
28
|
+
# @return [Hash] Estructura con class, message y backtrace.
|
|
29
|
+
def self.serialize(exception, max_lines: 25)
|
|
30
|
+
{
|
|
31
|
+
class: exception.class.name,
|
|
32
|
+
message: exception.message,
|
|
33
|
+
backtrace: exception.backtrace&.first(max_lines) || []
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Inicializa la excepción remota propagada desde el worker.
|
|
38
|
+
#
|
|
39
|
+
# @param original_class [String] Nombre completo de la clase de la excepción.
|
|
40
|
+
# @param message [String] Mensaje de la excepción.
|
|
41
|
+
# @param backtrace [Array<String>] Stack trace completo.
|
|
42
|
+
def initialize(original_class, message, backtrace)
|
|
43
|
+
@original_class = original_class
|
|
44
|
+
@original_message = message
|
|
45
|
+
@original_backtrace = backtrace || []
|
|
46
|
+
super(message)
|
|
47
|
+
set_backtrace(backtrace || [])
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# @return [String] Representación legible de la excepción.
|
|
51
|
+
def to_s
|
|
52
|
+
"#{self.class.name}(#{original_class}): #{message}"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
data/lib/bug_bunny/resource.rb
CHANGED
|
@@ -401,6 +401,17 @@ module BugBunny
|
|
|
401
401
|
attributes['id'] || @extra_attributes['id'] || @extra_attributes['ID'] || @extra_attributes['Id'] || @extra_attributes['_id']
|
|
402
402
|
end
|
|
403
403
|
|
|
404
|
+
# Representación legible del recurso.
|
|
405
|
+
# Muestra solo ID y atributos principales, sin detalles de infraestructura.
|
|
406
|
+
#
|
|
407
|
+
# @return [String]
|
|
408
|
+
def inspect
|
|
409
|
+
infra_keys = %w[routing_key exchange exchange_type exchange_options queue_options _id]
|
|
410
|
+
attrs = @extra_attributes.merge(attributes).reject { |k, _| infra_keys.include?(k) || k == 'id' }
|
|
411
|
+
attr_str = attrs.first(5).map { |k, v| "#{k}=#{v.inspect}" }.join(' ')
|
|
412
|
+
"#<#{self.class.name} id=#{id.inspect} persisted=#{@persisted}#{" #{attr_str}" unless attr_str.empty?}>"
|
|
413
|
+
end
|
|
414
|
+
|
|
404
415
|
def id=(value)
|
|
405
416
|
if self.class.attribute_names.include?('id')
|
|
406
417
|
super
|
|
@@ -461,6 +472,7 @@ module BugBunny
|
|
|
461
472
|
# @return [Boolean]
|
|
462
473
|
def destroy
|
|
463
474
|
return false unless persisted?
|
|
475
|
+
return false unless id
|
|
464
476
|
|
|
465
477
|
run_callbacks(:destroy) do
|
|
466
478
|
path = "#{self.class.resource_name}/#{id}"
|
data/lib/bug_bunny/version.rb
CHANGED
data/lib/bug_bunny.rb
CHANGED
|
@@ -4,6 +4,7 @@ require 'bunny'
|
|
|
4
4
|
require 'logger'
|
|
5
5
|
require_relative 'bug_bunny/version'
|
|
6
6
|
require_relative 'bug_bunny/exception'
|
|
7
|
+
require_relative 'bug_bunny/remote_error'
|
|
7
8
|
require_relative 'bug_bunny/configuration'
|
|
8
9
|
require_relative 'bug_bunny/observability'
|
|
9
10
|
require_relative 'bug_bunny/otel'
|
data/skills.lock
CHANGED
|
@@ -110,4 +110,48 @@ RSpec.describe BugBunny::Resource, :integration do
|
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
112
|
end
|
|
113
|
+
|
|
114
|
+
describe '#inspect' do
|
|
115
|
+
let(:node) { SpecNode.new(id: '123', name: 'test-node', status: 'active', ip: '192.168.1.1', port: 8080) }
|
|
116
|
+
|
|
117
|
+
it 'muestra id y persisted' do
|
|
118
|
+
expect(node.inspect).to include('id="123"')
|
|
119
|
+
expect(node.inspect).to include('persisted=false')
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it 'muestra atributos principales sin detalles de infraestructura' do
|
|
123
|
+
result = node.inspect
|
|
124
|
+
|
|
125
|
+
expect(result).to include('name="test-node"')
|
|
126
|
+
expect(result).to include('status="active"')
|
|
127
|
+
expect(result).to include('ip="192.168.1.1"')
|
|
128
|
+
expect(result).to include('port=8080')
|
|
129
|
+
expect(result).not_to include('routing_key')
|
|
130
|
+
expect(result).not_to include('exchange')
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it 'filtra atributos de infraestructura cuando están presentes' do
|
|
134
|
+
node.routing_key = 'radius_1'
|
|
135
|
+
node.exchange = 'test_exchange'
|
|
136
|
+
node.exchange_type = 'topic'
|
|
137
|
+
node.exchange_options = { durable: true }
|
|
138
|
+
node.persisted = true
|
|
139
|
+
|
|
140
|
+
result = node.inspect
|
|
141
|
+
|
|
142
|
+
expect(result).not_to include('routing_key')
|
|
143
|
+
expect(result).not_to include('exchange')
|
|
144
|
+
expect(result).not_to include('exchange_type')
|
|
145
|
+
expect(result).not_to include('exchange_options')
|
|
146
|
+
expect(result).to include('persisted=true')
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'limita a 5 atributos principales' do
|
|
150
|
+
node = SpecNode.new(id: '1', a: '1', b: '2', c: '3', d: '4', e: '5', f: '6')
|
|
151
|
+
|
|
152
|
+
result = node.inspect
|
|
153
|
+
|
|
154
|
+
expect(result.scan('=').length).to be <= 7 # id + persisted + max 5 attrs
|
|
155
|
+
end
|
|
156
|
+
end
|
|
113
157
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bug_bunny
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.10.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- gabix
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bunny
|
|
@@ -249,6 +249,7 @@ files:
|
|
|
249
249
|
- lib/bug_bunny/otel.rb
|
|
250
250
|
- lib/bug_bunny/producer.rb
|
|
251
251
|
- lib/bug_bunny/railtie.rb
|
|
252
|
+
- lib/bug_bunny/remote_error.rb
|
|
252
253
|
- lib/bug_bunny/request.rb
|
|
253
254
|
- lib/bug_bunny/resource.rb
|
|
254
255
|
- lib/bug_bunny/routing/route.rb
|
|
@@ -300,7 +301,7 @@ metadata:
|
|
|
300
301
|
homepage_uri: https://github.com/gedera/bug_bunny
|
|
301
302
|
source_code_uri: https://github.com/gedera/bug_bunny
|
|
302
303
|
changelog_uri: https://github.com/gedera/bug_bunny/blob/main/CHANGELOG.md
|
|
303
|
-
documentation_uri: https://github.com/gedera/bug_bunny/blob/v4.
|
|
304
|
+
documentation_uri: https://github.com/gedera/bug_bunny/blob/v4.10.0/skill
|
|
304
305
|
post_install_message:
|
|
305
306
|
rdoc_options: []
|
|
306
307
|
require_paths:
|