Class: PactBroker::Logging::TraceAwareJsonFormatter

Inherits:
SemanticLogger::Formatters::Json
  • Object
show all
Defined in:
lib/pact_broker/logging/trace_aware_json_formatter.rb

Overview

A JSON log formatter that adds the standard OpenTelemetry log-correlation fields (trace_id, span_id, trace_flags) when a valid span is active. Degrades to plain JSON when OTel is not loaded or there is no active span, so it is safe for the open-source Pact Broker.

Instance Method Summary collapse

Instance Method Details

#call(log, logger) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/pact_broker/logging/trace_aware_json_formatter.rb', line 11

def call(log, logger)
  json = super
  context = otel_trace_context
  return json if context.empty?

  # `hash` was populated by Raw#call during `super`; reuse it.
  SemanticLogger::Utils.to_json(hash.merge(context))
end