Class: Julewire::GCP::Formatter
- Inherits:
-
Object
- Object
- Julewire::GCP::Formatter
- Defined in:
- lib/julewire/gcp/formatter.rb
Constant Summary collapse
- SEVERITIES =
{ debug: "DEBUG", info: "INFO", warn: "WARNING", error: "ERROR", fatal: "CRITICAL", unknown: "DEFAULT" }.freeze
Instance Method Summary collapse
- #call(record) ⇒ Object
-
#initialize(project_id: nil, operation_producer: nil, service_context: nil, trace_headers_paths: [ %i[carry http request_headers], %i[payload request_headers], %i[context request_headers] ], **options) ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize(project_id: nil, operation_producer: nil, service_context: nil, trace_headers_paths: [ %i[carry http request_headers], %i[payload request_headers], %i[context request_headers] ], **options) ⇒ Formatter
Returns a new instance of Formatter.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/julewire/gcp/formatter.rb', line 18 def initialize(project_id: nil, operation_producer: nil, service_context: nil, trace_headers_paths: [ %i[carry http request_headers], %i[payload request_headers], %i[context request_headers] ], **) FormatterOptions.validate!() @project_id = project_id @operation_producer = operation_producer @service_context = frozen_service_context(service_context) @trace_headers_paths = FormatterOptions.trace_headers_paths(trace_headers_paths) @label_formatter = FormatterOptions.label_formatter() @trace_id_path = FormatterOptions.trace_value_path([:trace_id_path]) @span_id_path = FormatterOptions.trace_value_path([:span_id_path]) @trace_sampled_path = FormatterOptions.trace_value_path([:trace_sampled_path]) @execution_payload = ExecutionPayload.new( trace_id_path: @trace_id_path, span_id_path: @span_id_path, trace_sampled_path: @trace_sampled_path ) end |
Instance Method Details
#call(record) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/julewire/gcp/formatter.rb', line 43 def call(record) Julewire::Record.validate_normalized!(record) error = record.fetch(:error) = (record) neutral_attributes = Core::Fields::AttributeKeys.from(record.fetch(:neutral)) = SourceLocationOptions.call(record, neutral_attributes) entry = { "severity" => severity(record.fetch(:severity)), "time" => record.fetch(:timestamp) } append_log_field(entry, "message", Core::Records::DisplayMessage.call(record)) entry.tap do |log_entry| append_special_fields( log_entry, record, error: error, operation_options: , source_location_options: , neutral_attributes: neutral_attributes ) append_payload_fields(log_entry, record, error: error, operation_options: ) end end |