Class: AllStak::Modules::HttpMonitor
- Inherits:
-
Object
- Object
- AllStak::Modules::HttpMonitor
- Defined in:
- lib/allstak/modules/http_monitor.rb
Overview
Buffers + batches HTTP request telemetry (inbound and outbound). Max batch: 100.
Constant Summary collapse
- PATH =
"/ingest/v1/http-requests".freeze
- MAX_BATCH =
100
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(transport, config, logger) ⇒ HttpMonitor
constructor
A new instance of HttpMonitor.
- #record(direction:, method:, host:, path:, status_code:, duration_ms:, request_size: 0, response_size: 0, trace_id: nil, user_id: nil, error_fingerprint: nil, span_id: nil, parent_span_id: nil) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(transport, config, logger) ⇒ HttpMonitor
Returns a new instance of HttpMonitor.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/allstak/modules/http_monitor.rb', line 11 def initialize(transport, config, logger) @transport = transport @config = config @logger = logger @buffer = Transport::FlushBuffer.new( name: "http", max_size: config.buffer_size, interval_ms: config.flush_interval_ms, flush_proc: method(:flush_batch), logger: logger ) end |
Instance Method Details
#flush ⇒ Object
49 50 51 |
# File 'lib/allstak/modules/http_monitor.rb', line 49 def flush @buffer.flush end |
#record(direction:, method:, host:, path:, status_code:, duration_ms:, request_size: 0, response_size: 0, trace_id: nil, user_id: nil, error_fingerprint: nil, span_id: nil, parent_span_id: nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/allstak/modules/http_monitor.rb', line 24 def record(direction:, method:, host:, path:, status_code:, duration_ms:, request_size: 0, response_size: 0, trace_id: nil, user_id: nil, error_fingerprint: nil, span_id: nil, parent_span_id: nil) return if @transport.disabled? item = { direction: direction, method: method.to_s.upcase, host: host.to_s, path: strip_query(path.to_s), statusCode: status_code.to_i, durationMs: [duration_ms.to_i, 0].max, requestSize: request_size.to_i, responseSize: response_size.to_i, timestamp: Time.now.utc.iso8601(3), traceId: trace_id || SecureRandom.hex(16), userId: user_id, errorFingerprint: error_fingerprint, spanId: span_id, parentSpanId: parent_span_id, environment: @config.environment, release: @config.release }.compact @buffer.push(item) end |
#shutdown ⇒ Object
53 54 55 |
# File 'lib/allstak/modules/http_monitor.rb', line 53 def shutdown @buffer.shutdown end |