instruments 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/instruments.rb +23 -1
  2. metadata +1 -1
data/lib/instruments.rb CHANGED
@@ -1,4 +1,11 @@
1
1
  module Instruments
2
+
3
+ HTTP_WARN = ENV["HTTP_WARN"] || 300
4
+ HTTP_ERROR = ENV["HTTP_ERROR"] || 1000
5
+
6
+ DB_WARN = ENV["DB_WARN"] || 300
7
+ DB_ERROR = ENV["DB_ERROR"] || 1000
8
+
2
9
  def self.defaults=(args)
3
10
  @logger = args[:logger] || Kernel
4
11
  @method = args[:method] || :puts
@@ -23,7 +30,15 @@ module Instruments
23
30
  end
24
31
  after do
25
32
  t = Integer((Time.now - @start_request)*1000)
33
+ level = if t > HTTP_ERROR
34
+ :error
35
+ elsif t > HTTP_WARN
36
+ :warn
37
+ else
38
+ :info
39
+ end
26
40
  Instruments.write({
41
+ :leve => level,
27
42
  :lib => "sinatra",
28
43
  :action => "http-request",
29
44
  :route => @instrumented_route,
@@ -56,7 +71,14 @@ module Instruments
56
71
  end
57
72
 
58
73
  def log_duration(t, sql)
59
- Instruments.write(:info => true, :action => action(sql), :elapsed => t, :sql => sql)
74
+ level = if t > DB_ERROR
75
+ :error
76
+ elsif t > DB_WARN
77
+ :warn
78
+ else
79
+ :info
80
+ end
81
+ Instruments.write(:level => level, :action => action(sql), :elapsed => t, :sql => sql)
60
82
  end
61
83
 
62
84
  def log_exception(e, sql)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instruments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: