Class: SolarWindsAPM::API::CurrentTraceInfo::TraceInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/solarwinds_apm/api/current_trace_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTraceInfo

Returns a new instance of TraceInfo.



57
58
59
60
61
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 57

def initialize
  @trace_id, @span_id, @trace_flags, @tracestring = current_span
  @service_name = ENV['OTEL_SERVICE_NAME']
  @do_log = log? # true if the tracecontext should be added to logs
end

Instance Attribute Details

#do_logBoolean

Returns the current value of do_log.

Returns:

  • (Boolean)

    the current value of do_log



51
52
53
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 51

def do_log
  @do_log
end

#span_idString

Returns the current value of span_id.

Returns:

  • (String)

    the current value of span_id



51
52
53
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 51

def span_id
  @span_id
end

#trace_flagsString

Returns the current value of trace_flags.

Returns:

  • (String)

    the current value of trace_flags



51
52
53
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 51

def trace_flags
  @trace_flags
end

#trace_idString

Returns the current value of trace_id.

Returns:

  • (String)

    the current value of trace_id



51
52
53
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 51

def trace_id
  @trace_id
end

#tracestringString

Returns the current value of tracestring.

Returns:

  • (String)

    the current value of tracestring



51
52
53
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 51

def tracestring
  @tracestring
end

Instance Method Details

#for_logObject

for_log returns a string in the format ‘trace_id=<trace_id> span_id=<span_id> trace_flags=<trace_flags>’ or empty string.

An empty string is returned depending on the setting for SolarWindsAPM::Config[:log_traceId], which can be :never, :sampled, :traced, or :always.

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

Returns:

  • String



78
79
80
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 78

def for_log
  @for_log ||= @do_log ? "trace_id=#{@trace_id} span_id=#{@span_id} trace_flags=#{@trace_flags} resource.service.name=#{@service_name}" : ''
end

#hash_for_logObject

Construct the trace_id, span_id, trace_flags and resource.service.name for log insertion.

Example:

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

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

Returns:

  • Hash



100
101
102
103
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 100

def hash_for_log
  @hash_for_log = {}
  @hash_for_log = {trace_id: @trace_id, span_id: @span_id, trace_flags: @trace_flags, service_name: @service_name} if @do_log
end