Module: LogjamAgent
- Extended by:
- RequestHandling
- Defined in:
- lib/logjam_agent/sinatra.rb,
lib/logjam_agent.rb,
lib/logjam_agent/util.rb,
lib/logjam_agent/railtie.rb,
lib/logjam_agent/request.rb,
lib/logjam_agent/sinatra.rb,
lib/logjam_agent/version.rb,
lib/logjam_agent/receiver.rb,
lib/logjam_agent/forwarders.rb,
lib/logjam_agent/middleware.rb,
lib/logjam_agent/rack/logger.rb,
lib/logjam_agent/zmq_forwarder.rb,
lib/logjam_agent/syslog_like_formatter.rb,
lib/logjam_agent/actionpack/lib/action_dispatch/middleware/remote_ip.rb,
lib/logjam_agent/buffered_logger.rb,
lib/logjam_agent.rb
Overview
Patch Sinatra’s render logic to compute corrected view times.
Defined Under Namespace
Modules: ActionDispatch, ComputeRenderTimes, Forwarders, Rack, RequestHandling, Sinatra, Util
Classes: BufferedLogger, CallerTimeoutExceeded, ConsoleFormatter, ForwardingError, ForwardingWarning, Middleware, NegativeWaitTime, Railtie, Receiver, Request, SyslogLikeFormatter, ZMQForwarder
Constant Summary
collapse
- VERSION =
"0.32.1"
- NO_COMPRESSION =
0
- ZLIB_COMPRESSION =
1
- SNAPPY_COMPRESSION =
2
- LZ4_COMPRESSION =
3
Class Method Summary
collapse
finish_request, request, request=, start_request
Class Method Details
.add_forwarder(type, *args) ⇒ Object
305
306
307
308
309
310
311
|
# File 'lib/logjam_agent.rb', line 305
def self.add_forwarder(type, *args)
case type
when :zmq then Forwarders.add(ZMQForwarder.new(*args))
when :amqp then ArgumentError.new("logjam amqp transport no longer supported")
else raise ArgumentError.new("unkown logjam transport: '#{type}'")
end
end
|
.auto_detect_exception(exception_class) ⇒ Object
208
209
210
211
212
213
|
# File 'lib/logjam_agent.rb', line 208
def self.auto_detect_exception(exception_class)
if (class_name = exception_class.to_s) =~ /^[\w:]+$/
exception_classes << class_name unless exception_classes.include?(class_name)
end
end
|
.auto_detect_logged_exceptions ⇒ Object
226
227
228
229
230
231
232
233
234
235
236
|
# File 'lib/logjam_agent.rb', line 226
def self.auto_detect_logged_exceptions
return if @_exception_auto_detection_initialized
determine_loaded_exception_classes
Exception.class_eval <<-"EOS"
def self.inherited(subclass)
::LogjamAgent.auto_detect_exception(subclass)
::LogjamAgent.reset_exception_matcher
end
EOS
@_exception_auto_detection_initialized = true
end
|
.compression_method=(compression_method) ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/logjam_agent.rb', line 132
def self.compression_method=(compression_method)
case compression_method
when SNAPPY_COMPRESSION
begin
require "snappy"
@@compression_method = SNAPPY_COMPRESSION
rescue LoadError
end
when LZ4_COMPRESSION
begin
require "ruby-lz4"
@@compression_method = LZ4_COMPRESSION
rescue LoadError
end
when NO_COMPRESSION, ZLIB_COMPRESSION
@@compression_method = compression_method
else
raise ArgumentError.new("unknown compression method")
end
end
|
.cookie_obfuscator ⇒ Object
.decode_payload(data) ⇒ Object
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
# File 'lib/logjam_agent.rb', line 279
def self.decode_payload(data)
case compression_method
when SNAPPY_COMPRESSION
Snappy.inflate(data)
when LZ4_COMPRESSION
uncompressed_size = data[0..3].unpack("N")
buf = String.new("", capacity: uncompressed_size)
LZ4::Raw.decompress(data[4..-1], uncompressed_size, dest: buf).first
when ZLIB_COMPRESSION
ActiveSupport::Gzip.decompress(data)
else
data
end
end
|
.determine_loaded_exception_classes ⇒ Object
219
220
221
222
223
224
|
# File 'lib/logjam_agent.rb', line 219
def self.determine_loaded_exception_classes
ObjectSpace.each_object(Class) do |klass|
auto_detect_exception(klass) if klass != Exception && klass.ancestors.include?(Exception)
end
reset_exception_matcher
end
|
.disable! ⇒ Object
90
91
92
|
# File 'lib/logjam_agent.rb', line 90
def self.disable!
self.disabled = true
end
|
.enable! ⇒ Object
94
95
96
|
# File 'lib/logjam_agent.rb', line 94
def self.enable!
self.disabled = false
end
|
.encode_payload(data) ⇒ Object
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
# File 'lib/logjam_agent.rb', line 262
def self.encode_payload(data)
json = json_encode_payload(data)
case compression_method
when SNAPPY_COMPRESSION
Snappy.deflate(json)
when LZ4_COMPRESSION
n = data.byte_size
max_compressed_size = n + n/256 + 16
buf = String.new([n].pack("N"), capacity: max_compressed_size + 4)
LZ4::Raw.compress(json, input_size: n, dest: buf, max_ouput_size: max_compressed_size).first
when ZLIB_COMPRESSION
ActiveSupport::Gzip.compress(json)
else
json
end
end
|
.event(label, extra_fields = {}) ⇒ Object
294
295
296
297
298
299
300
301
302
303
|
# File 'lib/logjam_agent.rb', line 294
def self.event(label, = {})
fields = {
:label => label,
:started_at => Time.now.iso8601,
:host => hostname,
:uuid => generate_uuid
}
fields.merge!()
forwarder.forward(fields, :routing_key => events_routing_key, :sync => true)
end
|
.events_routing_key ⇒ Object
315
316
317
|
# File 'lib/logjam_agent.rb', line 315
def self.events_routing_key
"events.#{application_name}.#{environment_name}"
end
|
.forwarder ⇒ Object
319
320
321
|
# File 'lib/logjam_agent.rb', line 319
def self.forwarder
@forwarder ||= Forwarders.get(application_name, environment_name)
end
|
.get_hostname ⇒ Object
78
79
80
81
82
83
84
85
|
# File 'lib/logjam_agent.rb', line 78
def self.get_hostname
n = Socket.gethostname
if n.split('.').size > 1
n
else
Socket.gethostbyname(n).first rescue n
end
end
|
.ip_obfuscator(ip) ⇒ Object
108
109
110
|
# File 'lib/logjam_agent.rb', line 108
def self.ip_obfuscator(ip)
obfuscate_ips ? ip.to_s.sub(/\d+\z/, 'XXX') : ip
end
|
.log_to_log_device?(severity, msg) ⇒ Boolean
197
198
199
200
201
202
203
204
205
206
|
# File 'lib/logjam_agent.rb', line 197
def self.log_to_log_device?(severity, msg)
return false if severity < log_device_log_level
if override_global_ignore_lines?
msg !~ request.log_device_ignored_lines
else
!(log_device_ignored_lines && msg =~ log_device_ignored_lines)
end
rescue
true
end
|
.max_logged_size_for(key) ⇒ Object
177
178
179
180
181
182
183
|
# File 'lib/logjam_agent.rb', line 177
def self.max_logged_size_for(key)
if key == 'HTTP_COOKIE'.freeze
max_logged_cookie_size
else
max_logged_param_size
end
end
|
.override_global_ignore_lines? ⇒ Boolean
323
324
325
|
# File 'lib/logjam_agent.rb', line 323
def self.override_global_ignore_lines?
request && request.log_device_ignored_lines
end
|
.reset_exception_matcher ⇒ Object
215
216
217
|
# File 'lib/logjam_agent.rb', line 215
def self.reset_exception_matcher
self.exception_matcher = Regexp.new(self.exception_classes.map{|e| Regexp.escape(e)}.join("|"))
end
|