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/instruments/roda.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/instruments/redis.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
.config ⇒ Object
38
39
40
|
# File 'lib/app_perf_rpm.rb', line 38
def config
@config ||= Configuration.new
end
|
.logger ⇒ Object
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
.collector ⇒ Object
62
63
64
|
# File 'lib/app_perf_rpm.rb', line 62
def collector
@collector ||= AppPerfRpm::Tracing::Collector.new(endpoint)
end
|
42
43
44
|
# File 'lib/app_perf_rpm.rb', line 42
def configure
yield(config)
end
|
.disable_agent? ⇒ Boolean
145
146
147
148
149
150
151
152
153
|
# File 'lib/app_perf_rpm.rb', line 145
def disable_agent?
if config.agent_disabled
true
elsif Introspector.agentable?
false
else
true
end
end
|
.endpoint ⇒ Object
58
59
60
|
# File 'lib/app_perf_rpm.rb', line 58
def endpoint
@endpoint ||= AppPerfRpm::Tracing::Endpoint.local_endpoint(config.application_name)
end
|
.floor_time(t, sec = 1) ⇒ Object
141
142
143
|
# File 'lib/app_perf_rpm.rb', line 141
def floor_time(t, sec = 1)
Time.at((t.to_f / sec).floor * sec)
end
|
.host ⇒ Object
121
122
123
|
# File 'lib/app_perf_rpm.rb', line 121
def host
@host ||= Socket.gethostname
end
|
.load ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/app_perf_rpm.rb', line 46
def load
unless disable_agent?
AppPerfRpm::Instrumentation.load
AppPerfRpm.tracing_on
end
end
|
.mutex ⇒ Object
54
55
56
|
# File 'lib/app_perf_rpm.rb', line 54
def mutex
@mutex ||= Mutex.new
end
|
.now ⇒ Object
155
156
157
158
159
160
161
|
# File 'lib/app_perf_rpm.rb', line 155
def now
if defined?(Process::CLOCK_REALTIME)
Process.clock_gettime(Process::CLOCK_REALTIME)
else
Time.now
end
end
|
.round_time(t, sec = 1) ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/app_perf_rpm.rb', line 125
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
|
.sender ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/app_perf_rpm.rb', line 70
def sender
@sender ||= AppPerfRpm::Reporters::JsonClient.new(
url: url,
collector: collector,
flush_interval: config.flush_interval
)
end
|
.tracer ⇒ Object
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/app_perf_rpm.rb', line 78
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
107
108
109
|
# File 'lib/app_perf_rpm.rb', line 107
def tracing?
!!@tracing
end
|
.tracing_off ⇒ Object
100
101
102
103
104
105
|
# File 'lib/app_perf_rpm.rb', line 100
def tracing_off
mutex.synchronize do
AppPerfRpm.logger.debug "Disabling tracing."
@tracing = false
end
end
|
.tracing_on ⇒ Object
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/app_perf_rpm.rb', line 89
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
|
.url ⇒ Object
66
67
68
|
# File 'lib/app_perf_rpm.rb', line 66
def url
@url ||= "#{config.host}/api/listener/3/#{config.license_key}"
end
|
.without_tracing ⇒ Object
111
112
113
114
115
116
117
118
119
|
# File 'lib/app_perf_rpm.rb', line 111
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
|