Class: SolarWindsAPM::API::CurrentTraceInfo::TraceInfo
- Inherits:
-
Object
- Object
- SolarWindsAPM::API::CurrentTraceInfo::TraceInfo
- Defined in:
- lib/solarwinds_apm/api/current_trace_info.rb
Instance Attribute Summary collapse
-
#do_log ⇒ Boolean
The current value of do_log.
-
#span_id ⇒ String
The current value of span_id.
-
#trace_flags ⇒ String
The current value of trace_flags.
-
#trace_id ⇒ String
The current value of trace_id.
-
#tracestring ⇒ String
The current value of tracestring.
Instance Method Summary collapse
-
#for_log ⇒ Object
for_log returns a string in the format ‘trace_id=<trace_id> span_id=<span_id> trace_flags=<trace_flags>’ or empty string.
-
#hash_for_log ⇒ Object
Construct the trace_id, span_id, trace_flags and resource.service.name for log insertion.
-
#initialize ⇒ TraceInfo
constructor
A new instance of TraceInfo.
Constructor Details
#initialize ⇒ TraceInfo
Returns a new instance of TraceInfo.
59 60 61 62 63 |
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 59 def initialize @trace_id, @span_id, @trace_flags, @tracestring = current_span @service_name = ENV.fetch('OTEL_SERVICE_NAME', nil) @do_log = log? # true if the tracecontext should be added to logs end |
Instance Attribute Details
#do_log ⇒ Boolean
Returns the current value of do_log.
53 54 55 |
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 53 def do_log @do_log end |
#span_id ⇒ String
Returns the current value of span_id.
53 54 55 |
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 53 def span_id @span_id end |
#trace_flags ⇒ String
Returns the current value of trace_flags.
53 54 55 |
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 53 def trace_flags @trace_flags end |
#trace_id ⇒ String
Returns the current value of trace_id.
53 54 55 |
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 53 def trace_id @trace_id end |
#tracestring ⇒ String
Returns the current value of tracestring.
53 54 55 |
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 53 def tracestring @tracestring end |
Instance Method Details
#for_log ⇒ Object
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
80 81 82 |
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 80 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_log ⇒ Object
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
102 103 104 105 106 107 108 109 |
# File 'lib/solarwinds_apm/api/current_trace_info.rb', line 102 def hash_for_log @hash_for_log = if @do_log { 'trace_id' => @trace_id, 'span_id' => @span_id, 'trace_flags' => @trace_flags, 'resource.service.name' => @service_name } else {} end end |