framed_rails 0.1.5 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -0
- data/lib/framed/client.rb +1 -1
- data/lib/framed/emitters.rb +5 -5
- data/lib/framed/rails.rb +25 -17
- data/lib/framed/version.rb +2 -1
- data/lib/framed_rails.rb +23 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -69,6 +69,15 @@ Configuration
|
|
69
69
|
<td>false</td>
|
70
70
|
</tr>
|
71
71
|
|
72
|
+
<tr>
|
73
|
+
<td>:excluded_params</td>
|
74
|
+
<td>An array of request parameter keys to never send to Framed. <code>:controller</code>, <code>:action</code>,
|
75
|
+
<code>:utf8</code>, <code>:authenticity_token</code>, <code>:commit</code>, and <code>:password</code> are never
|
76
|
+
sent, and anything added here is in addition to default values.
|
77
|
+
</td>
|
78
|
+
<td>[]</td>
|
79
|
+
</tr>
|
80
|
+
|
72
81
|
</table>
|
73
82
|
|
74
83
|
Emitters
|
data/lib/framed/client.rb
CHANGED
data/lib/framed/emitters.rb
CHANGED
@@ -27,7 +27,7 @@ module Framed
|
|
27
27
|
begin
|
28
28
|
@client.track(events)
|
29
29
|
rescue Exception => exc
|
30
|
-
Framed.
|
30
|
+
Framed.log_error("#transmit failed: #{exc}")
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -47,7 +47,7 @@ module Framed
|
|
47
47
|
|
48
48
|
class Logger < Base
|
49
49
|
def enqueue(event)
|
50
|
-
Framed.
|
50
|
+
Framed.log_info(JSON.generate(event))
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -78,7 +78,7 @@ module Framed
|
|
78
78
|
|
79
79
|
def start
|
80
80
|
if @request_thread and !@request_thread.alive?
|
81
|
-
Framed.
|
81
|
+
Framed.log_info("Starting request thread due to dead thread")
|
82
82
|
end
|
83
83
|
|
84
84
|
@request_thread = Thread.new do
|
@@ -116,7 +116,7 @@ module Framed
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def warn_full(event)
|
119
|
-
Framed.
|
119
|
+
Framed.log_error("Queued #{event} to Framed, but queue is full. Dropping event.")
|
120
120
|
end
|
121
121
|
|
122
122
|
def enqueue(event)
|
@@ -179,7 +179,7 @@ module Framed
|
|
179
179
|
begin
|
180
180
|
@client.track(events)
|
181
181
|
rescue Exception => exc
|
182
|
-
Framed.
|
182
|
+
Framed.log_error("#transmit failed: #{exc}")
|
183
183
|
end
|
184
184
|
end
|
185
185
|
end
|
data/lib/framed/rails.rb
CHANGED
@@ -6,28 +6,43 @@ ActionController::Base.class_eval do
|
|
6
6
|
"#{request.method}_#{params[:controller]}\##{params[:action]}"
|
7
7
|
end
|
8
8
|
|
9
|
+
# XHR requests are not sent unless explictly enabled or Turbolinks, which
|
10
|
+
# is a special kind of XHR
|
9
11
|
def framed_included?(request)
|
10
12
|
return true if Framed.configuration[:include_xhr]
|
11
|
-
# include Turbolinks requests (which are a special kind of XHR)
|
12
13
|
return true if request.headers.include?('X-XHR-Referer')
|
13
14
|
|
14
15
|
!request.xhr?
|
15
16
|
end
|
16
17
|
|
18
|
+
def framed_get_or_make_anonymous_id
|
19
|
+
anonymous_id = cookies.signed[Framed.anonymous_cookie]
|
20
|
+
|
21
|
+
if anonymous_id.nil?
|
22
|
+
anonymous_id = Framed.new_anonymous_id
|
23
|
+
cookie = {:value => anonymous_id, :httponly => true}
|
24
|
+
cookies.signed.permanent[Framed.anonymous_cookie] = cookie
|
25
|
+
end
|
26
|
+
|
27
|
+
return anonymous_id
|
28
|
+
end
|
29
|
+
|
30
|
+
def framed_current_user_id
|
31
|
+
begin
|
32
|
+
current_user.try(:id)
|
33
|
+
rescue
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
17
38
|
def framed_report_request
|
18
39
|
return unless framed_included?(request)
|
19
40
|
|
20
41
|
begin
|
21
|
-
anonymous_id =
|
42
|
+
anonymous_id = framed_get_or_make_anonymous_id
|
22
43
|
user_id = send(Framed.user_id_controller_method)
|
44
|
+
cleaned_params = params.except(*Framed.excluded_params).to_h
|
23
45
|
|
24
|
-
if anonymous_id.nil?
|
25
|
-
anonymous_id = Framed.new_anonymous_id
|
26
|
-
cookie = {:value => anonymous_id, :httponly => true}
|
27
|
-
cookies.signed.permanent[Framed.anonymous_cookie] = cookie
|
28
|
-
end
|
29
|
-
|
30
|
-
cleaned_params = params.except(:controller, :action).to_h
|
31
46
|
event = {
|
32
47
|
:type => :track,
|
33
48
|
:anonymous_id => anonymous_id,
|
@@ -46,15 +61,8 @@ ActionController::Base.class_eval do
|
|
46
61
|
|
47
62
|
Framed.report(event)
|
48
63
|
rescue Exception => exc
|
49
|
-
Framed.
|
64
|
+
Framed.log_error("Failed to report request #{exc}")
|
50
65
|
end
|
51
66
|
end
|
52
67
|
|
53
|
-
def framed_current_user_id
|
54
|
-
begin
|
55
|
-
current_user.try(:id)
|
56
|
-
rescue
|
57
|
-
nil
|
58
|
-
end
|
59
|
-
end
|
60
68
|
end
|
data/lib/framed/version.rb
CHANGED
data/lib/framed_rails.rb
CHANGED
@@ -12,6 +12,15 @@ module Framed
|
|
12
12
|
SEGMENT_API_ENDPOINT = 'https://api.segment.io/v1/track'
|
13
13
|
FRAMED_API_ENDPOINT = 'https://intake.framed.io/events'
|
14
14
|
COOKIE_NAME = 'framed_id'
|
15
|
+
LOG_PREFIX = '[framed_rails] '
|
16
|
+
|
17
|
+
DEFAULT_EXCLUDED_PARAMS =
|
18
|
+
[:controller,
|
19
|
+
:action,
|
20
|
+
:utf8,
|
21
|
+
:authenticity_token,
|
22
|
+
:commit,
|
23
|
+
:password]
|
15
24
|
|
16
25
|
class << self
|
17
26
|
attr_accessor :client, :consumer
|
@@ -23,10 +32,15 @@ module Framed
|
|
23
32
|
:endpoint => Framed::FRAMED_API_ENDPOINT,
|
24
33
|
:logger => Logger.new(STDERR),
|
25
34
|
:anonymous_cookie => Framed::COOKIE_NAME,
|
26
|
-
:include_xhr => false
|
35
|
+
:include_xhr => false,
|
36
|
+
:excluded_params => []
|
27
37
|
}
|
28
38
|
end
|
29
39
|
|
40
|
+
def excluded_params
|
41
|
+
(configuration[:excluded_params] + DEFAULT_EXCLUDED_PARAMS).uniq
|
42
|
+
end
|
43
|
+
|
30
44
|
def configure(silent = false)
|
31
45
|
yield configuration
|
32
46
|
self.client = Client.new(configuration)
|
@@ -55,6 +69,14 @@ module Framed
|
|
55
69
|
configuration[:logger]
|
56
70
|
end
|
57
71
|
|
72
|
+
def log_info(msg)
|
73
|
+
logger.info(LOG_PREFIX + msg)
|
74
|
+
end
|
75
|
+
|
76
|
+
def log_error(msg)
|
77
|
+
logger.error(LOG_PREFIX + msg)
|
78
|
+
end
|
79
|
+
|
58
80
|
def drain
|
59
81
|
@consumer.stop(true) if @consumer
|
60
82
|
end
|
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.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-12-04 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'TK
|
15
15
|
|