Module: Splunk::Otel::Logging

Defined in:
lib/splunk/otel/logging.rb

Overview

functions for log correlation

Class Method Summary collapse

Class Method Details

.format_correlationObject

return log formatted trace context



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/splunk/otel/logging.rb', line 8

def format_correlation
  resource_attributes = OpenTelemetry.tracer_provider.resource.attribute_enumerator.to_h
  service_name = resource_attributes["service.name"]
  span = OpenTelemetry::Trace.current_span

  if span == OpenTelemetry::Trace::Span::INVALID
    "service.name=#{service_name}"
  else
    %W[service.name=#{service_name} trace_id=#{span.context.hex_trace_id}
       span_id=#{span.context.hex_span_id}].join(" ")
  end
end