Module: SolarWindsAPM::API::CurrentTraceInfo

Defined in:
lib/solarwinds_apm/api/current_trace_info.rb

Defined Under Namespace

Classes: TraceInfo

Instance Method Summary collapse

Instance Method Details

#current_trace_infoObject

Creates an instance of TraceInfo with instance methods:
SolarWindsAPM::API::CurrentTraceInfo::TraceInfo#trace_id
SolarWindsAPM::API::CurrentTraceInfo::TraceInfo#span_id
SolarWindsAPM::API::CurrentTraceInfo::TraceInfo#trace_flags
SolarWindsAPM::API::CurrentTraceInfo::TraceInfo#for_log
SolarWindsAPM::API::CurrentTraceInfo::TraceInfo#hash_for_log

The SolarWindsAPM::Config[:log_traceId] configuration setting for automatic trace context in logs affects the return value of methods in this module.

The following options are available:
:never (default)
:sampled only include the Trace ID of sampled requests
:traced include the Trace ID for all traced requests
:always always add a Trace ID, it will be “trace_id=00000000000000000000000000000000 span_id=0000000000000000 trace_flags=00 resource.service.name=otel_service_name” when there is no tracing context.

Example:

trace = SolarWindsAPM::API.current_trace_info
trace.for_log        # 'trace_id=7435a9fe510ae4533414d425dadf4e18 span_id=49e60702469db05f trace_flags=01 resource.service.name=otel_service_name' or '' depends on Config
trace.hash_for_log   # { trace_id: '7435a9fe510ae4533414d425dadf4e18',
                         span_id: '49e60702469db05f',
                         trace_flags: '',
                         resource.service.name: 'otel_service_name' }  or {} depends on Config

Configure trace info injection with lograge:

Lograge.custom_options = lambda do |event|
   SolarWindsAPM::API.current_trace_info.hash_for_log
end


44
45
46
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 44

def current_trace_info
  TraceInfo.new
end