Class: Coolhand::LoggerService
- Inherits:
-
ApiService
- Object
- ApiService
- Coolhand::LoggerService
- Defined in:
- lib/coolhand/logger_service.rb
Instance Attribute Summary
Attributes inherited from ApiService
Instance Method Summary collapse
-
#forward_webhook(webhook_body:, source:, event_type: nil, headers: {}, **options) ⇒ Object
Helper method for forwarding webhook data to Coolhand.
-
#initialize ⇒ LoggerService
constructor
A new instance of LoggerService.
- #log_to_api(captured_data) ⇒ Object
Methods inherited from ApiService
#api_key, #base_url, #configuration, #debug_mode?, #send_llm_request_log, #silent
Constructor Details
#initialize ⇒ LoggerService
Returns a new instance of LoggerService.
7 8 9 |
# File 'lib/coolhand/logger_service.rb', line 7 def initialize super("v2/llm_request_logs") end |
Instance Method Details
#forward_webhook(webhook_body:, source:, event_type: nil, headers: {}, **options) ⇒ Object
Helper method for forwarding webhook data to Coolhand
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/coolhand/logger_service.rb', line 16 def forward_webhook(webhook_body:, source:, event_type: nil, headers: {}, **) # Validate required parameters unless Coolhand.required_field?(webhook_body) error_msg = "webhook_body is required and cannot be nil or empty" if Coolhand.configuration.silent puts "COOLHAND WARNING: #{error_msg}" return false else raise ArgumentError, error_msg end end unless Coolhand.required_field?(source) error_msg = "source is required and cannot be nil or empty" if Coolhand.configuration.silent puts "COOLHAND WARNING: #{error_msg}" return false else raise ArgumentError, error_msg end end # Auto-generate required fields unless provided webhook_data = { id: [:id] || SecureRandom.uuid, timestamp: [:timestamp] || Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%6NZ"), method: [:method] || "POST", url: [:url] || build_webhook_url(source, event_type), headers: sanitize_headers(headers), request_body: clean_webhook_body(webhook_body, source), response_body: [:response_body], response_headers: [:response_headers], status_code: [:status_code] || 200, source: "#{source}_webhook" }.merge(.slice(:metadata, :conversation_id, :agent_id)) # Send to API asynchronously log_to_api(webhook_data) end |
#log_to_api(captured_data) ⇒ Object
11 12 13 |
# File 'lib/coolhand/logger_service.rb', line 11 def log_to_api(captured_data) create_log(captured_data, "auto-monitor") end |