Class: SemanticLogger::Formatters::OpenTelemetry
- Defined in:
- lib/semantic_logger/formatters/open_telemetry.rb
Constant Summary collapse
- PRIMS =
primitives allowed by OTLP logs in Ruby: String, Integer, Float, TrueClass, FalseClass
[String, Integer, Float, TrueClass, FalseClass].freeze
Instance Attribute Summary
Attributes inherited from Raw
Attributes inherited from Base
#filter, #instance_named_tags, #instance_tags, #name
Instance Method Summary collapse
-
#call(log, logger) ⇒ Object
Returns the attributes hash submitted to the OpenTelemetry SDK.
-
#level ⇒ Object
Log level.
-
#payload ⇒ Object
Payload is submitted directly as attributes.
Methods inherited from Raw
#application, #duration, #environment, #exception, #file_name_and_line, #host, #initialize, #message, #metric, #name, #named_tags, #pid, #tags, #thread_name, #time
Methods inherited from Base
#backtrace, #fast_tag, #level=, #log, #measure, #named_tags, #pop_tags, #push_tags, #should_log?, #silence, #tagged, #tags, #with_level
Constructor Details
This class inherits a constructor from SemanticLogger::Formatters::Raw
Instance Method Details
#call(log, logger) ⇒ Object
Returns the attributes hash submitted to the OpenTelemetry SDK.
Unlike the JSON formatters there is no single .to_json boundary here:
the hash is handed to the OTLP exporter, which requires valid UTF-8. Cleanse
the whole structure so binary / non UTF-8 strings cannot break the export.
13 14 15 |
# File 'lib/semantic_logger/formatters/open_telemetry.rb', line 13 def call(log, logger) Utils.encode_utf8(super) end |
#level ⇒ Object
Log level
18 19 20 21 |
# File 'lib/semantic_logger/formatters/open_telemetry.rb', line 18 def level hash[:level] = log.level.to_s hash[:level_index] = severity_number(log.level) end |
#payload ⇒ Object
Payload is submitted directly as attributes
24 25 26 27 28 |
# File 'lib/semantic_logger/formatters/open_telemetry.rb', line 24 def payload return unless log.payload.respond_to?(:empty?) && !log.payload.empty? hash[:payload] = coerce_map(log.payload) end |