logtail 0.1.22 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/logtail/log_devices/http.rb +3 -2
- data/lib/logtail/logger.rb +5 -0
- data/lib/logtail/version.rb +1 -1
- data/spec/logtail/logger_spec.rb +79 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3d5ab231af5dc942cabbb907be7db40167b6fc170e114c86cc537eb5b0655131
|
|
4
|
+
data.tar.gz: 036d73c755c4f2b790fb021fda88c8ab80e29671a11650385abdc78fb28324ef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 84c6722d3dd83456274005c933ecde9fbcfea6111cf2dcfa6b28434a32acde03e3fe709061222cd6f3cb8ccaed1d7eb20d75978b6078ce33b005ad84d874823a
|
|
7
|
+
data.tar.gz: 3e5ae00d1d0a20d325849f9f0b712ccb16ea43d05537a0907ecba624d6ae2b6b76357c804769ad744e65fa73c90986d5d5ee53fdfa14d78cedb1eb43d9988a56
|
|
@@ -702,8 +702,9 @@ Logtail::Config.instance.debug_logger = ::Logger.new(STDOUT)
|
|
|
702
702
|
# seconds or as an HTTP date, at most {MAX_RETRY_AFTER}. 0 without a valid header.
|
|
703
703
|
def retry_after(resp)
|
|
704
704
|
value = resp["Retry-After"].to_s.strip
|
|
705
|
-
|
|
706
|
-
seconds.
|
|
705
|
+
# =~, min and max, not match? and clamp: Ruby 2.3, which the gemspec allows, has neither
|
|
706
|
+
seconds = value =~ /\A\d+\z/ ? value.to_i : (Time.httpdate(value) - Time.now).ceil
|
|
707
|
+
[[seconds, MAX_RETRY_AFTER].min, 0].max
|
|
707
708
|
rescue ArgumentError
|
|
708
709
|
0
|
|
709
710
|
end
|
data/lib/logtail/logger.rb
CHANGED
|
@@ -41,6 +41,11 @@ module Logtail
|
|
|
41
41
|
level = SEVERITY_MAP.fetch(severity, :unknown)
|
|
42
42
|
tags = extract_active_support_tagged_logging_tags.clone
|
|
43
43
|
|
|
44
|
+
if logged_obj.is_a?(::Exception)
|
|
45
|
+
logged_obj = Events::Error.new(name: logged_obj.class.name, error_message: logged_obj.message,
|
|
46
|
+
backtrace: logged_obj.backtrace)
|
|
47
|
+
end
|
|
48
|
+
|
|
44
49
|
if logged_obj.is_a?(Event)
|
|
45
50
|
LogEntry.new(level, time, progname, logged_obj.message, context_snapshot, logged_obj,
|
|
46
51
|
tags: tags)
|
data/lib/logtail/version.rb
CHANGED
data/spec/logtail/logger_spec.rb
CHANGED
|
@@ -237,6 +237,85 @@ describe Logtail::Logger do
|
|
|
237
237
|
expect(io.string).to include('"level":"error"')
|
|
238
238
|
expect(io.string).to include('"tags":["tag"]')
|
|
239
239
|
end
|
|
240
|
+
|
|
241
|
+
context "with an exception" do
|
|
242
|
+
let(:exception) do
|
|
243
|
+
RuntimeError.new("boom").tap do |e|
|
|
244
|
+
e.set_backtrace(["app/models/order.rb:12:in 'Order#charge'", "app/jobs/charge_job.rb:5:in 'ChargeJob#perform'"])
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
it "should log a rescued exception as an error event with its backtrace" do
|
|
249
|
+
begin
|
|
250
|
+
raise "boom"
|
|
251
|
+
rescue => e
|
|
252
|
+
logger.error(e)
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
line = JSON.parse(io.string)
|
|
256
|
+
expect(line["level"]).to eq("error")
|
|
257
|
+
expect(line["message"]).to eq("RuntimeError (boom)")
|
|
258
|
+
expect(line["error"]).to include("name" => "RuntimeError", "message" => "boom")
|
|
259
|
+
expect(line["error"]["backtrace_json"]).to include("/spec/logtail/logger_spec.rb:")
|
|
260
|
+
expect(JSON.parse(line["error"]["backtrace_json"])).to eq(e.backtrace)
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
it "should log an exception that was never raised without a backtrace" do
|
|
264
|
+
logger.error(RuntimeError.new("never raised"))
|
|
265
|
+
|
|
266
|
+
line = JSON.parse(io.string)
|
|
267
|
+
expect(line["message"]).to eq("RuntimeError (never raised)")
|
|
268
|
+
expect(line["error"]).to eq("name" => "RuntimeError", "message" => "never raised", "backtrace_json" => nil)
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
it "should log an exception returned by a block the same way" do
|
|
272
|
+
logger.error { exception }
|
|
273
|
+
|
|
274
|
+
line = JSON.parse(io.string)
|
|
275
|
+
expect(line["message"]).to eq("RuntimeError (boom)")
|
|
276
|
+
expect(line["error"]).to eq(
|
|
277
|
+
"name" => "RuntimeError",
|
|
278
|
+
"message" => "boom",
|
|
279
|
+
"backtrace_json" => %q(["app/models/order.rb:12:in 'Order#charge'","app/jobs/charge_job.rb:5:in 'ChargeJob#perform'"])
|
|
280
|
+
)
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
it "should log the error event as metadata with the AugmentedFormatter" do
|
|
284
|
+
logger.formatter = Logtail::Logger::AugmentedFormatter.new
|
|
285
|
+
logger.error(exception)
|
|
286
|
+
|
|
287
|
+
expect(io.string).to start_with(%q(RuntimeError (boom) @metadata {"level":"error",))
|
|
288
|
+
expect(io.string).to include(%q("error":{"name":"RuntimeError","message":"boom","backtrace_json":"[\"app/models/order.rb:12:in 'Order#charge'\",\"app/jobs/charge_job.rb:5:in 'ChargeJob#perform'\"]"}))
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
it "should log the class and message with the MessageOnlyFormatter" do
|
|
292
|
+
logger.formatter = Logtail::Logger::MessageOnlyFormatter.new
|
|
293
|
+
logger.error(exception)
|
|
294
|
+
|
|
295
|
+
expect(io.string).to eq("RuntimeError (boom)\n")
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
it "should deliver the error event with the HTTP log device" do
|
|
299
|
+
http_device = Logtail::LogDevices::HTTP.new("MYKEY", flush_continuously: false)
|
|
300
|
+
logger = Logtail::Logger.new(http_device)
|
|
301
|
+
|
|
302
|
+
logger.error(exception)
|
|
303
|
+
|
|
304
|
+
http_device.send(:flush_async)
|
|
305
|
+
request = http_device.instance_variable_get(:@request_queue).deq.request
|
|
306
|
+
entries = MessagePack.unpack(Zlib::Inflate.inflate(request.body))
|
|
307
|
+
expect(entries.size).to eq(1)
|
|
308
|
+
expect(entries[0]).to include(
|
|
309
|
+
"level" => "error",
|
|
310
|
+
"message" => "RuntimeError (boom)",
|
|
311
|
+
"error" => {
|
|
312
|
+
"name" => "RuntimeError",
|
|
313
|
+
"message" => "boom",
|
|
314
|
+
"backtrace_json" => %q(["app/models/order.rb:12:in 'Order#charge'","app/jobs/charge_job.rb:5:in 'ChargeJob#perform'"])
|
|
315
|
+
}
|
|
316
|
+
)
|
|
317
|
+
end
|
|
318
|
+
end
|
|
240
319
|
end
|
|
241
320
|
|
|
242
321
|
describe "#unknown" do
|