ridc 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/exception_reporter.rb +28 -0
- data/lib/ridc.rb +43 -3
- data/lib/sender.rb +49 -0
- metadata +3 -2
- data/lib/ri_sender.rb +0 -41
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
class Ridc::ExceptionReporter
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
response = @app.call(env)
|
10
|
+
rescue Exception => exception
|
11
|
+
Ridc::ExceptionReporter.report(exception, env)
|
12
|
+
raise exception
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.report(exception, environment)
|
16
|
+
|
17
|
+
event_session_id = Thread.current["session_id"]
|
18
|
+
event_session_content = Thread.current["session_content"]
|
19
|
+
event = {
|
20
|
+
:exception => exception,
|
21
|
+
:environment => environment,
|
22
|
+
:event_session_id => event_session_id,
|
23
|
+
:event_session_content => event_session_content
|
24
|
+
}
|
25
|
+
Ridc.sender.send(event)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/lib/ridc.rb
CHANGED
@@ -1,10 +1,50 @@
|
|
1
1
|
require 'rails'
|
2
|
+
require 'sender'
|
3
|
+
require 'exception_reporter'
|
4
|
+
|
5
|
+
class Ridc::MainRailtie < Rails::Railtie
|
2
6
|
|
3
|
-
class Ridc < Rails::Railtie
|
4
7
|
initializer "rails_intelligence.configure_rails_initialization" do |app|
|
5
8
|
ActiveSupport::Notifications.subscribe do |*args|
|
6
|
-
|
7
|
-
|
9
|
+
|
10
|
+
event_payload = ActiveSupport::Notifications::Event.new *args
|
11
|
+
event_session_id = Thread.current["session_id"]
|
12
|
+
event_session_content = Thread.current["session_content"]
|
13
|
+
|
14
|
+
event = {
|
15
|
+
:event => event_payload,
|
16
|
+
:event_session_id => event_session_id,
|
17
|
+
:event_session_content => event_session_content
|
18
|
+
}
|
19
|
+
Ridc.sender.send(event)
|
20
|
+
# for debugging use:
|
21
|
+
# Rails.logger.debug(event.to_json)
|
22
|
+
end
|
23
|
+
|
24
|
+
ActiveSupport.on_load(:action_controller) do
|
25
|
+
ActionController::Base.send(:include, SessionToRailsIntelligenceFilter)
|
8
26
|
end
|
27
|
+
|
28
|
+
middleware_name = if defined?(ActionDispatch::DebugExceptions)
|
29
|
+
# for Rails >= 3.2.0
|
30
|
+
"ActionDispatch::DebugExceptions"
|
31
|
+
else
|
32
|
+
# for Rails < 3.2.0
|
33
|
+
"ActionDispatch::ShowExceptions"
|
34
|
+
end
|
35
|
+
app.config.middleware.insert_after middleware_name, "Ridc::ExceptionReporter"
|
9
36
|
end
|
37
|
+
|
38
|
+
module SessionToRailsIntelligenceFilter
|
39
|
+
extend ActiveSupport::Concern
|
40
|
+
|
41
|
+
included do
|
42
|
+
append_before_filter :make_session_available_to_ridc
|
43
|
+
end
|
44
|
+
|
45
|
+
def make_session_available_to_ridc
|
46
|
+
Thread.current["session_id"] = request.session_options[:id]
|
47
|
+
Thread.current["session_content"] = session
|
48
|
+
end
|
49
|
+
end
|
10
50
|
end
|
data/lib/sender.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'base64'
|
4
|
+
require 'openssl'
|
5
|
+
require 'digest/sha1'
|
6
|
+
|
7
|
+
module Ridc
|
8
|
+
|
9
|
+
def Ridc.sender
|
10
|
+
Thread.current[:ridc_sender] ||= Sender.new("customerKey1" , "secret1", "railsintelligence.com", 8080)
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class Sender
|
15
|
+
|
16
|
+
def initialize(customer_key, secret_key, host, port)
|
17
|
+
@customer_key = customer_key
|
18
|
+
@secret_key = secret_key
|
19
|
+
@host = host
|
20
|
+
@port = port
|
21
|
+
end
|
22
|
+
|
23
|
+
def send(event)
|
24
|
+
req = Net::HTTP::Post.new("/events", initheader = {'Content-Type' => 'application/json'})
|
25
|
+
|
26
|
+
body = {
|
27
|
+
"customerKey" => @customer_key,
|
28
|
+
"signature" => sign_with_secret_key(event.to_json),
|
29
|
+
"event" => event
|
30
|
+
}.to_json
|
31
|
+
|
32
|
+
req.body = body
|
33
|
+
response = Net::HTTP.new(@host, @port).start { |http| http.request(req) }
|
34
|
+
response
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def sign_with_secret_key(payload)
|
40
|
+
signature = Base64.encode64(
|
41
|
+
OpenSSL::HMAC.digest(
|
42
|
+
OpenSSL::Digest::Digest.new('sha1'),
|
43
|
+
@secret_key, payload)
|
44
|
+
).gsub("\n", "")
|
45
|
+
|
46
|
+
signature
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -21,7 +21,8 @@ extensions: []
|
|
21
21
|
extra_rdoc_files: []
|
22
22
|
files:
|
23
23
|
- lib/ridc.rb
|
24
|
-
- lib/
|
24
|
+
- lib/sender.rb
|
25
|
+
- lib/exception_reporter.rb
|
25
26
|
homepage: http://www.railsintelligence.com
|
26
27
|
licenses:
|
27
28
|
- MIT
|
data/lib/ri_sender.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'json'
|
3
|
-
require 'base64'
|
4
|
-
require 'openssl'
|
5
|
-
require 'digest/sha1'
|
6
|
-
|
7
|
-
class RiSender
|
8
|
-
|
9
|
-
def initialize(customer_key, secret_key, host, port)
|
10
|
-
@customer_key = customer_key
|
11
|
-
@secret_key = secret_key
|
12
|
-
@host = host
|
13
|
-
@port = port
|
14
|
-
end
|
15
|
-
|
16
|
-
def send(event)
|
17
|
-
req = Net::HTTP::Post.new("/events", initheader = {'Content-Type' => 'application/json'})
|
18
|
-
|
19
|
-
body = {
|
20
|
-
"customerKey" => @customer_key,
|
21
|
-
"signature" => sign_with_secret_key(event.to_json),
|
22
|
-
"event" => event
|
23
|
-
}.to_json
|
24
|
-
|
25
|
-
req.body = body
|
26
|
-
response = Net::HTTP.new(@host, @port).start { |http| http.request(req) }
|
27
|
-
response
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def sign_with_secret_key(payload)
|
33
|
-
signature = Base64.encode64(
|
34
|
-
OpenSSL::HMAC.digest(
|
35
|
-
OpenSSL::Digest::Digest.new('sha1'),
|
36
|
-
@secret_key, payload)
|
37
|
-
).gsub("\n", "")
|
38
|
-
|
39
|
-
signature
|
40
|
-
end
|
41
|
-
end
|