Class: OpenTelemetry::SDK::Logs::Export::SimpleLogRecordProcessor
- Inherits:
-
LogRecordProcessor
- Object
- LogRecordProcessor
- OpenTelemetry::SDK::Logs::Export::SimpleLogRecordProcessor
- Defined in:
- lib/opentelemetry/sdk/logs/export/simple_log_record_processor.rb
Overview
An implementation of LogRecordProcessor that converts the LogRecord into a ReadableLogRecord and passes it to the configured exporter on emit.
Typically, the SimpleLogRecordProcessor will be most suitable for use in testing; it should be used with caution in production. It may be appropriate for production use in scenarios where creating multiple threads is not desirable as well as scenarios where different custom attributes should be added to individual log records based on code scopes.
Instance Method Summary collapse
-
#force_flush(timeout: nil) ⇒ Integer
Export all log records to the configured
Exporter
that have not yet been exported, then call Exporter#force_flush. -
#initialize(log_record_exporter) ⇒ SimpleLogRecordProcessor
constructor
Returns a new SimpleLogRecordProcessor that converts log records to ReadableLogRecords and forwards them to the given log_record_exporter.
-
#on_emit(log_record, _context) ⇒ Object
Called when a LogRecord is emitted.
-
#shutdown(timeout: nil) ⇒ Integer
Called when LoggerProvider#shutdown is called.
Constructor Details
#initialize(log_record_exporter) ⇒ SimpleLogRecordProcessor
Returns a new OpenTelemetry::SDK::Logs::Export::SimpleLogRecordProcessor that converts log records to ReadableLogRecords and forwards them to the given log_record_exporter.
30 31 32 33 34 35 |
# File 'lib/opentelemetry/sdk/logs/export/simple_log_record_processor.rb', line 30 def initialize(log_record_exporter) raise ArgumentError, "exporter #{log_record_exporter.inspect} does not appear to be a valid exporter" unless Common::Utilities.valid_exporter?(log_record_exporter) @log_record_exporter = log_record_exporter @stopped = false end |
Instance Method Details
#force_flush(timeout: nil) ⇒ Integer
Export all log records to the configured Exporter
that have not yet been exported, then call Exporter#force_flush.
This method should only be called in cases where it is absolutely necessary, such as when using some FaaS providers that may suspend the process after an invocation, but before the Processor
exports the completed log records.
TODO: Should a rescue/handle error be added here for non-specific failures?
65 66 67 68 69 |
# File 'lib/opentelemetry/sdk/logs/export/simple_log_record_processor.rb', line 65 def force_flush(timeout: nil) return if @stopped @log_record_exporter&.force_flush(timeout: timeout) || SUCCESS end |
#on_emit(log_record, _context) ⇒ Object
Called when a LogRecord is emitted.
This method is called synchronously on the execution thread. It should not throw or block the execution thread. It may not be called after shutdown.
45 46 47 48 49 50 51 |
# File 'lib/opentelemetry/sdk/logs/export/simple_log_record_processor.rb', line 45 def on_emit(log_record, _context) return if @stopped @log_record_exporter&.export([log_record.to_log_record_data]) rescue => e # rubocop:disable Style/RescueStandardError OpenTelemetry.handle_error(exception: e, message: 'Unexpected error in Logger#on_emit') end |
#shutdown(timeout: nil) ⇒ Integer
Called when LoggerProvider#shutdown is called.
TODO: Should a rescue/handle error be added here for non-specific failures?
77 78 79 80 81 82 83 |
# File 'lib/opentelemetry/sdk/logs/export/simple_log_record_processor.rb', line 77 def shutdown(timeout: nil) return if @stopped @log_record_exporter&.shutdown(timeout: timeout) || SUCCESS ensure @stopped = true end |