ridc 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/configuration.rb +28 -0
- data/lib/configuration_generator.rb +25 -0
- data/lib/log_reporter.rb +21 -0
- data/lib/ridc.rb +11 -9
- data/lib/sender.rb +32 -24
- metadata +4 -1
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module Ridc
|
4
|
+
class << self
|
5
|
+
attr_writer :configuration
|
6
|
+
|
7
|
+
def configuration
|
8
|
+
@configuration ||= OpenStruct.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def configure
|
12
|
+
yield(configuration)
|
13
|
+
end
|
14
|
+
|
15
|
+
def system_configured?
|
16
|
+
config = Ridc.configuration
|
17
|
+
[
|
18
|
+
config.customer_key,
|
19
|
+
config.secret_key,
|
20
|
+
config.host,
|
21
|
+
config.port,
|
22
|
+
config.application_id
|
23
|
+
|
24
|
+
].select { |a| a.nil? }.length == 0
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
|
4
|
+
module Ridc
|
5
|
+
|
6
|
+
class ConfigurationGenerator < Rails::Generators::Base
|
7
|
+
argument :application_token
|
8
|
+
|
9
|
+
desc "This generator creates Rails Intelligence system initializer"
|
10
|
+
def create_configuration_file
|
11
|
+
initializer "rails_intelligence.rb" do
|
12
|
+
<<-EOS
|
13
|
+
Ridc.configure do |config|
|
14
|
+
config.customer_key = "customerKey1"
|
15
|
+
config.secret_key = "secret1"
|
16
|
+
config.host = "railsintelligence.com"
|
17
|
+
config.port = "8080"
|
18
|
+
config.application_id = "appplication1"
|
19
|
+
end
|
20
|
+
EOS
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/lib/log_reporter.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
class Ridc::LogReporter
|
4
|
+
|
5
|
+
attr_reader :original
|
6
|
+
|
7
|
+
def initialize(original_logger)
|
8
|
+
@original = original_logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(m, *args, &block)
|
12
|
+
if %w{debug info warn error fatal}.include?(m.to_s)
|
13
|
+
event = {
|
14
|
+
"logger_severity" => m.to_s,
|
15
|
+
"logger_message" => args.join(' ')
|
16
|
+
}
|
17
|
+
Ridc.sender.load(event) if event["logger_message"].to_s.length > 0
|
18
|
+
end
|
19
|
+
@original.send(m, *args, &block)
|
20
|
+
end
|
21
|
+
end
|
data/lib/ridc.rb
CHANGED
@@ -1,24 +1,28 @@
|
|
1
1
|
require 'rails'
|
2
2
|
require 'sender'
|
3
3
|
require 'exception_reporter'
|
4
|
+
require 'log_reporter'
|
5
|
+
require 'configuration'
|
6
|
+
require 'configuration_generator'
|
4
7
|
|
5
8
|
class Ridc::MainRailtie < Rails::Railtie
|
6
9
|
|
7
10
|
initializer "rails_intelligence.configure_rails_initialization" do |app|
|
11
|
+
|
12
|
+
|
13
|
+
Rails.logger = Ridc::LogReporter.new(Rails.logger)
|
14
|
+
|
8
15
|
ActiveSupport::Notifications.subscribe do |*args|
|
9
16
|
|
10
17
|
event_payload = ActiveSupport::Notifications::Event.new *args
|
11
|
-
|
12
|
-
event_session_content = Thread.current["session_content"]
|
18
|
+
|
13
19
|
|
14
20
|
event = {
|
15
21
|
:event => event_payload,
|
16
|
-
:event_session_id => event_session_id,
|
17
|
-
:event_session_content => event_session_content
|
18
22
|
}
|
19
23
|
Ridc.sender.load(event)
|
20
24
|
# for debugging use:
|
21
|
-
# Rails.logger.debug(event.to_json)
|
25
|
+
# Rails.logger.original.debug(event.to_json)
|
22
26
|
end
|
23
27
|
|
24
28
|
ActiveSupport.on_load(:action_controller) do
|
@@ -29,12 +33,10 @@ class Ridc::MainRailtie < Rails::Railtie
|
|
29
33
|
# for Rails >= 3.2.0
|
30
34
|
"ActionDispatch::DebugExceptions"
|
31
35
|
else
|
32
|
-
|
36
|
+
# for Rails < 3.2.0
|
33
37
|
"ActionDispatch::ShowExceptions"
|
34
38
|
end
|
35
|
-
|
36
|
-
Rails.logger.warn("yeah!")
|
37
|
-
Rails.logger.warn(app.config.middleware)
|
39
|
+
app.config.middleware.insert_after middleware_name, "Ridc::ExceptionReporter"
|
38
40
|
end
|
39
41
|
|
40
42
|
module SessionToRailsIntelligenceFilter
|
data/lib/sender.rb
CHANGED
@@ -4,24 +4,32 @@ require 'base64'
|
|
4
4
|
require 'openssl'
|
5
5
|
require 'digest/sha1'
|
6
6
|
require 'socket'
|
7
|
+
require 'configuration'
|
7
8
|
|
8
9
|
module Ridc
|
9
10
|
|
10
11
|
SEND_LOOP_DELAY_S = 1
|
11
12
|
|
12
13
|
def Ridc.sender
|
13
|
-
|
14
|
+
|
15
|
+
Thread.current[:sender_worker] ||= Sender.new(
|
16
|
+
Ridc.configuration.customer_key ,
|
17
|
+
Ridc.configuration.secret_key,
|
18
|
+
Ridc.configuration.host,
|
19
|
+
Ridc.configuration.port,
|
20
|
+
Ridc.configuration.application_id)
|
14
21
|
end
|
15
22
|
|
16
23
|
class Sender
|
17
24
|
|
18
|
-
def initialize(customer_key, secret_key, host, port)
|
25
|
+
def initialize(customer_key, secret_key, host, port, application_id)
|
19
26
|
@queue = Queue.new
|
20
27
|
@worker_mutex = Mutex.new
|
28
|
+
@application_id = application_id
|
21
29
|
@customer_key = customer_key
|
22
30
|
@secret_key = secret_key
|
23
31
|
@host = host
|
24
|
-
@port = port
|
32
|
+
@port = port.to_s.to_i
|
25
33
|
@my_public_ip = my_first_public_ipv4
|
26
34
|
@my_private_ip = my_first_private_ipv4
|
27
35
|
@my_hostname = Socket.gethostname
|
@@ -31,9 +39,20 @@ module Ridc
|
|
31
39
|
end
|
32
40
|
|
33
41
|
def load(event)
|
34
|
-
|
42
|
+
event[:event_session_id] = Thread.current["session_id"]
|
43
|
+
event[:event_session_content] = Thread.current["session_content"]
|
44
|
+
event[:time] = Time.now.utc.to_i
|
45
|
+
body = {
|
46
|
+
"customerKey" => @customer_key,
|
47
|
+
"signature" => sign_with_secret_key(event.to_json),
|
48
|
+
"event" => event,
|
49
|
+
"hostname" => @my_hostname,
|
50
|
+
"public_ip_v4" => @my_public_ip,
|
51
|
+
"private_ip_v4" => @my_private_ip,
|
52
|
+
"environment" => @environment
|
53
|
+
}
|
35
54
|
|
36
|
-
@queue <<
|
55
|
+
@queue << body
|
37
56
|
@worker_mutex.synchronize do
|
38
57
|
if @sender_started
|
39
58
|
check_sender_thread
|
@@ -54,33 +73,22 @@ module Ridc
|
|
54
73
|
|
55
74
|
def send_all_events
|
56
75
|
loop do
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
send(event)
|
76
|
+
body = @queue.pop(true)
|
77
|
+
unless body.nil?
|
78
|
+
send_request(body)
|
61
79
|
else
|
62
80
|
sleep(SEND_LOOP_DELAY_S)
|
63
81
|
end
|
64
82
|
end
|
65
83
|
end
|
66
84
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
Rails.logger.info("sending")
|
71
|
-
body = {
|
72
|
-
"customerKey" => @customer_key,
|
73
|
-
"signature" => sign_with_secret_key(event.to_json),
|
74
|
-
"event" => event,
|
75
|
-
"hostname" => @my_hostname,
|
76
|
-
"public_ip_v4" => @my_public_ip,
|
77
|
-
"private_ip_v4" => @my_private_ip,
|
78
|
-
"environment" => @environment
|
79
|
-
}.to_json
|
80
|
-
|
81
|
-
req.body = body
|
85
|
+
def send_request(body)
|
86
|
+
req = Net::HTTP::Post.new("/events", initheader = {'Content-Type' => 'application/json'})
|
87
|
+
req.body = body.to_json
|
82
88
|
response = Net::HTTP.new(@host, @port).start { |http| http.request(req) }
|
83
89
|
return response
|
90
|
+
rescue Exception => e
|
91
|
+
Rails.logger.original.error(e)
|
84
92
|
end
|
85
93
|
|
86
94
|
|
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.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -23,6 +23,9 @@ files:
|
|
23
23
|
- lib/ridc.rb
|
24
24
|
- lib/sender.rb
|
25
25
|
- lib/exception_reporter.rb
|
26
|
+
- lib/log_reporter.rb
|
27
|
+
- lib/configuration.rb
|
28
|
+
- lib/configuration_generator.rb
|
26
29
|
homepage: http://www.railsintelligence.com
|
27
30
|
licenses:
|
28
31
|
- MIT
|