framed_rails 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rubocop.yml +61 -0
- data/Gemfile +1 -1
- data/README.md +29 -26
- data/circle.yml +3 -0
- data/framed_rails.gemspec +12 -14
- data/lib/framed/client.rb +2 -1
- data/lib/framed/emitters.rb +13 -12
- data/lib/framed/rails.rb +2 -2
- data/lib/framed/utils.rb +3 -3
- data/lib/framed/version.rb +1 -1
- data/lib/framed_rails.rb +9 -9
- metadata +21 -3
data/.rubocop.yml
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'lib/framed/okjson.rb'
|
4
|
+
- 'vendor/**/*'
|
5
|
+
|
6
|
+
Documentation:
|
7
|
+
Enabled: False
|
8
|
+
|
9
|
+
Lint/HandleExceptions:
|
10
|
+
Enabled: False
|
11
|
+
|
12
|
+
Metrics/AbcSize:
|
13
|
+
Enabled: False
|
14
|
+
|
15
|
+
Metrics/LineLength:
|
16
|
+
Enabled: False
|
17
|
+
|
18
|
+
Metrics/MethodLength:
|
19
|
+
Enabled: False
|
20
|
+
|
21
|
+
Style/BracesAroundHashParameters:
|
22
|
+
Enabled: False
|
23
|
+
|
24
|
+
Style/EachWithObject:
|
25
|
+
Enabled: False
|
26
|
+
|
27
|
+
Style/EmptyLinesAroundBlockBody:
|
28
|
+
Enabled: False
|
29
|
+
|
30
|
+
Style/GuardClause:
|
31
|
+
Enabled: False
|
32
|
+
|
33
|
+
Style/HashSyntax:
|
34
|
+
Enabled: False
|
35
|
+
|
36
|
+
Style/IfUnlessModifier:
|
37
|
+
Enabled: False
|
38
|
+
|
39
|
+
Style/IndentHash:
|
40
|
+
Enabled: False
|
41
|
+
|
42
|
+
Style/ModuleFunction:
|
43
|
+
Enabled: False
|
44
|
+
|
45
|
+
Style/RaiseArgs:
|
46
|
+
Enabled: False
|
47
|
+
|
48
|
+
Style/RedundantBegin:
|
49
|
+
Enabled: False
|
50
|
+
|
51
|
+
Style/RedundantSelf:
|
52
|
+
Enabled: False
|
53
|
+
|
54
|
+
Style/SignalException:
|
55
|
+
Enabled: False
|
56
|
+
|
57
|
+
Style/SpaceInsideHashLiteralBraces:
|
58
|
+
Enabled: False
|
59
|
+
|
60
|
+
Style/WhileUntilModifier:
|
61
|
+
Enabled: False
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
------------
|
3
3
|
|
4
4
|
`framed_rails` is a gem to add Framed instrumentation to your Rails 4
|
5
|
-
app. For each request, it sends an event to Framed.
|
5
|
+
app. For each request that occurs in your app, it sends an event to Framed for analysis.
|
6
6
|
|
7
7
|
To use this in your Rails project:
|
8
8
|
|
9
|
-
* Add `gem 'framed_rails', '~> 0.1.
|
9
|
+
* Add `gem 'framed_rails', '~> 0.1.7'` to your Gemfile.
|
10
10
|
* Add the following to `config/initializers/framed_rails.rb`:
|
11
11
|
|
12
12
|
```ruby
|
@@ -17,7 +17,8 @@ Framed.configure do |config|
|
|
17
17
|
end
|
18
18
|
```
|
19
19
|
|
20
|
-
If reporting fails,
|
20
|
+
If request reporting fails, an exception will be logged to `Rails.logger` by default.
|
21
|
+
The logger used can be customized in config.
|
21
22
|
|
22
23
|
Configuration
|
23
24
|
-------------
|
@@ -30,47 +31,40 @@ Configuration
|
|
30
31
|
</tr>
|
31
32
|
|
32
33
|
<tr>
|
33
|
-
<td>:
|
34
|
-
<td>The emitter to be used for reporting.
|
34
|
+
<td><code>:emitter</code></td>
|
35
|
+
<td>The emitter to be used for reporting. See the Emitters
|
35
36
|
section below.</td>
|
36
|
-
<td
|
37
|
+
<td><code>Framed::Emitters::Blocking</code></td>
|
37
38
|
</tr>
|
38
39
|
|
39
40
|
<tr>
|
40
|
-
<td>:user_id_controller_method</td>
|
41
|
-
<td>The name of a controller method which returns the user
|
41
|
+
<td><code>:user_id_controller_method</code></td>
|
42
|
+
<td>The name of a controller method which returns id of the current user, if
|
42
43
|
any</td>
|
43
|
-
<td
|
44
|
+
<td><code>'framed_current_user_id'</code> (tries <code>current_user.id</code>)</td>
|
44
45
|
</tr>
|
45
46
|
|
46
47
|
<tr>
|
47
|
-
<td>:logger</td>
|
48
|
+
<td><code>:logger</code></td>
|
48
49
|
<td>A Logger for reporting errors.</td>
|
49
|
-
<td
|
50
|
+
<td><code>Rails.logger</code></td>
|
50
51
|
</tr>
|
51
52
|
|
52
53
|
<tr>
|
53
|
-
<td>:anonymous_cookie</td>
|
54
|
-
<td>The name of the
|
55
|
-
Long-lived anonymous user IDs are issued anonymous
|
56
|
-
<td
|
57
|
-
</tr>
|
58
|
-
|
59
|
-
<tr>
|
60
|
-
<td>:user_id_controller_method</td>
|
61
|
-
<td>The name of a controller method which can provide the current
|
62
|
-
User ID. (Also works with Devise).</td>
|
63
|
-
<td>'framed_current_user_id'</td>
|
54
|
+
<td><code>:anonymous_cookie</code></td>
|
55
|
+
<td>The name of the signed cookie for anonymous user IDs.
|
56
|
+
Long-lived anonymous user IDs are issued anonymous IDs by default.</td>
|
57
|
+
<td><code>Framed::COOKIE_NAME</code></td>
|
64
58
|
</tr>
|
65
59
|
|
66
60
|
<tr>
|
67
|
-
<td>:include_xhr</td>
|
61
|
+
<td><code>:include_xhr</code></td>
|
68
62
|
<td>Whether to include requests sent via AJAX. (Turbolinks are always included.)</td>
|
69
63
|
<td>false</td>
|
70
64
|
</tr>
|
71
65
|
|
72
66
|
<tr>
|
73
|
-
<td>:excluded_params</td>
|
67
|
+
<td><code>:excluded_params</code></td>
|
74
68
|
<td>An array of request parameter keys to never send to Framed. <code>:controller</code>, <code>:action</code>,
|
75
69
|
<code>:utf8</code>, <code>:authenticity_token</code>, <code>:commit</code>, and <code>:password</code> are never
|
76
70
|
sent, and anything added here is in addition to default values.
|
@@ -80,6 +74,15 @@ Configuration
|
|
80
74
|
|
81
75
|
</table>
|
82
76
|
|
77
|
+
|
78
|
+
user_id_controller_method
|
79
|
+
--------
|
80
|
+
This function is used to get the ID of the current user (if any) for properly attributing
|
81
|
+
events to the users who performed them. The default implementation effectively tries to read
|
82
|
+
`current_user.id`, but will not fail if `current_user` is not defined. You can change this
|
83
|
+
to a to a controller function of your choosing by specifying its name as a string (invoked via `send`).
|
84
|
+
|
85
|
+
|
83
86
|
Emitters
|
84
87
|
--------
|
85
88
|
|
@@ -89,7 +92,7 @@ your configure block:
|
|
89
92
|
|
90
93
|
|
91
94
|
```ruby
|
92
|
-
config[:
|
95
|
+
config[:emitter] = Framed::Emitters::Buffered
|
93
96
|
```
|
94
97
|
|
95
98
|
Emitters included in this gem:
|
@@ -97,7 +100,7 @@ Emitters included in this gem:
|
|
97
100
|
* `Framed::Emitters::Blocking` - Logs each request to Framed using a single blocking request (default)
|
98
101
|
* `Framed::Emitters::Buffered` - Logs to Framed 1) if no request is in progress, immediately 2) otherwise in batches of up to 100 as soon as the previous request completes. All requests are sent on a background thread.
|
99
102
|
* `Framed::Emitters::InMemory` - stores reported events in memory,
|
100
|
-
rather than transmitting them. Events are later available as `Framed.
|
103
|
+
rather than transmitting them. Events are later available as `Framed.emitter.reported`.
|
101
104
|
* `Framed::Emitters::Logger` - Logs an info message to `config[:logger]`.
|
102
105
|
|
103
106
|
Both `InMemory` and `Logger` should be considered for debugging/diagnostic purposes only.
|
data/circle.yml
ADDED
data/framed_rails.gemspec
CHANGED
@@ -5,33 +5,31 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
require 'framed/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
|
-
s.name =
|
8
|
+
s.name = 'framed_rails'
|
9
9
|
s.version = Framed::VERSION
|
10
10
|
s.required_ruby_version = '>= 1.8.7'
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new(
|
12
|
-
s.authors = [
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new('> 1.3.1') if s.respond_to? :required_rubygems_version=
|
12
|
+
s.authors = ['Jeremy Dunck']
|
13
13
|
s.date = Time.now.strftime('%Y-%m-%d')
|
14
14
|
s.licenses = ['MIT']
|
15
15
|
s.description = <<-EOS
|
16
16
|
TK
|
17
17
|
EOS
|
18
|
-
s.email =
|
19
|
-
s.executables = [
|
18
|
+
s.email = 'support@framed.io'
|
19
|
+
s.executables = []
|
20
20
|
s.extra_rdoc_files = [
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
'CHANGELOG',
|
22
|
+
'LICENSE',
|
23
|
+
'README.md'
|
24
24
|
]
|
25
25
|
|
26
26
|
file_list = `git ls-files`.split
|
27
27
|
s.files = file_list
|
28
28
|
|
29
|
-
s.homepage =
|
30
|
-
s.require_paths = [
|
29
|
+
s.homepage = 'http://www.github.com/framed-data/framed_rails'
|
30
|
+
s.require_paths = ['lib', 'vendor/gems/excon-0.45.3/lib']
|
31
31
|
s.rubygems_version = Gem::VERSION
|
32
|
-
s.summary =
|
32
|
+
s.summary = 'Framed.io data collector'
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
# FIXME: RUBY_VERSION, RUBY_PLATFORM, RUBY_ENGINE
|
34
|
+
s.add_development_dependency 'rubocop', '~> 0.35.1'
|
37
35
|
end
|
data/lib/framed/client.rb
CHANGED
@@ -20,7 +20,8 @@ module Framed
|
|
20
20
|
|
21
21
|
creds = Base64.strict_encode64(@config[:api_key] + ':')
|
22
22
|
payload = JSON.generate(data)
|
23
|
-
response = Excon.post(
|
23
|
+
response = Excon.post(
|
24
|
+
@config[:endpoint],
|
24
25
|
:headers => {
|
25
26
|
'Authorization' => "Basic #{creds}",
|
26
27
|
'Content-Type' => 'application/json'
|
data/lib/framed/emitters.rb
CHANGED
@@ -8,14 +8,13 @@ module Framed
|
|
8
8
|
@client = client
|
9
9
|
end
|
10
10
|
|
11
|
-
def stop(
|
12
|
-
|
11
|
+
def stop(_drain = false)
|
13
12
|
end
|
14
|
-
def start
|
15
13
|
|
14
|
+
def start
|
16
15
|
end
|
17
16
|
|
18
|
-
def enqueue(
|
17
|
+
def enqueue(_event)
|
19
18
|
raise NotImplementedError
|
20
19
|
end
|
21
20
|
|
@@ -26,7 +25,7 @@ module Framed
|
|
26
25
|
|
27
26
|
begin
|
28
27
|
@client.track(events)
|
29
|
-
rescue
|
28
|
+
rescue StandardError => exc
|
30
29
|
Framed.log_error("#transmit failed: #{exc}")
|
31
30
|
end
|
32
31
|
end
|
@@ -54,8 +53,10 @@ module Framed
|
|
54
53
|
class Blocking < Base
|
55
54
|
def start
|
56
55
|
end
|
57
|
-
|
56
|
+
|
57
|
+
def stop(_drain = false)
|
58
58
|
end
|
59
|
+
|
59
60
|
def enqueue(event)
|
60
61
|
transmit([event])
|
61
62
|
end
|
@@ -77,12 +78,12 @@ module Framed
|
|
77
78
|
end
|
78
79
|
|
79
80
|
def start
|
80
|
-
if @request_thread
|
81
|
-
Framed.log_info(
|
81
|
+
if @request_thread && !@request_thread.alive?
|
82
|
+
Framed.log_info('Starting request thread due to dead thread')
|
82
83
|
end
|
83
84
|
|
84
85
|
@request_thread = Thread.new do
|
85
|
-
|
86
|
+
loop do
|
86
87
|
pending = @request_queue.pop
|
87
88
|
|
88
89
|
@request_pending.synchronize do
|
@@ -126,7 +127,7 @@ module Framed
|
|
126
127
|
# we remember if the queue is full and log outside the lock.
|
127
128
|
queue_full = @event_queue.length >= MAX_QUEUE_SIZE
|
128
129
|
|
129
|
-
|
130
|
+
unless queue_full
|
130
131
|
@event_queue << event
|
131
132
|
end
|
132
133
|
|
@@ -166,7 +167,7 @@ module Framed
|
|
166
167
|
|
167
168
|
pending = []
|
168
169
|
while pending.length < MAX_REQUEST_BATCH_SIZE && @event_queue.length > 0
|
169
|
-
|
170
|
+
pending << @event_queue.pop
|
170
171
|
end
|
171
172
|
|
172
173
|
@request_queue << pending
|
@@ -178,7 +179,7 @@ module Framed
|
|
178
179
|
|
179
180
|
begin
|
180
181
|
@client.track(events)
|
181
|
-
rescue
|
182
|
+
rescue StandardError => exc
|
182
183
|
Framed.log_error("#transmit failed: #{exc}")
|
183
184
|
end
|
184
185
|
end
|
data/lib/framed/rails.rb
CHANGED
@@ -24,7 +24,7 @@ ActionController::Base.class_eval do
|
|
24
24
|
cookies.signed.permanent[Framed.anonymous_cookie] = cookie
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
anonymous_id
|
28
28
|
end
|
29
29
|
|
30
30
|
def framed_current_user_id
|
@@ -60,7 +60,7 @@ ActionController::Base.class_eval do
|
|
60
60
|
}
|
61
61
|
|
62
62
|
Framed.report(event)
|
63
|
-
rescue
|
63
|
+
rescue StandardError => exc
|
64
64
|
Framed.log_error("Failed to report request #{exc}")
|
65
65
|
end
|
66
66
|
end
|
data/lib/framed/utils.rb
CHANGED
@@ -39,8 +39,8 @@ module Framed
|
|
39
39
|
dt.utc.iso8601
|
40
40
|
end
|
41
41
|
|
42
|
-
def flattened_hash(h, namespace = '',
|
43
|
-
h.reduce(
|
42
|
+
def flattened_hash(h, namespace = '', init = {})
|
43
|
+
h.reduce(init) do |memo, (key, value)|
|
44
44
|
value = value.to_h if value.respond_to?(:to_h)
|
45
45
|
if value.instance_of?(Hash)
|
46
46
|
memo.merge!(flattened_hash(value, "#{namespace}#{key}_", memo))
|
@@ -48,7 +48,7 @@ module Framed
|
|
48
48
|
memo["#{namespace}#{key}"] = value
|
49
49
|
end
|
50
50
|
memo
|
51
|
-
|
51
|
+
end
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
data/lib/framed/version.rb
CHANGED
data/lib/framed_rails.rb
CHANGED
@@ -23,11 +23,11 @@ module Framed
|
|
23
23
|
:password]
|
24
24
|
|
25
25
|
class << self
|
26
|
-
attr_accessor :client, :
|
26
|
+
attr_accessor :client, :emitter
|
27
27
|
|
28
28
|
def configuration
|
29
29
|
@configuration ||= {
|
30
|
-
:
|
30
|
+
:emitter => Framed::Emitters::Blocking,
|
31
31
|
:user_id_controller_method => 'framed_current_user_id',
|
32
32
|
:endpoint => Framed::FRAMED_API_ENDPOINT,
|
33
33
|
:logger => Logger.new(STDERR),
|
@@ -41,28 +41,28 @@ module Framed
|
|
41
41
|
(configuration[:excluded_params] + DEFAULT_EXCLUDED_PARAMS).uniq
|
42
42
|
end
|
43
43
|
|
44
|
-
def configure
|
44
|
+
def configure
|
45
45
|
yield configuration
|
46
46
|
self.client = Client.new(configuration)
|
47
47
|
|
48
|
-
@
|
49
|
-
@
|
48
|
+
@emitter.stop(true) if @emitter
|
49
|
+
@emitter = configuration[:emitter].new(self.client)
|
50
50
|
end
|
51
51
|
|
52
52
|
def report(event)
|
53
|
-
event[:lib] =
|
53
|
+
event[:lib] = 'framed_ruby'
|
54
54
|
event[:lib_version] = Framed::VERSION
|
55
55
|
event[:type] ||= :track
|
56
56
|
event[:context] ||= {}
|
57
57
|
event[:context].merge!({
|
58
|
-
:channel => 'server'
|
58
|
+
:channel => 'server'
|
59
59
|
})
|
60
60
|
|
61
61
|
event[:properties] ||= {}
|
62
62
|
|
63
63
|
# fill in if needed, in case it sits in queue for a while.
|
64
64
|
event[:timestamp] ||= Framed::Utils.serialize_date(Time.now)
|
65
|
-
@
|
65
|
+
@emitter.enqueue(event)
|
66
66
|
end
|
67
67
|
|
68
68
|
def logger
|
@@ -78,7 +78,7 @@ module Framed
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def drain
|
81
|
-
@
|
81
|
+
@emitter.stop(true) if @emitter
|
82
82
|
end
|
83
83
|
|
84
84
|
def user_id_controller_method
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: framed_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-12-
|
13
|
-
dependencies:
|
12
|
+
date: 2015-12-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rubocop
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.35.1
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.35.1
|
14
30
|
description: ! 'TK
|
15
31
|
|
16
32
|
'
|
@@ -23,11 +39,13 @@ extra_rdoc_files:
|
|
23
39
|
- README.md
|
24
40
|
files:
|
25
41
|
- .gitignore
|
42
|
+
- .rubocop.yml
|
26
43
|
- .ruby-version
|
27
44
|
- CHANGELOG
|
28
45
|
- Gemfile
|
29
46
|
- LICENSE
|
30
47
|
- README.md
|
48
|
+
- circle.yml
|
31
49
|
- framed_rails.gemspec
|
32
50
|
- lib/framed/client.rb
|
33
51
|
- lib/framed/emitters.rb
|