Class: Chronos::Application::CaptureTelemetry
- Inherits:
-
Object
- Object
- Chronos::Application::CaptureTelemetry
- Defined in:
- lib/chronos/application/capture_telemetry.rb
Overview
Coordinates bounded non-exception telemetry capture.
Instance Method Summary collapse
- #call(event_type, payload = {}, context = {}) ⇒ Object
- #diagnostics ⇒ Object
- #flush ⇒ Object
-
#initialize(config, delivery_pipeline, logger = nil, options = {}) ⇒ CaptureTelemetry
constructor
A new instance of CaptureTelemetry.
Constructor Details
#initialize(config, delivery_pipeline, logger = nil, options = {}) ⇒ CaptureTelemetry
Returns a new instance of CaptureTelemetry.
16 17 18 19 20 21 22 23 24 |
# File 'lib/chronos/application/capture_telemetry.rb', line 16 def initialize(config, delivery_pipeline, logger = nil, = {}) @config = config @delivery_pipeline = delivery_pipeline @logger = logger || Internal::SafeLogger.new(config.logger) @serializer = [:serializer] || Core::TelemetrySerializer.new( config, nil, :max_payload_size => proc { @delivery_pipeline.max_payload_size } ) @aggregator = [:aggregator] || ApmAggregator.new(config) end |
Instance Method Details
#call(event_type, payload = {}, context = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/chronos/application/capture_telemetry.rb', line 26 def call(event_type, payload = {}, context = {}) return false unless @config.enabled_for_environment? return false unless @delivery_pipeline.capture_allowed?(event_type) aggregate = aggregation_enabled? batches = aggregate ? @aggregator.record(event_type, payload, context) : [] return enqueue_batches(batches) if aggregate && aggregate_type?(event_type) event = Core::TelemetryEvent.new(event_type, payload, context) delivered = @delivery_pipeline.enqueue(@serializer.call(event)) enqueue_batches(batches) delivered rescue StandardError => error @logger.warn("Chronos telemetry capture failed: #{error.class}") false end |
#diagnostics ⇒ Object
50 51 52 53 54 |
# File 'lib/chronos/application/capture_telemetry.rb', line 50 def diagnostics @aggregator.diagnostics rescue StandardError {} end |
#flush ⇒ Object
43 44 45 46 47 48 |
# File 'lib/chronos/application/capture_telemetry.rb', line 43 def flush enqueue_batches(@aggregator.flush) rescue StandardError => error @logger.warn("Chronos APM flush failed: #{error.class}") false end |