Module: A2A::Monitoring::Instrumentation
- Defined in:
- lib/a2a/monitoring.rb
Overview
Request/Response instrumentation
Class Method Summary collapse
-
.instrument_request(request) { ... } ⇒ Object
Instrument A2A request.
-
.instrument_task(task_id, operation) { ... } ⇒ Object
Instrument task operations.
Class Method Details
.instrument_request(request) { ... } ⇒ Object
Instrument A2A request
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/a2a/monitoring.rb', line 405 def self.instrument_request(request) method = request[:method] || "unknown" labels = { method: method } A2A::Monitoring.increment_counter("a2a_requests", **labels) A2A::Monitoring.time("a2a_request_duration", **labels) do correlation_id = request[:id] || SecureRandom.hex(8) A2A::Monitoring.logger.with_correlation_id(correlation_id) do A2A::Monitoring.log(:info, "Processing A2A request", method: method, request_id: correlation_id) begin result = yield A2A::Monitoring.increment_counter("a2a_requests_success", **labels) A2A::Monitoring.log(:info, "A2A request completed", method: method, request_id: correlation_id) result rescue StandardError => e A2A::Monitoring.increment_counter("a2a_requests_error", **labels, error_type: e.class.name) A2A::Monitoring.log(:error, "A2A request failed", method: method, request_id: correlation_id, error: e.) raise end end end end |
.instrument_task(task_id, operation) { ... } ⇒ Object
Instrument task operations
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
# File 'lib/a2a/monitoring.rb', line 437 def self.instrument_task(task_id, operation) labels = { operation: operation } A2A::Monitoring.increment_counter("a2a_task_operations", **labels) A2A::Monitoring.time("a2a_task_operation_duration", **labels) do A2A::Monitoring.logger.with_correlation_id(task_id) do A2A::Monitoring.log(:info, "Task operation started", task_id: task_id, operation: operation) begin result = yield A2A::Monitoring.increment_counter("a2a_task_operations_success", **labels) A2A::Monitoring.log(:info, "Task operation completed", task_id: task_id, operation: operation) result rescue StandardError => e A2A::Monitoring.increment_counter("a2a_task_operations_error", **labels, error_type: e.class.name) A2A::Monitoring.log(:error, "Task operation failed", task_id: task_id, operation: operation, error: e.) raise end end end end |