pliny 0.17.1 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pliny.rb +2 -1
- data/lib/pliny/error_reporters.rb +19 -0
- data/lib/pliny/error_reporters/rollbar.rb +30 -0
- data/lib/pliny/metrics.rb +29 -0
- data/lib/pliny/middleware/rescue_errors.rb +1 -1
- data/lib/pliny/version.rb +1 -1
- data/lib/template/Gemfile +2 -2
- data/lib/template/config/initializers/rollbar.rb +4 -0
- data/spec/{error_reporter_spec.rb → error_reporters_spec.rb} +13 -6
- data/spec/metrics_spec.rb +56 -0
- data/spec/middleware/rescue_errors_spec.rb +1 -1
- data/spec/router_spec.rb +0 -1
- metadata +7 -4
- data/lib/pliny/error_reporter.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50ee2327594f7a24b91de1931315b9d56857a6db
|
4
|
+
data.tar.gz: 19764f159ec7799e68d4d704ff679b2101eddf43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c20a3261666622c51f92614f2c4c49bd3d169b34fed20f8359ba6647a45ed4fc5bdbde260127ea9f4d6dae66a909a80bf2cc756d28845900afed16449bc5838
|
7
|
+
data.tar.gz: d29a0d1bf16fd8cc623b7ee302113cf61b131bab0d171fc41e96cef1703d6bc4c3b097b352b3b4c4b6ddb6f0a3ea88ba2fcb8fb5c4946da23f0d4e4fd4db3a4c
|
data/lib/pliny.rb
CHANGED
@@ -2,12 +2,13 @@ require "multi_json"
|
|
2
2
|
require "sinatra/base"
|
3
3
|
|
4
4
|
require_relative "pliny/version"
|
5
|
-
require_relative "pliny/
|
5
|
+
require_relative "pliny/error_reporters"
|
6
6
|
require_relative "pliny/errors"
|
7
7
|
require_relative "pliny/helpers/encode"
|
8
8
|
require_relative "pliny/helpers/params"
|
9
9
|
require_relative "pliny/helpers/serialize"
|
10
10
|
require_relative "pliny/log"
|
11
|
+
require_relative "pliny/metrics"
|
11
12
|
require_relative "pliny/request_store"
|
12
13
|
require_relative "pliny/rollbar_logger"
|
13
14
|
require_relative "pliny/router"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Pliny::ErrorReporters
|
2
|
+
extend self
|
3
|
+
|
4
|
+
@error_reporters = []
|
5
|
+
|
6
|
+
attr_accessor :error_reporters
|
7
|
+
|
8
|
+
def notify(exception, context: {}, rack_env: {})
|
9
|
+
Pliny.log_exception(exception)
|
10
|
+
|
11
|
+
error_reporters.each do |reporter|
|
12
|
+
begin
|
13
|
+
reporter.new.notify(exception, context: context, rack_env: rack_env)
|
14
|
+
rescue
|
15
|
+
Pliny.log_exception($!)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rollbar/exception_reporter'
|
2
|
+
require 'rollbar/request_data_extractor'
|
3
|
+
|
4
|
+
module Pliny
|
5
|
+
module ErrorReporters
|
6
|
+
class Rollbar
|
7
|
+
include ::Rollbar::ExceptionReporter
|
8
|
+
include ::Rollbar::RequestDataExtractor
|
9
|
+
|
10
|
+
def notify(exception, context:, rack_env:)
|
11
|
+
::Rollbar.reset_notifier!
|
12
|
+
scope = fetch_scope(context: context, rack_env: rack_env)
|
13
|
+
::Rollbar.scoped(scope) do
|
14
|
+
report_exception_to_rollbar(rack_env, exception)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def fetch_scope(context:, rack_env:)
|
21
|
+
{
|
22
|
+
request: proc { extract_request_data_from_rack(rack_env) }
|
23
|
+
}
|
24
|
+
rescue Exception => e
|
25
|
+
report_exception_to_rollbar(rack_env, e)
|
26
|
+
raise
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Pliny
|
2
|
+
module Metrics
|
3
|
+
def self.count(*names, value: 1)
|
4
|
+
counts = Hash[names.map { |n| [metric_prefix(:count, n), value] }]
|
5
|
+
Pliny.log(counts)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.measure(*names, &block)
|
9
|
+
elapsed, return_value = time_elapsed(&block)
|
10
|
+
measures = Hash[names.map { |n| [metric_prefix(:measure, n), elapsed] }]
|
11
|
+
Pliny.log(measures)
|
12
|
+
|
13
|
+
return_value
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def self.metric_prefix(type, name)
|
19
|
+
"#{type.to_s}##{Config.app_name}.#{name}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.time_elapsed(&block)
|
23
|
+
start = Time.now
|
24
|
+
return_value = block.call
|
25
|
+
[Time.now - start, return_value]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
data/lib/pliny/version.rb
CHANGED
data/lib/template/Gemfile
CHANGED
@@ -4,13 +4,13 @@ ruby "2.3.1"
|
|
4
4
|
gem "multi_json"
|
5
5
|
gem "oj"
|
6
6
|
gem "pg"
|
7
|
-
gem "pliny", "~> 0.
|
7
|
+
gem "pliny", "~> 0.18"
|
8
8
|
gem "pry"
|
9
9
|
gem "puma", "~> 2.16"
|
10
10
|
gem "rack-ssl"
|
11
11
|
gem "rack-timeout", "~> 0.4"
|
12
12
|
gem "rake"
|
13
|
-
gem "rollbar"
|
13
|
+
gem "rollbar"
|
14
14
|
gem "sequel", "~> 4.34"
|
15
15
|
gem "sequel-paranoid"
|
16
16
|
gem "sequel_pg", "~> 1.6", require: "sequel"
|
@@ -1,9 +1,10 @@
|
|
1
|
-
|
2
1
|
require "spec_helper"
|
3
2
|
|
4
|
-
describe Pliny::
|
3
|
+
describe Pliny::ErrorReporters do
|
5
4
|
subject(:reporter) { described_class }
|
6
5
|
|
6
|
+
let(:reporter_double) { double("reporter").as_null_object }
|
7
|
+
|
7
8
|
describe ".notify" do
|
8
9
|
let(:exception) { RuntimeError.new }
|
9
10
|
let(:context) { { context: "foo" } }
|
@@ -13,12 +14,18 @@ describe Pliny::ErrorReporter do
|
|
13
14
|
reporter.notify(exception, context: context, rack_env: rack_env)
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
to receive(:notify).
|
19
|
-
with(exception, context: context, rack_env: rack_env)
|
17
|
+
before do
|
18
|
+
Pliny::ErrorReporters.error_reporters << reporter_double
|
20
19
|
|
20
|
+
allow(reporter_double).to receive(:notify)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "notifies rollbar" do
|
21
24
|
notify_reporter
|
25
|
+
|
26
|
+
expect(reporter_double).to have_received(:notify)
|
27
|
+
.once
|
28
|
+
.with(exception, context: context, rack_env: rack_env)
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Pliny::Metrics do
|
4
|
+
let(:io) { double }
|
5
|
+
|
6
|
+
subject(:metrics) { Pliny::Metrics }
|
7
|
+
|
8
|
+
before do
|
9
|
+
Pliny.stdout = io
|
10
|
+
|
11
|
+
allow(io).to receive(:print)
|
12
|
+
allow(Config).to receive(:app_name).and_return('pliny')
|
13
|
+
end
|
14
|
+
|
15
|
+
context "#count" do
|
16
|
+
it "counts a single key with a default value" do
|
17
|
+
metrics.count(:foo)
|
18
|
+
expect(io).to have_received(:print).with("count#pliny.foo=1\n")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "counts a single key with a provided value" do
|
22
|
+
metrics.count(:foo, value: 2)
|
23
|
+
expect(io).to have_received(:print).with("count#pliny.foo=2\n")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "counts multiple keys" do
|
27
|
+
metrics.count(:foo, :bar)
|
28
|
+
expect(io).to have_received(:print).with(
|
29
|
+
"count#pliny.foo=1 count#pliny.bar=1\n")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "#measure" do
|
34
|
+
before do
|
35
|
+
Timecop.freeze(Time.now)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "measures a single key" do
|
39
|
+
metrics.measure(:foo) { }
|
40
|
+
expect(io).to have_received(:print).with("measure#pliny.foo=0.000\n")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "measures a single key over a minute" do
|
44
|
+
metrics.measure(:foo) do
|
45
|
+
Timecop.travel(60)
|
46
|
+
end
|
47
|
+
expect(io).to have_received(:print).with("measure#pliny.foo=60.000\n")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "measures multiple keys" do
|
51
|
+
metrics.measure(:foo, :bar) { }
|
52
|
+
expect(io).to have_received(:print).with(
|
53
|
+
"measure#pliny.foo=0.000 measure#pliny.bar=0.000\n")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -28,7 +28,7 @@ describe Pliny::Middleware::RescueErrors do
|
|
28
28
|
|
29
29
|
it "intercepts exceptions and renders" do
|
30
30
|
@app = new_rack_app
|
31
|
-
expect(Pliny::
|
31
|
+
expect(Pliny::ErrorReporters).to receive(:notify)
|
32
32
|
get "/"
|
33
33
|
assert_equal 500, last_response.status
|
34
34
|
error_json = MultiJson.decode(last_response.body)
|
data/spec/router_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pliny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur Leach
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -354,12 +354,14 @@ files:
|
|
354
354
|
- lib/pliny/commands/updater.rb
|
355
355
|
- lib/pliny/config_helpers.rb
|
356
356
|
- lib/pliny/db_support.rb
|
357
|
-
- lib/pliny/
|
357
|
+
- lib/pliny/error_reporters.rb
|
358
|
+
- lib/pliny/error_reporters/rollbar.rb
|
358
359
|
- lib/pliny/errors.rb
|
359
360
|
- lib/pliny/helpers/encode.rb
|
360
361
|
- lib/pliny/helpers/params.rb
|
361
362
|
- lib/pliny/helpers/serialize.rb
|
362
363
|
- lib/pliny/log.rb
|
364
|
+
- lib/pliny/metrics.rb
|
363
365
|
- lib/pliny/middleware/cors.rb
|
364
366
|
- lib/pliny/middleware/instruments.rb
|
365
367
|
- lib/pliny/middleware/request_id.rb
|
@@ -439,12 +441,13 @@ files:
|
|
439
441
|
- spec/commands/updater_spec.rb
|
440
442
|
- spec/config_helpers_spec.rb
|
441
443
|
- spec/db_support_spec.rb
|
442
|
-
- spec/
|
444
|
+
- spec/error_reporters_spec.rb
|
443
445
|
- spec/errors_spec.rb
|
444
446
|
- spec/helpers/encode_spec.rb
|
445
447
|
- spec/helpers/serialize_spec.rb
|
446
448
|
- spec/integration_spec.rb
|
447
449
|
- spec/log_spec.rb
|
450
|
+
- spec/metrics_spec.rb
|
448
451
|
- spec/middleware/cors_spec.rb
|
449
452
|
- spec/middleware/instruments_spec.rb
|
450
453
|
- spec/middleware/request_id_spec.rb
|
data/lib/pliny/error_reporter.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'rollbar/exception_reporter'
|
2
|
-
require 'rollbar/request_data_extractor'
|
3
|
-
|
4
|
-
class Pliny::ErrorReporter
|
5
|
-
def self.notify(exception, context: {}, rack_env: {})
|
6
|
-
Pliny.log_exception(exception)
|
7
|
-
|
8
|
-
REPORTERS.each do |reporter|
|
9
|
-
begin
|
10
|
-
reporter.new.notify(exception, context: context, rack_env: rack_env)
|
11
|
-
rescue
|
12
|
-
Pliny.log_exception($!)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class RollbarReporter
|
18
|
-
include ::Rollbar::ExceptionReporter
|
19
|
-
include ::Rollbar::RequestDataExtractor
|
20
|
-
|
21
|
-
def notify(exception, context:, rack_env:)
|
22
|
-
Rollbar.reset_notifier!
|
23
|
-
scope = fetch_scope(context: context, rack_env: rack_env)
|
24
|
-
Rollbar.scoped(scope) do
|
25
|
-
report_exception_to_rollbar(rack_env, exception)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def fetch_scope(context:, rack_env:)
|
32
|
-
{
|
33
|
-
request: proc { extract_request_data_from_rack(rack_env) }
|
34
|
-
}
|
35
|
-
rescue Exception => e
|
36
|
-
report_exception_to_rollbar(rack_env, e)
|
37
|
-
raise
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
REPORTERS = [RollbarReporter]
|
42
|
-
end
|