trackets 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ab51f862a68579d25a95431d01837188a576643
4
- data.tar.gz: 9ab4073d18a851ce750e1f515cf1a373dc1c792c
3
+ metadata.gz: e2dbf014142cf8754519141f942b30fcf611208b
4
+ data.tar.gz: 4d980a1f00648ab4202f6ab395529740d0c2289b
5
5
  SHA512:
6
- metadata.gz: 1f3934d1d485647b2820b5145b320b0458be583ffbdc0c79069333a4432a9807c23b4846843fb2c1b5a6193e64fe2334daf86988e3bd6e2995bff5db62b804ea
7
- data.tar.gz: 65d9ba622500cf4f0ed079ecf70bcafd4bec459d8c2ce916686a9f302f466d17156355a4e5afe5a88fcb3ce23bc8294fa6f69664a279ec06046a0504903ff4a5
6
+ metadata.gz: 33d10a87d3596d5478d29bb00a9265a109eb17297bc00ee799cd27143529b33fbd950591541dea43acdde4f486ad13e2fc961aa35e304bb63e12e4bf4e62fdf8
7
+ data.tar.gz: 1515bbe0dcee9a762154e948249aa21ed7dba4d3f7c2547c799e2405449349357286318e51e95b0ff9b5937d08a9ee1000567cbd44c0846aa893c930f253d545
data/README.md CHANGED
@@ -16,6 +16,14 @@ And then execute:
16
16
 
17
17
  $ rails g trackets:install API_KEY
18
18
 
19
+ ## Rails
20
+
21
+ To include JavaScript tracking code in your app just add this line to your `app/views/layout/application.html.erb`
22
+
23
+ ```erb
24
+ <%= trackets_include_tag %>
25
+ ```
26
+
19
27
  ## Contributing
20
28
 
21
29
  1. Fork it ( https://github.com/[my-github-username]/trackets/fork )
data/lib/tasks/.keep ADDED
File without changes
@@ -0,0 +1,15 @@
1
+ namespace :trackets do
2
+
3
+ desc "Test Trackets integration"
4
+ task :test => :environment do
5
+ puts "Raising exception to test Trackets integration"
6
+
7
+ Trackets.send_custom_exception('Testing Trackets Gem integration via "rake trackets:test"')
8
+ end
9
+
10
+ desc "Send custom message defined in a MESSAGE environment variable"
11
+ task :notify => :environment do
12
+ Trackets.send_custom_exception(ENV['MESSAGE'])
13
+ end
14
+
15
+ end
@@ -1,6 +1,8 @@
1
1
  require "httparty"
2
2
  require "trackets/backtrace"
3
3
  require "trackets/params"
4
+ require "trackets/null_env"
5
+ require "trackets/rack_env_sanitizer"
4
6
 
5
7
  module Trackets
6
8
  class Client
@@ -27,27 +29,11 @@ module Trackets
27
29
  end
28
30
 
29
31
  def params
30
- @params ||= Params.new(env)
32
+ @params ||= env ? Params.new(env) : NullEnv.new
31
33
  end
32
34
 
33
- def whitelisted_env
34
- env.reject { |k,v| !Trackets.configuration.whitelisted_env.include?(k) }
35
- end
36
-
37
- def filtered_env
38
- whitelisted_env.inject({}) do |result, (key, val)|
39
- result[key] = filter_env_val(val) if key && val =~ /\S/
40
- result
41
- end
42
- end
43
-
44
- def filter_env_val(value)
45
- value.scan(/(?:^|&|\?)([^=?&]+)=([^&]+)/).each do |match|
46
- next unless params.blacklisted?(match[0])
47
- value.gsub!(/#{match[1]}/, '[FILTERED]')
48
- end
49
-
50
- value
35
+ def rack_env_sanitizer
36
+ @rack_env_sanitizer ||= env ? RackEnvSanitizer.new(env) : NullEnv.new
51
37
  end
52
38
 
53
39
  def payload
@@ -56,7 +42,7 @@ module Trackets
56
42
  message: exception.message,
57
43
  class_name: exception.class.to_s,
58
44
  stacktrace: backtrace.parse.join("\n"),
59
- env: filtered_env,
45
+ env: rack_env_sanitizer.filtered,
60
46
  environment_name: config.environment_name,
61
47
  project_root: config.project_root,
62
48
  framework: config.framework,
@@ -35,5 +35,17 @@ module Trackets
35
35
  @blacklisted_params = DEFAULT_BLACKLISTED_PARAMS
36
36
  end
37
37
 
38
+ def rack_filter_keys(rack_env = nil)
39
+ @rack_filter_keys ||= rack_env ? Array(rack_env["action_dispatch.parameter_filter"]) : []
40
+ end
41
+
42
+ def blacklisted_keys(rack_env = nil)
43
+ @blacklisted_keys ||= (blacklisted_params + rack_filter_keys).map(&:to_s)
44
+ end
45
+
46
+ def blacklisted_key?(key, rack_env = nil)
47
+ blacklisted_keys.include?(key)
48
+ end
49
+
38
50
  end
39
51
  end
@@ -0,0 +1,9 @@
1
+ module Trackets
2
+ class NullEnv
3
+
4
+ def filtered
5
+ nil
6
+ end
7
+
8
+ end
9
+ end
@@ -7,10 +7,6 @@ module Trackets
7
7
  @rack_env = rack_env
8
8
  end
9
9
 
10
- def rack_filter_keys
11
- @rack_filter_keys ||= Array(rack_env["action_dispatch.parameter_filter"])
12
- end
13
-
14
10
  def request
15
11
  @request ||= Rack::Request.new(rack_env)
16
12
  end
@@ -19,20 +15,12 @@ module Trackets
19
15
  @hash ||= request.params
20
16
  end
21
17
 
22
- def blacklisted_keys
23
- @blacklisted_keys ||= (Trackets.configuration.blacklisted_params + rack_filter_keys).map(&:to_s)
24
- end
25
-
26
- def blacklisted?(key)
27
- blacklisted_keys.include?(key)
28
- end
29
-
30
18
  def filtered
31
19
  hash.inject({}) do |ret, (key, value)|
32
20
  ret[key] = if value.kind_of?(Hash)
33
21
  self.class.new(value).filtered
34
22
  else
35
- blacklisted?(key) ? "[FILTERED]" : value
23
+ Trackets.configuration.blacklisted_key?(key, rack_env) ? "[FILTERED]" : value
36
24
  end
37
25
 
38
26
  ret
@@ -0,0 +1,32 @@
1
+ module Trackets
2
+ class RackEnvSanitizer
3
+
4
+ attr_reader :rack_env
5
+
6
+ def initialize(rack_env)
7
+ @rack_env = rack_env
8
+ end
9
+
10
+ def filtered
11
+ whitelisted_env.inject({}) do |result, (key, val)|
12
+ result[key] = filter_val(val) if key && val =~ /\S/
13
+ result
14
+ end
15
+ end
16
+
17
+ private
18
+ def whitelisted_env
19
+ rack_env.reject { |k,v| !Trackets.configuration.whitelisted_env.include?(k) }
20
+ end
21
+
22
+ def filter_val(value)
23
+ value.scan(/(?:^|&|\?)([^=?&]+)=([^&]+)/).each do |match|
24
+ next unless Trackets.configuration.blacklisted_key?(match[0], rack_env)
25
+ value.gsub!(/#{match[1]}/, '[FILTERED]')
26
+ end
27
+
28
+ value
29
+ end
30
+
31
+ end
32
+ end
@@ -22,5 +22,9 @@ module Trackets
22
22
  end
23
23
  end
24
24
 
25
+ rake_tasks do
26
+ load "tasks/trackets.tasks"
27
+ end
28
+
25
29
  end
26
30
  end
@@ -1,3 +1,3 @@
1
1
  module Trackets
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  module Trackets
2
2
  module ViewHelpers
3
3
  def trackets_include_tag
4
- javascript_include_tag "//trackets.s3.amazonaws.com/client.js"
4
+ javascript_include_tag "//trackets.s3.amazonaws.com/client.js", data: { "trackets-key" => Trackets.configuration.api_key }
5
5
  end
6
6
  end
7
7
  end
data/lib/trackets.rb CHANGED
@@ -14,9 +14,19 @@ module Trackets
14
14
  @configuration ||= Configuration.new
15
15
  end
16
16
 
17
- def notify(exception, env)
17
+ def notify(exception, env = nil)
18
18
  Client.notify(exception, env)
19
19
  end
20
20
 
21
+ class TracketsCustomException < StandardError; end
22
+
23
+ def send_custom_exception(message = nil)
24
+ begin
25
+ raise TracketsCustomException, message
26
+ rescue TracketsCustomException => e
27
+ Trackets.notify(e)
28
+ end
29
+ end
30
+
21
31
  end
22
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trackets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Votava
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-19 00:00:00.000000000 Z
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -142,12 +142,16 @@ files:
142
142
  - features/support/templates/trackets_interceptor.rb
143
143
  - lib/generators/trackets/install_generator.rb
144
144
  - lib/generators/trackets/templates/initializer.rb
145
+ - lib/tasks/.keep
146
+ - lib/tasks/trackets.tasks
145
147
  - lib/trackets.rb
146
148
  - lib/trackets/backtrace.rb
147
149
  - lib/trackets/client.rb
148
150
  - lib/trackets/configuration.rb
149
151
  - lib/trackets/middleware/rack_exception_handler.rb
152
+ - lib/trackets/null_env.rb
150
153
  - lib/trackets/params.rb
154
+ - lib/trackets/rack_env_sanitizer.rb
151
155
  - lib/trackets/railtie.rb
152
156
  - lib/trackets/version.rb
153
157
  - lib/trackets/view_helpers.rb