Class: AppOpticsAPM::SDK::CurrentTrace::TraceId
- Inherits:
-
Object
- Object
- AppOpticsAPM::SDK::CurrentTrace::TraceId
- Defined in:
- lib/appoptics_apm/sdk/current_trace.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
the current traceId, it looks like: ‘7435A9FE510AE4533414D425DADF4E180D2B4E36-0’ and ends in ‘-1’ if the request is sampled and ‘-0’ otherwise.
Instance Method Summary collapse
-
#for_log ⇒ Object
for_log returns a string in the format ‘traceId=<current_trace.id>’ or ”.
- #hash_for_log ⇒ Object
-
#initialize ⇒ TraceId
constructor
A new instance of TraceId.
-
#log? ⇒ Boolean
should the traceId be added to the log?.
Constructor Details
#initialize ⇒ TraceId
Returns a new instance of TraceId.
39 40 41 42 43 44 |
# File 'lib/appoptics_apm/sdk/current_trace.rb', line 39 def initialize @xtrace = AppOpticsAPM::Context.toString task_id = AppOpticsAPM::XTrace.task_id(@xtrace) sampled = AppOpticsAPM::XTrace.sampled?(@xtrace) @id = "#{task_id}-#{sampled ? 1 : 0}" end |
Instance Attribute Details
#id ⇒ Object
the current traceId, it looks like: ‘7435A9FE510AE4533414D425DADF4E180D2B4E36-0’ and ends in ‘-1’ if the request is sampled and ‘-0’ otherwise. Results in ‘0000000000000000000000000000000000000000-0’ if the CurrentTrace instance was created outside of the context of a request.
36 37 38 |
# File 'lib/appoptics_apm/sdk/current_trace.rb', line 36 def id @id end |
Instance Method Details
#for_log ⇒ Object
for_log returns a string in the format ‘traceId=<current_trace.id>’ or ”.
An empty string is returned depending on the setting for
<tt>AppOpticsAPM::Config[:log_traceId]</tt>, which can be :never,
:sampled, :traced, or :always.
51 52 53 |
# File 'lib/appoptics_apm/sdk/current_trace.rb', line 51 def for_log @for_log ||= log? ? "ao.traceId=#{@id}" : '' end |
#hash_for_log ⇒ Object
55 56 57 |
# File 'lib/appoptics_apm/sdk/current_trace.rb', line 55 def hash_for_log @hash_for_log ||= log? ? { ao: { traceId: @id } } : {} end |
#log? ⇒ Boolean
should the traceId be added to the log?
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/appoptics_apm/sdk/current_trace.rb', line 59 def log? # should the traceId be added to the log? case AppOpticsAPM::Config[:log_traceId] when :never, nil false when :always AppOpticsAPM::XTrace.ok?(@xtrace) when :traced AppOpticsAPM::XTrace.valid?(@xtrace) when :sampled AppOpticsAPM::XTrace.sampled?(@xtrace) end end |