Module: AppPerfRpm

Defined in:
lib/app_perf_rpm.rb,
lib/app_perf_rpm/utils.rb,
lib/app_perf_rpm/logger.rb,
lib/app_perf_rpm/tracer.rb,
lib/app_perf_rpm/railtie.rb,
lib/app_perf_rpm/backtrace.rb,
lib/app_perf_rpm/introspector.rb,
lib/app_perf_rpm/tracing/span.rb,
lib/app_perf_rpm/configuration.rb,
lib/app_perf_rpm/tracing/buffer.rb,
lib/app_perf_rpm/tracing/tracer.rb,
lib/app_perf_rpm/instrumentation.rb,
lib/app_perf_rpm/tracing/carrier.rb,
lib/app_perf_rpm/instruments/rack.rb,
lib/app_perf_rpm/instruments/rack.rb,
lib/app_perf_rpm/tracing/endpoint.rb,
lib/app_perf_rpm/tracing/trace_id.rb,
lib/app_perf_rpm/instruments/grape.rb,
lib/app_perf_rpm/tracing/collector.rb,
lib/app_perf_rpm/instruments/sequel.rb,
lib/app_perf_rpm/instruments/faraday.rb,
lib/app_perf_rpm/instruments/sidekiq.rb,
lib/app_perf_rpm/instruments/sinatra.rb,
lib/app_perf_rpm/instruments/typhoeus.rb,
lib/app_perf_rpm/tracing/managed_span.rb,
lib/app_perf_rpm/tracing/span_context.rb,
lib/app_perf_rpm/reporters/json_client.rb,
lib/app_perf_rpm/reporters/null_client.rb,
lib/app_perf_rpm/tracing/managed_tracer.rb,
lib/app_perf_rpm/instruments/active_record.rb,
lib/app_perf_rpm/tracing/thread_span_stack.rb,
lib/app_perf_rpm/instruments/emque_consuming.rb,
lib/app_perf_rpm/instruments/action_controller.rb,
lib/app_perf_rpm/instruments/activerecord_import.rb,
lib/app_perf_rpm/instruments/active_record/adapters/mysql2.rb,
lib/app_perf_rpm/instruments/active_record/adapters/sqlite3.rb,
lib/app_perf_rpm/instruments/active_record/adapters/postgresql.rb

Defined Under Namespace

Modules: Instruments, Reporters, Tracing, Utils Classes: Backtrace, Configuration, Instrumentation, Introspector, Logger, Railtie, SidekiqClient, SidekiqServer, Tracer

Constant Summary collapse

TRACE_CONTEXT_KEY =
'AppPerf-Trace-Context'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject



37
38
39
# File 'lib/app_perf_rpm.rb', line 37

def config
  @config ||= Configuration.new
end

.loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/app_perf_rpm/logger.rb', line 7

def logger
  @logger
end

Class Method Details

.collectorObject



61
62
63
# File 'lib/app_perf_rpm.rb', line 61

def collector
  @collector ||= AppPerfRpm::Tracing::Collector.new(endpoint)
end

.configure {|config| ... } ⇒ Object

Yields:



41
42
43
# File 'lib/app_perf_rpm.rb', line 41

def configure
  yield(config)
end

.disable_agent?Boolean

Returns:

  • (Boolean)


144
145
146
147
148
149
150
151
152
# File 'lib/app_perf_rpm.rb', line 144

def disable_agent?
  if config.agent_disabled
    true
  elsif Introspector.agentable?
    false
  else
    true
  end
end

.endpointObject



57
58
59
# File 'lib/app_perf_rpm.rb', line 57

def endpoint
  @endpoint ||= AppPerfRpm::Tracing::Endpoint.local_endpoint(config.application_name)
end

.floor_time(t, sec = 1) ⇒ Object



140
141
142
# File 'lib/app_perf_rpm.rb', line 140

def floor_time(t, sec = 1)
  Time.at((t.to_f / sec).floor * sec)
end

.hostObject



120
121
122
# File 'lib/app_perf_rpm.rb', line 120

def host
  @host ||= Socket.gethostname
end

.loadObject



45
46
47
48
49
50
51
# File 'lib/app_perf_rpm.rb', line 45

def load
  #Oj.mimic_JSON
  unless disable_agent?
    AppPerfRpm::Instrumentation.load
    AppPerfRpm.tracing_on
  end
end

.mutexObject



53
54
55
# File 'lib/app_perf_rpm.rb', line 53

def mutex
  @mutex ||= Mutex.new
end

.nowObject



154
155
156
157
158
159
160
# File 'lib/app_perf_rpm.rb', line 154

def now
  if defined?(Process::CLOCK_REALTIME)
    Process.clock_gettime(Process::CLOCK_REALTIME)
  else
    Time.now
  end
end

.round_time(t, sec = 1) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/app_perf_rpm.rb', line 124

def round_time(t, sec = 1)
  t = Time.parse(t.to_s)

  down = t - (t.to_i % sec)
  up = down + sec

  difference_down = t - down
  difference_up = up - t

  if (difference_down < difference_up)
    return down
  else
    return up
  end
end

.senderObject



69
70
71
72
73
74
75
# File 'lib/app_perf_rpm.rb', line 69

def sender
  @sender ||= AppPerfRpm::Reporters::JsonClient.new(
    url: url,
    collector: collector,
    flush_interval: config.flush_interval
  )
end

.tracerObject



77
78
79
80
81
82
83
84
85
86
# File 'lib/app_perf_rpm.rb', line 77

def tracer
  @tracer ||= AppPerfRpm::Tracing::ManagedTracer.new(
    AppPerfRpm::Tracing::Tracer.build(
      :service_name => config.application_name,
      :sender => sender,
      :collector => collector
    ),
    AppPerfRpm::Tracing::ThreadSpanStack.new
  )
end

.tracing?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/app_perf_rpm.rb', line 106

def tracing?
  !!@tracing
end

.tracing_offObject



99
100
101
102
103
104
# File 'lib/app_perf_rpm.rb', line 99

def tracing_off
  mutex.synchronize do
    AppPerfRpm.logger.debug "Disabling tracing."
    @tracing = false
  end
end

.tracing_onObject



88
89
90
91
92
93
94
95
96
97
# File 'lib/app_perf_rpm.rb', line 88

def tracing_on
  if @without_tracing_enabled
    AppPerfRpm.logger.debug "Not turning tracing on due to without tracing mode."
    return
  end
  mutex.synchronize do
    AppPerfRpm.logger.debug "Enabling tracing."
    @tracing = true
  end
end

.urlObject



65
66
67
# File 'lib/app_perf_rpm.rb', line 65

def url
  @url ||= "#{config.host}/api/listener/3/#{config.license_key}"
end

.without_tracingObject



110
111
112
113
114
115
116
117
118
# File 'lib/app_perf_rpm.rb', line 110

def without_tracing
  @previously_tracing = AppPerfRpm.tracing?
  @without_tracing_enabled = true
  AppPerfRpm.tracing_off
  yield if block_given?
  @without_tracing_enabled = false
ensure
  AppPerfRpm.tracing_on if @previously_tracing
end