whenauser 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -36,7 +36,7 @@ You should create two incoming channels (event streams) in WhenAUser, and config
36
36
  Using girl_friday for asynchronous communication and persistence
37
37
  -----------------
38
38
 
39
- By default this gem sends a batch of events to the WhenAUser service synchronously, at the end of each request to your application. This means that each request to your app will be slowed down by the time it takes to do that communication. In general, this is not going to be acceptable. To avoid this delay, WhenAUser supports the use of the [girl_friday](https://github.com/mperham/girl_friday) gem, which you can enable in your whenauser.rb file:
39
+ By default this gem sends a batch of events to the WhenAUser service synchronously, at the end of each request to your application. This means that each request to your app will be slowed down by the time it takes to do that communication. While this is fine for development or for low-volume sites, for those who wish to avoid this delay WhenAUser supports the use of the [girl_friday](https://github.com/mperham/girl_friday) gem, which you can enable in your whenauser.rb file:
40
40
 
41
41
  queue WhenAUser::GirlFridayQueue
42
42
 
@@ -29,6 +29,7 @@ module WhenAUser
29
29
  begin
30
30
  @app.call(env)
31
31
  rescue Exception => exception
32
+ env['whenauser.exception'] = exception
32
33
  send_event_now event(env, exception), @options[:token] unless should_be_ignored(env, exception)
33
34
  raise exception
34
35
  end
@@ -55,24 +56,15 @@ module WhenAUser
55
56
  false
56
57
  end
57
58
 
58
- def clean_backtrace(exception)
59
- if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner)
60
- Rails.backtrace_cleaner.send(:filter, exception.backtrace)
61
- else
62
- exception.backtrace
63
- end
64
- end
65
-
66
59
  def event(env, exception)
67
60
  request = ActionDispatch::Request.new(env)
68
61
  backtrace = clean_backtrace(exception)
69
- actor = backtrace.first.match(/^(.*:.*):/)[1] rescue @app.to_s
70
62
  event = {
71
- :_actor => actor,
63
+ :_actor => actor_for_exception(exception),
72
64
  :_domain => 'exception',
73
65
  :_name => exception.class.to_s,
74
66
  :message => exception.to_s,
75
- :backtrace => backtrace.join("; "),
67
+ :backtrace => backtrace.join("\n"),
76
68
  :request_url => request.url,
77
69
  :request_method => request.request_method,
78
70
  :params => request.params.except(*WhenAUser.filter_parameters),
@@ -18,5 +18,19 @@ module WhenAUser
18
18
  rescue
19
19
  nil
20
20
  end
21
+
22
+ def clean_backtrace(exception)
23
+ if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner)
24
+ Rails.backtrace_cleaner.send(:filter, exception.backtrace)
25
+ else
26
+ exception.backtrace
27
+ end
28
+ end
29
+
30
+ def actor_for_exception(exception)
31
+ backtrace = clean_backtrace(exception)
32
+ fileline = backtrace.first.match(/^(.*:.*):/)[1] rescue @app.to_s
33
+ "#{exception.class.to_s}:#{fileline}"
34
+ end
21
35
  end
22
36
  end
@@ -16,6 +16,7 @@ module WhenAUser
16
16
  end
17
17
 
18
18
  def call(env)
19
+ request = ActionDispatch::Request.new(env)
19
20
  before = Time.now
20
21
  status, headers, response = @app.call(env)
21
22
  [status, headers, response]
@@ -24,7 +25,6 @@ module WhenAUser
24
25
  raise e
25
26
  ensure
26
27
  after = Time.now
27
- request = ActionDispatch::Request.new(env)
28
28
  WhenAUser.send_event event(env, request, status, after - before) unless should_be_ignored(env, request)
29
29
  end
30
30
 
@@ -45,7 +45,7 @@ module WhenAUser
45
45
  false
46
46
  end
47
47
 
48
- def event_name(request)
48
+ def page_event_name(request)
49
49
  if (params = request.params)['controller']
50
50
  "#{params['controller']}##{params['action']}"
51
51
  else
@@ -57,8 +57,8 @@ module WhenAUser
57
57
  actor = current_user(env) || 'anonymous'
58
58
  event = {
59
59
  :_actor => actor,
60
- :_domain => 'pageview',
61
- :_name => event_name(request),
60
+ :_domain => (status >= 400) ? 'pageerror' : 'pageview',
61
+ :_name => page_event_name(request),
62
62
  :request_url => request.url,
63
63
  :request_method => request.request_method,
64
64
  :params => request.params.except(*WhenAUser.filter_parameters),
@@ -66,6 +66,10 @@ module WhenAUser
66
66
  :status => status,
67
67
  :duration => "%.2f" % (duration * 1000)
68
68
  }
69
+ if exception = env['whenauser.exception']
70
+ event.merge!(:error => actor_for_exception(exception))
71
+ event.merge!(:message => exception.to_s)
72
+ end
69
73
  event.merge!(:referer_url => request.referer) if request.referer
70
74
  event.merge!(:rails_env => Rails.env) if defined?(Rails)
71
75
  event.merge!(@options[:custom_data].call(env))
@@ -1,3 +1,3 @@
1
1
  module WhenAUser
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whenauser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-02 00:00:00.000000000 Z
13
+ date: 2012-08-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport