Class: AppOpticsAPM::SDK::CurrentTrace::TraceId

Inherits:
Object
  • Object
show all
Defined in:
lib/appoptics_apm/sdk/current_trace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTraceId

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

#idObject

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.

Returns:

  • (Object)

    the current value of id



36
37
38
# File 'lib/appoptics_apm/sdk/current_trace.rb', line 36

def id
  @id
end

Instance Method Details

#for_logObject

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_logObject



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?

Returns:

  • (Boolean)


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