scout_apm 0.1.16 → 0.1.17
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d868630dc6de8b7e4387d2fc6e0e40860df1500d
|
4
|
+
data.tar.gz: 585b6bbb87aeaeec7408cc24750fa3089165e4b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0be21301d0033dbb09c11bfa79a6723c4ac24b900e99afab977152331a46dc7db8739813ae8d27f80b0fd65f04f02c5cd10f53fe4a0de89e8b3bfc7c1a6420e8
|
7
|
+
data.tar.gz: 2e604678abf6cafcfd6a13ce39955212eae6486a69b92290427ad5f703ab4fa8556643388723dbe5f761409a039b49d8507bc730f1effc2af391216d85fb9a76
|
data/CHANGELOG.markdown
CHANGED
@@ -19,6 +19,14 @@ module ScoutApm
|
|
19
19
|
|
20
20
|
# TODO: Fetch the name
|
21
21
|
def application_name
|
22
|
+
possible = ObjectSpace.each_object(Class).select { |klass| klass < Sinatra::Base } - [Sinatra::Application]
|
23
|
+
if possible.length == 1
|
24
|
+
possible.first.name
|
25
|
+
else
|
26
|
+
"Sinatra"
|
27
|
+
end
|
28
|
+
rescue => e
|
29
|
+
logger.debug "Failed getting Sinatra Application Name: #{e.message}\n#{e.backtrace.join("\n\t")}"
|
22
30
|
"Sinatra"
|
23
31
|
end
|
24
32
|
|
@@ -2,7 +2,7 @@ class ScoutApm::SlowTransaction
|
|
2
2
|
BACKTRACE_THRESHOLD = 0.5 # the minimum threshold to record the backtrace for a metric.
|
3
3
|
BACKTRACE_LIMIT = 5 # Max length of callers to display
|
4
4
|
MAX_SIZE = 100 # Limits the size of the metric hash to prevent a metric explosion.
|
5
|
-
attr_reader :metric_name, :total_call_time, :metrics, :meta, :uri, :context, :time
|
5
|
+
attr_reader :metric_name, :total_call_time, :metrics, :meta, :uri, :context, :time, :prof, :raw_prof
|
6
6
|
|
7
7
|
# Given a call stack, generates a filtered backtrace that:
|
8
8
|
# * Limits to the app/models, app/controllers, or app/views directories
|
@@ -16,12 +16,11 @@ module ScoutApm
|
|
16
16
|
attr_accessor :database_engine
|
17
17
|
|
18
18
|
def initialize(sql)
|
19
|
-
@sql = sql.dup
|
19
|
+
@sql = scrubbed(sql.dup)
|
20
20
|
@database_engine = ScoutApm::Environment.instance.database_engine
|
21
21
|
end
|
22
22
|
|
23
23
|
def to_s
|
24
|
-
return nil if sql.length > 1000 # safeguard - don't sanitize large SQL statements
|
25
24
|
case database_engine
|
26
25
|
when :postgres then to_s_postgres
|
27
26
|
when :mysql then to_s_mysql
|
@@ -60,6 +59,25 @@ module ScoutApm
|
|
60
59
|
sql.gsub!(MULTIPLE_SPACES, ' ')
|
61
60
|
sql.gsub!(TRAILING_SPACES, '')
|
62
61
|
end
|
62
|
+
|
63
|
+
def has_encodings?(encodings=['UTF-8', 'binary'])
|
64
|
+
encodings.all?{|enc| Encoding.find(enc) rescue false}
|
65
|
+
end
|
66
|
+
|
67
|
+
def scrubbed(str)
|
68
|
+
return '' if !str.is_a?(String) || str.length > 1000 # safeguard - don't sanitize or scrub large SQL statements
|
69
|
+
return str if !str.respond_to?(:encode) # Ruby <= 1.8 doesn't have string encoding
|
70
|
+
return str if str.valid_encoding? # Whatever encoding it is, it is valid and we can operate on it
|
71
|
+
ScoutApm::Agent.instance.logger.debug "Scrubbing invalid sql encoding."
|
72
|
+
if str.respond_to?(:scrub) # Prefer to scrub before we have to convert
|
73
|
+
return str.scrub('_')
|
74
|
+
elsif has_encodings?(['UTF-8', 'binary'])
|
75
|
+
return str.encode('UTF-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '_')
|
76
|
+
end
|
77
|
+
ScoutApm::Agent.instance.logger.debug "Unable to scrub invalid sql encoding."
|
78
|
+
''
|
79
|
+
end
|
80
|
+
|
63
81
|
end
|
64
82
|
end
|
65
83
|
end
|
data/lib/scout_apm/version.rb
CHANGED
@@ -8,7 +8,7 @@ module ScoutApm
|
|
8
8
|
# Too long, and we just bail out to prevent long running instrumentation
|
9
9
|
def test_long_sql
|
10
10
|
sql = " " * 1001
|
11
|
-
|
11
|
+
assert_equal '', SqlSanitizer.new(sql).to_s
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_postgres_simple_select_of_first
|
@@ -62,6 +62,16 @@ module ScoutApm
|
|
62
62
|
ss = SqlSanitizer.new(sql).tap{ |it| it.database_engine = :mysql }
|
63
63
|
assert_equal %q|SELECT `blogs`.* FROM `blogs` WHERE (title = ?)|, ss.to_s
|
64
64
|
end
|
65
|
+
|
66
|
+
def test_scrubs_invalid_encoding
|
67
|
+
sql = "SELECT `blogs`.* FROM `blogs` WHERE (title = 'a\255c')".force_encoding('UTF-8')
|
68
|
+
assert_equal false, sql.valid_encoding?
|
69
|
+
ss = SqlSanitizer.new(sql).tap{ |it| it.database_engine = :mysql }
|
70
|
+
assert_equal %q|SELECT `blogs`.* FROM `blogs` WHERE (title = 'a_c')|, ss.sql
|
71
|
+
assert_nothing_raised do
|
72
|
+
assert_equal %q|SELECT `blogs`.* FROM `blogs` WHERE (title = ?)|, ss.to_s
|
73
|
+
end
|
74
|
+
end
|
65
75
|
end
|
66
76
|
end
|
67
77
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scout_apm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek Haynes
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-09-
|
12
|
+
date: 2015-09-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -146,10 +146,4 @@ rubygems_version: 2.2.2
|
|
146
146
|
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: Ruby application performance monitoring
|
149
|
-
test_files:
|
150
|
-
- test/data/config_test_1.yml
|
151
|
-
- test/test_helper.rb
|
152
|
-
- test/unit/config_test.rb
|
153
|
-
- test/unit/environment_test.rb
|
154
|
-
- test/unit/instruments/active_record_instruments_test.rb
|
155
|
-
- test/unit/sql_sanitizer_test.rb
|
149
|
+
test_files: []
|