excepty 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/bin/excepty +2 -0
- data/excepty.gemspec +29 -0
- data/lib/excepty.rb +19 -0
- data/lib/excepty/analyzer.rb +10 -0
- data/lib/excepty/analyzers/enviroment.rb +138 -0
- data/lib/excepty/analyzers/error.rb +20 -0
- data/lib/excepty/analyzers/repositoy.rb +7 -0
- data/lib/excepty/analyzers/request.rb +7 -0
- data/lib/excepty/connector.rb +61 -0
- data/lib/excepty/exception_interceptor.rb +28 -0
- data/lib/excepty/manager.rb +148 -0
- data/lib/excepty/railtie.rb +38 -0
- data/lib/excepty/settings.rb +96 -0
- data/lib/excepty/version.rb +3 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTZlMjU1Y2JmMmRjZmIxZmMzZjQ2YThlMmU2ZDQzMmI5YjQwNzg1Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MzkwNDRjYTIxZTMxNTdkYmM2M2FjN2U4MWRiNmYzZmQ0ZjE1MmNkZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Yzk5MDlhY2ZkNjhmZDI2Y2IxZmZmMGRiM2IwNjE5YWU5OGM5MWYxN2YwODNk
|
10
|
+
YzViMWQ3YzcxYTYzMmUxZGQ5ZDdjMzA3YjFmZTdiZjc1NTE5ZDk1NDE3NjBm
|
11
|
+
YWFmYzcxNjgxYWNhODczNTcwYzY4MzYxMjIwNTIzYmM1MWYyZjc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MWEyZDlkMThmOTRlZWVmOTgwNjRlYjYyNzUzOGY4ZWUzYjg1NTZmMmJiOGI5
|
14
|
+
NjZmZWI5MWY5MGFkNWMwNzk3ZGYwNGZmZjhiYjVlZGQxNGYyNzIxYjZlMmIy
|
15
|
+
NjM5MjhhMzFjOWE5MmZkZjY0NTM2YTMwMGJhMWQwNTI5MjMzMzc=
|
data/bin/excepty
ADDED
data/excepty.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#require File.expand_path('../lib/excepty/version', __FILE__)
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'excepty/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |gem|
|
9
|
+
gem.name = "excepty"
|
10
|
+
gem.version = Excepty::VERSION
|
11
|
+
gem.authors = ["Excepty"]
|
12
|
+
gem.email = ["gem@excepty.com"]
|
13
|
+
gem.description = %q{T ODO: Write a gem description} #TODO
|
14
|
+
gem.summary = %q{T ODO: Write a gem summary} #TODO
|
15
|
+
gem.homepage = "http://www.excepty.com/"
|
16
|
+
|
17
|
+
#gem.files = `git ls-files`.split($/)
|
18
|
+
gem.files = Dir['lib/**/*'] + Dir['*.rb'] + ["excepty.gemspec"]
|
19
|
+
# + Dir['spec/**/*'] + Dir['spec/**/*'] + Dir['rails/**/*'] + Dir['tasks/**/*']
|
20
|
+
|
21
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
22
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
23
|
+
gem.require_paths = ["lib"]
|
24
|
+
|
25
|
+
gem.executables << 'excepty'
|
26
|
+
#gem.rubyforge_project = %q{excepty}
|
27
|
+
#gem.requirements << "json_pure, json-jruby or json gem required"
|
28
|
+
|
29
|
+
end
|
data/lib/excepty.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
EXCEPTY_IN_TESTING_MODE = false
|
2
|
+
|
3
|
+
require "excepty/version"
|
4
|
+
|
5
|
+
require 'excepty/manager'
|
6
|
+
require 'excepty/settings'
|
7
|
+
require 'excepty/analyzer'
|
8
|
+
require 'excepty/connector'
|
9
|
+
require 'excepty/exception_interceptor'
|
10
|
+
|
11
|
+
|
12
|
+
require 'excepty/railtie' if defined?(Rails) && defined?(Rails::Railtie)
|
13
|
+
|
14
|
+
|
15
|
+
module Excepty
|
16
|
+
|
17
|
+
# Your code goes here...
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
|
2
|
+
module Excepty
|
3
|
+
module Analyzer
|
4
|
+
class Enviroment
|
5
|
+
|
6
|
+
def self.get_struct( my_env = nil )
|
7
|
+
my_env = ENV if my_env.blank?
|
8
|
+
return_struct = {}
|
9
|
+
begin
|
10
|
+
return_struct['env'] = get_env( my_env )
|
11
|
+
rescue Exception => e
|
12
|
+
Excepty::Manager.logga "exception (get_struct-get_env)"
|
13
|
+
begin
|
14
|
+
Excepty::Manager.logga e
|
15
|
+
return_struct['env'] = 'EXCEPTION'
|
16
|
+
#return_struct['env'] = my_env
|
17
|
+
rescue Exception => e
|
18
|
+
end
|
19
|
+
end
|
20
|
+
begin
|
21
|
+
return_struct['rack_env'] = my_env['RACK_ENV']
|
22
|
+
return_struct['rails_env'] = my_env['RAILS_ENV']
|
23
|
+
return_struct['host'] = begin Socket.gethostname; rescue Exception => e; 'UNKNOWN' end
|
24
|
+
rescue Exception => e
|
25
|
+
end
|
26
|
+
begin
|
27
|
+
return_struct['root_folder'] = Rails.root
|
28
|
+
return_struct['root_folder_dir_pwd'] = Dir.pwd
|
29
|
+
|
30
|
+
return_struct['ruby_version'] = RUBY_VERSION
|
31
|
+
return_struct['ruby_pathlevel'] = begin RUBY_PATCHLEVEL; rescue Exception => e; 'EXCEPTION' end
|
32
|
+
return_struct['ruby_release_date'] = begin RUBY_RELEASE_DATE; rescue Exception => e; 'EXCEPTION' end
|
33
|
+
return_struct['ruby_platform'] = begin RUBY_PLATFORM; rescue Exception => e; 'EXCEPTION' end
|
34
|
+
return_struct['root_folder_bis'] = begin RAILS_ROOT; rescue Exception => e; 'EXCEPTION' end
|
35
|
+
rescue Exception => e
|
36
|
+
end
|
37
|
+
begin
|
38
|
+
#return_struct['libraries_loaded_keys'] = Gem.loaded_specs.keys
|
39
|
+
return_struct['libraries_loaded_all'] = Gem.loaded_specs.values.map{|x| "#{x.name} (#{x.version})"}
|
40
|
+
rescue Exception => e
|
41
|
+
end
|
42
|
+
|
43
|
+
return return_struct
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def self.get_env( my_env )
|
50
|
+
env = {}
|
51
|
+
#Excepty::Manager.logga "before each" if EXCEPTY_IN_TESTING_MODE
|
52
|
+
my_env.each do |key, value|
|
53
|
+
#Excepty::Manager.logga "each: #{ key }" if EXCEPTY_IN_TESTING_MODE
|
54
|
+
if env[key].blank?
|
55
|
+
env = get_hash( env, key, value)
|
56
|
+
else
|
57
|
+
begin
|
58
|
+
env["other"] = {} if env["other"].blank?
|
59
|
+
env["other"][key] = value.to_json
|
60
|
+
rescue Exception => e
|
61
|
+
Excepty::Manager.logga "exp" if EXCEPTY_IN_TESTING_MODE
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
return env
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.get_hash( env, key, value )
|
69
|
+
#TODO da testare
|
70
|
+
key_arr = key.split(".")
|
71
|
+
if key_arr.size == 1
|
72
|
+
env["#{key}"] = get_value( value )
|
73
|
+
else
|
74
|
+
#Excepty::Manager.logga "else" if EXCEPTY_IN_TESTING_MODE
|
75
|
+
new_key = key_arr.shift()
|
76
|
+
#Excepty::Manager.logga "new_key: #{new_key} key_arr: #{ key_arr.join(".") }" if EXCEPTY_IN_TESTING_MODE
|
77
|
+
env[new_key] = {} if env[new_key].blank?
|
78
|
+
unless env[new_key].is_a? Hash
|
79
|
+
tmp = env[new_key]
|
80
|
+
env[new_key] = {}
|
81
|
+
env[new_key]["excepty_value_not_hash"] = tmp
|
82
|
+
end
|
83
|
+
env["#{new_key}"] = get_hash( env[new_key], key_arr.join("."), value )
|
84
|
+
end
|
85
|
+
return env
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.get_value( value )
|
89
|
+
begin
|
90
|
+
case value
|
91
|
+
when String, Fixnum, Integer, Bignum
|
92
|
+
return value
|
93
|
+
when NilClass
|
94
|
+
return nil
|
95
|
+
when Array, Hash
|
96
|
+
return value
|
97
|
+
when ApplicationController
|
98
|
+
return value.class.to_s
|
99
|
+
|
100
|
+
#TODO dividere con un altro switch compreso tra try e catch
|
101
|
+
when ActionDispatch::RemoteIp::GetIp
|
102
|
+
return value.to_s
|
103
|
+
when FalseClass, TrueClass
|
104
|
+
return value.to_s
|
105
|
+
#when ActionDispatch::Routing::RouteSet
|
106
|
+
#Excepty::Manager.logga value.router
|
107
|
+
#return value.class.to_s
|
108
|
+
when StringIO
|
109
|
+
if EXCEPTY_IN_TESTING_MODE
|
110
|
+
Excepty::Manager.logga "StringIO"
|
111
|
+
Excepty::Manager.logga value.string
|
112
|
+
Excepty::Manager.logga value.to_json
|
113
|
+
end
|
114
|
+
return value.string
|
115
|
+
else
|
116
|
+
Excepty::Manager.logga "value.class => #{ value.class.to_s }" if EXCEPTY_IN_TESTING_MODE
|
117
|
+
return value.class.to_s
|
118
|
+
end
|
119
|
+
rescue Exception => e
|
120
|
+
Excepty::Manager.logga "EXCEPTY-exception (get_value)" if EXCEPTY_IN_TESTING_MODE
|
121
|
+
return "EXCEPTY-exception (get_value)"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
=begin
|
125
|
+
TODO
|
126
|
+
value.class => StringIO
|
127
|
+
value.class => IO
|
128
|
+
value.class => ActionDispatch::Routing::RouteSet
|
129
|
+
value.class => ActiveSupport::TaggedLogging
|
130
|
+
value.class => Rails::BacktraceCleaner
|
131
|
+
value.class => ActionDispatch::RemoteIp::GetIp
|
132
|
+
value.class => ActionDispatch::Cookies::CookieJar
|
133
|
+
=end
|
134
|
+
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Excepty
|
2
|
+
module Analyzer
|
3
|
+
class Error
|
4
|
+
|
5
|
+
def self.get_struct( exception, env )
|
6
|
+
return_struct = {}
|
7
|
+
|
8
|
+
return_struct["exception_class"] = exception.class.to_s
|
9
|
+
return_struct["message"] = exception.message.to_s
|
10
|
+
return_struct["backtrace"] = exception.backtrace
|
11
|
+
|
12
|
+
return return_struct
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'zlib'
|
2
|
+
require 'base64'
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
5
|
+
require 'uri'
|
6
|
+
#require 'json'
|
7
|
+
|
8
|
+
|
9
|
+
#http://apidock.com/ruby/Net/HTTP
|
10
|
+
|
11
|
+
module Excepty
|
12
|
+
Excepty::Manager.logga "Excepty - Settings - 2" if EXCEPTY_IN_TESTING_MODE
|
13
|
+
class Connector
|
14
|
+
def self.call( url, data = {}, extra_params = nil)
|
15
|
+
arr = []
|
16
|
+
arr.push( "key=#{ Excepty::Settings.config[:key] }" )
|
17
|
+
arr.push( "pv=#{ Excepty::Settings::PROTOCOL_VERSION }" )
|
18
|
+
arr += extra_params.map{ |k,v| "#{k.to_s}=#{v.to_s}" } unless extra_params.blank?
|
19
|
+
url_with_params = url.to_s + "?#{ arr.join("&") }"
|
20
|
+
data_compressed = Zlib::Deflate.deflate( data.to_json, Zlib::BEST_SPEED )
|
21
|
+
data_formatted = Base64.encode64( data_compressed )
|
22
|
+
return start_call( url_with_params, data_formatted )
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def self.start_call( url, data )
|
29
|
+
config = Excepty::Settings.config
|
30
|
+
proxy_settings = Net::HTTP::Proxy( config[:proxy_host], config[:proxy_port], config[:proxy_user], config[:proxy_pass] )
|
31
|
+
conn = proxy_settings.new(config[:server_host], config[:server_port])
|
32
|
+
if !config[:ssl].blank? && ( config[:ssl] == true || config[:ssl].to_s == 'true' )
|
33
|
+
conn.use_ssl = true
|
34
|
+
conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
35
|
+
else
|
36
|
+
conn.use_ssl = false
|
37
|
+
end
|
38
|
+
conn.open_timeout = config[:open_timeout]
|
39
|
+
conn.read_timeout = config[:read_timeout]
|
40
|
+
begin
|
41
|
+
data_to_sent = URI.encode(data)
|
42
|
+
response = conn.post(url, data_to_sent)
|
43
|
+
Excepty::Manager.logga "ricevuto qualcosa" if EXCEPTY_IN_TESTING_MODE
|
44
|
+
case response
|
45
|
+
when Net::HTTPSuccess
|
46
|
+
Excepty::Manager.logga "successofull" if EXCEPTY_IN_TESTING_MODE
|
47
|
+
data = JSON.parse( response.body )
|
48
|
+
return { 'status' => response.code, 'data' => data }
|
49
|
+
else
|
50
|
+
Excepty::Manager.logga "NOOOOOOO successofull" if EXCEPTY_IN_TESTING_MODE
|
51
|
+
return { 'status' => response.code, 'data' => nil }
|
52
|
+
end
|
53
|
+
rescue Exception => e
|
54
|
+
Excepty::Manager.logga "Exceptionnnnnnnn" if EXCEPTY_IN_TESTING_MODE
|
55
|
+
Excepty::Manager.logga e if EXCEPTY_IN_TESTING_MODE
|
56
|
+
return { 'status' => -1, 'data' => nil }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Excepty
|
2
|
+
module ExceptionInterceptor
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.send( :alias_method_chain, :render_exception, :excepty )
|
6
|
+
Excepty::Manager.logga "Excepty - ExceptionInterceptor - included" if EXCEPTY_IN_TESTING_MODE
|
7
|
+
end
|
8
|
+
|
9
|
+
def render_exception_with_excepty( env, exception )
|
10
|
+
Excepty::Manager.logga "Excepty - ExceptionInterceptor - render_exception_with_excepty" if EXCEPTY_IN_TESTING_MODE
|
11
|
+
begin
|
12
|
+
Excepty::Manager.analyse_exception( env, exception )
|
13
|
+
rescue Exception => e
|
14
|
+
Excepty::Manager.logga "EXCEPTION" if EXCEPTY_IN_TESTING_MODE
|
15
|
+
Excepty::Manager.logga e if EXCEPTY_IN_TESTING_MODE
|
16
|
+
Excepty::Manager.logga "e.class" if EXCEPTY_IN_TESTING_MODE
|
17
|
+
Excepty::Manager.logga e.class if EXCEPTY_IN_TESTING_MODE
|
18
|
+
Excepty::Manager.logga "e.message" if EXCEPTY_IN_TESTING_MODE
|
19
|
+
Excepty::Manager.logga e.message if EXCEPTY_IN_TESTING_MODE
|
20
|
+
Excepty::Manager.logga "e.backtrace" if EXCEPTY_IN_TESTING_MODE
|
21
|
+
Excepty::Manager.logga e.backtrace if EXCEPTY_IN_TESTING_MODE
|
22
|
+
end
|
23
|
+
|
24
|
+
render_exception_without_excepty( env, exception )
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Excepty
|
4
|
+
class Manager
|
5
|
+
@@excepty_session_id = nil
|
6
|
+
@@excepty_session_id_bis
|
7
|
+
EXCEPTY_SESSION_FILE_NAME = "tmp/excepty.sid"
|
8
|
+
EXCEPTY_LOGGER_FILE_NAME = "excepty.log"
|
9
|
+
EXCEPTY_DEFAULT_LOG_LEVEL = Logger::INFO
|
10
|
+
|
11
|
+
|
12
|
+
cattr_accessor :logger
|
13
|
+
|
14
|
+
|
15
|
+
self.logger = if defined?(Rails)
|
16
|
+
Rails.logger
|
17
|
+
elsif defined?(EXCEPTY_DEFAULT_LOG_LEVEL)
|
18
|
+
EXCEPTY_DEFAULT_LOG_LEVEL
|
19
|
+
else
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def self.start()
|
25
|
+
self.logger ||= Logger.new( File.join( Rails.root, "log", EXCEPTY_LOGGER_FILE_NAME ) )
|
26
|
+
|
27
|
+
logga( "Manager: - start" ) if EXCEPTY_IN_TESTING_MODE
|
28
|
+
|
29
|
+
app_env = get_env_struct()
|
30
|
+
gem_info = get_gem_info_struct()
|
31
|
+
app_info = get_app_info_struct()
|
32
|
+
|
33
|
+
struct_to_send = { app_env: app_env, gem_info: gem_info, app_info: app_info }
|
34
|
+
begin struct_to_send["time_now"] = Time.now.utc; rescue Exception => e; end
|
35
|
+
#struct_to_send = {}
|
36
|
+
returned_obj = Excepty::Connector.call( "/collector/start", struct_to_send )
|
37
|
+
if returned_obj['status'].to_i == 200
|
38
|
+
@@excepty_session_id = returned_obj['data']['reload_id']
|
39
|
+
@@excepty_session_id_bis = @@excepty_session_id
|
40
|
+
File.delete( EXCEPTY_SESSION_FILE_NAME ) if File::exists?( "file.rb" )
|
41
|
+
file = File.new( EXCEPTY_SESSION_FILE_NAME, "w" )
|
42
|
+
file.puts @@excepty_session_id
|
43
|
+
file.close
|
44
|
+
logga "Dir.tmpdir: #{ Dir.tmpdir }" if EXCEPTY_IN_TESTING_MODE
|
45
|
+
message_response = "Excepty - connetted"
|
46
|
+
logga "@@excepty_session_id: #{@@excepty_session_id}" if EXCEPTY_IN_TESTING_MODE
|
47
|
+
logga "self.excepty_session_id: #{ self.excepty_session_id }" if EXCEPTY_IN_TESTING_MODE
|
48
|
+
else
|
49
|
+
#TODO vedere che fare
|
50
|
+
message_response = "Excepty - NOT connetted"
|
51
|
+
end
|
52
|
+
begin
|
53
|
+
logga(message_response)
|
54
|
+
Rails.logger.info(message_response)
|
55
|
+
rescue Exception => e
|
56
|
+
end
|
57
|
+
logga "@@excepty_session_id: #{@@excepty_session_id}" if EXCEPTY_IN_TESTING_MODE
|
58
|
+
logga "self.excepty_session_id: #{ self.excepty_session_id }" if EXCEPTY_IN_TESTING_MODE
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.analyse_exception( env, exception )
|
62
|
+
logga "Excepty - Exception detected"
|
63
|
+
app_env = get_env_struct( env )
|
64
|
+
gem_info = get_gem_info_struct()
|
65
|
+
exc_info = get_exception_struct( exception, env )
|
66
|
+
struct_to_send = { app_env: app_env, gem_info: gem_info, exc_info: exc_info }
|
67
|
+
begin struct_to_send["time_now"] = Time.now.utc; rescue Exception => e; end
|
68
|
+
#@@excepty_session_id = nil
|
69
|
+
if @@excepty_session_id.blank?
|
70
|
+
logga "allora @@excepty_session_id.blank" if EXCEPTY_IN_TESTING_MODE
|
71
|
+
#self.start()
|
72
|
+
file = File.new( EXCEPTY_SESSION_FILE_NAME, "r" )
|
73
|
+
if file
|
74
|
+
content = file.sysread(20)
|
75
|
+
logga content if EXCEPTY_IN_TESTING_MODE
|
76
|
+
logga "LEGGGGGOOOOO"
|
77
|
+
logga "LEGGGGGOOOOO"
|
78
|
+
logga "LEGGGGGOOOOO"
|
79
|
+
@@excepty_session_id = content.to_i
|
80
|
+
end
|
81
|
+
end
|
82
|
+
logga "@@excepty_session_id: #{@@excepty_session_id}" if EXCEPTY_IN_TESTING_MODE
|
83
|
+
logga "self.excepty_session_id: #{ self.excepty_session_id }" if EXCEPTY_IN_TESTING_MODE
|
84
|
+
begin
|
85
|
+
logga "@@@@excepty_session_id_bis: #{ @@excepty_session_id_bis }" if EXCEPTY_IN_TESTING_MODE
|
86
|
+
rescue Exception => e
|
87
|
+
end
|
88
|
+
begin
|
89
|
+
returned_obj = Excepty::Connector.call( "/collector/error", struct_to_send, { session_id: ( @@excepty_session_id || self.excepty_session_id ) } )
|
90
|
+
logga "Excepty - Exception sent"
|
91
|
+
rescue Exception => e
|
92
|
+
logga "Excepty - Exception NOT sent"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.excepty_session_id
|
97
|
+
@@excepty_session_id
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.logga(text, level = EXCEPTY_DEFAULT_LOG_LEVEL)
|
101
|
+
text = "[Excepty(#{name})] #{text}"
|
102
|
+
logger.add level, "#{Time.now.strftime('%FT%T%z')}: #{text}" if logger
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def self.get_gem_info_struct()
|
109
|
+
gem_info = nil
|
110
|
+
begin
|
111
|
+
gem_info = { name: "excepty", version: Excepty::VERSION, protocol_version: Excepty::Settings::PROTOCOL_VERSION }
|
112
|
+
rescue Exception => e
|
113
|
+
end
|
114
|
+
return gem_info
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.get_app_info_struct()
|
118
|
+
gem_settings = nil
|
119
|
+
begin
|
120
|
+
gem_settings = Excepty::Settings.get_struct
|
121
|
+
rescue Exception => e
|
122
|
+
end
|
123
|
+
return gem_settings
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.get_env_struct( env = nil )
|
127
|
+
app_env = nil
|
128
|
+
begin
|
129
|
+
app_env = Excepty::Analyzer::Enviroment.get_struct( env )
|
130
|
+
rescue Exception => e
|
131
|
+
logga "Exception - Excepty::Analyzer::Enviroment.get_struct" if EXCEPTY_IN_TESTING_MODE
|
132
|
+
end
|
133
|
+
return app_env
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.get_exception_struct( exception, env )
|
137
|
+
exc_info = nil
|
138
|
+
begin
|
139
|
+
exc_info = Excepty::Analyzer::Error.get_struct( exception, env )
|
140
|
+
rescue Exception => e
|
141
|
+
logga "exceptiodfdfs"
|
142
|
+
logga e
|
143
|
+
end
|
144
|
+
return exc_info
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'excepty'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
#http://edgeapi.rubyonrails.org/classes/Rails/Railtie.html
|
5
|
+
|
6
|
+
module Excepty
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
initializer "excepty.middleware" do |app|
|
9
|
+
config_yml_file = File.join( Rails.root, "/config/excepty.yml" )
|
10
|
+
Excepty::Settings.configure_with_file( config_yml_file )
|
11
|
+
Excepty::Manager.logga "EXCEPTY - Maybe We Ara in!!" if EXCEPTY_IN_TESTING_MODE
|
12
|
+
Excepty::Manager.logga "nome #{ Excepty::Settings.config[:app_name] }" if EXCEPTY_IN_TESTING_MODE
|
13
|
+
|
14
|
+
#Excepty::Manager.logga "ANALIZER"
|
15
|
+
#Excepty::Manager.logga Excepty::Analyzer::Enviroment.get_struct
|
16
|
+
#Excepty::Manager.logga Excepty::Analyzer.example
|
17
|
+
|
18
|
+
Excepty::Manager.start()
|
19
|
+
|
20
|
+
if Excepty::Settings.can_catch_exceptions?
|
21
|
+
if defined?(ActionDispatch::DebugExceptions)
|
22
|
+
#rails 3.2.X
|
23
|
+
Excepty::Manager.logga "rails 3.2.X" if EXCEPTY_IN_TESTING_MODE
|
24
|
+
ActionDispatch::DebugExceptions.send(:include,Excepty::ExceptionInterceptor)
|
25
|
+
elsif defined?(ActionDispatch::ShowExceptions)
|
26
|
+
#rails 3.0.X -> 3.1.X
|
27
|
+
Excepty::Manager.logga "rails 3.0.X -> 3.1.X" if EXCEPTY_IN_TESTING_MODE
|
28
|
+
else
|
29
|
+
#rails ~ 2.X
|
30
|
+
Excepty::Manager.logga "rails ~ 2.X" if EXCEPTY_IN_TESTING_MODE
|
31
|
+
end
|
32
|
+
Excepty::Manager.logga "Excepty - exception module actived"
|
33
|
+
else
|
34
|
+
Excepty::Manager.logga "Excepty - exception module NOT actived"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
#http://stackoverflow.com/questions/6233124/where-to-place-access-config-file-in-gem
|
5
|
+
|
6
|
+
Excepty::Manager.logga "Excepty - Settings - 1" if EXCEPTY_IN_TESTING_MODE
|
7
|
+
module Excepty
|
8
|
+
Excepty::Manager.logga "Excepty - Settings - 2" if EXCEPTY_IN_TESTING_MODE
|
9
|
+
class Settings
|
10
|
+
|
11
|
+
PROTOCOL_VERSION = "1"
|
12
|
+
|
13
|
+
Excepty::Manager.logga "Excepty - Settings - 3" if EXCEPTY_IN_TESTING_MODE
|
14
|
+
# Settings defaults
|
15
|
+
@config = {
|
16
|
+
# APP INFO
|
17
|
+
:key => "1A2B3C4D5E",
|
18
|
+
:app_name => "My Application",
|
19
|
+
|
20
|
+
# DEBUGING
|
21
|
+
:enabled => true,
|
22
|
+
:releases_enabled => true,
|
23
|
+
:version_enabled => true,
|
24
|
+
|
25
|
+
#SERVER
|
26
|
+
:server_host => "collector.excepty.com",
|
27
|
+
:server_port => 80,
|
28
|
+
|
29
|
+
# CONNECTION
|
30
|
+
:ssl => false,
|
31
|
+
:proxy_host => nil, #hostname
|
32
|
+
:proxy_port => nil, #8080
|
33
|
+
:proxy_user => nil,
|
34
|
+
:proxy_pass => nil,
|
35
|
+
|
36
|
+
:open_timeout => 4,
|
37
|
+
:read_timeout => 7
|
38
|
+
}
|
39
|
+
@valid_config_keys = @config.keys
|
40
|
+
|
41
|
+
# Configure Settings through yaml file
|
42
|
+
def self.configure_with_file( config_yml_file )
|
43
|
+
#begin
|
44
|
+
if config_yml_file.blank? || !File.file?( config_yml_file )
|
45
|
+
#TODO what can I do or say?
|
46
|
+
Excepty::Manager.logga "BLANCO" if EXCEPTY_IN_TESTING_MODE
|
47
|
+
return
|
48
|
+
end
|
49
|
+
|
50
|
+
Excepty::Manager.logga "Excepty - Settings - 5" if EXCEPTY_IN_TESTING_MODE
|
51
|
+
#begin
|
52
|
+
enviroment = ENV['RAILS_ENV'] || ENV['RACK_ENV']
|
53
|
+
config_yml = YAML::load( IO.read( config_yml_file ) )
|
54
|
+
#config_yml = YAML.load( ERB.new( File.new( config_yml_file ).read ).result )
|
55
|
+
config_yml_by_env = config_yml[enviroment] || {}
|
56
|
+
begin
|
57
|
+
rescue Errno::ENOENT
|
58
|
+
log(:warning, "YAML configuration file couldn't be found. Using defaults."); return
|
59
|
+
rescue Psych::SyntaxError
|
60
|
+
log(:warning, "YAML configuration file contains invalid syntax. Using defaults."); return
|
61
|
+
end
|
62
|
+
|
63
|
+
#begin
|
64
|
+
#@config.each { |k,v| @config[k.to_sym] = config_yml_by_env[k.to_sym] || config_yml[k.to_sym] || v if @valid_config_keys.include? k.to_sym }
|
65
|
+
@config.each do |k,v|
|
66
|
+
@config[k.to_sym] = config_yml_by_env[k.to_s] || config_yml[k.to_s] || v if @valid_config_keys.include? k.to_sym
|
67
|
+
end
|
68
|
+
Excepty::Manager.logga "@config: #{@config.to_json}" if EXCEPTY_IN_TESTING_MODE
|
69
|
+
begin # <= lele
|
70
|
+
rescue Exception => e
|
71
|
+
log(:warning, "YAML Settings error in load yml file."); return
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.config
|
76
|
+
@config
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.can_catch_exceptions?
|
80
|
+
return true if EXCEPTY_IN_TESTING_MODE
|
81
|
+
return @config['enabled'] || true
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.get_struct
|
85
|
+
obj = {}
|
86
|
+
begin obj['app_name'] = @config[:app_name]; rescue Exception => e; end
|
87
|
+
begin obj['key'] = @config[:key]; rescue Exception => e; end
|
88
|
+
begin obj['webapp_name_by_env'] = ENV["APP_NAME"]; rescue Exception => e; end
|
89
|
+
begin obj['webapp_name'] = Rails.application.class.parent_name; rescue Exception => e; end
|
90
|
+
begin obj['webapp_name_class'] = Rails.application.class.to_s; rescue Exception => e; end
|
91
|
+
return obj
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: excepty
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Excepty
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ! 'T ODO: Write a gem description'
|
14
|
+
email:
|
15
|
+
- gem@excepty.com
|
16
|
+
executables:
|
17
|
+
- excepty
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/excepty
|
22
|
+
- excepty.gemspec
|
23
|
+
- lib/excepty.rb
|
24
|
+
- lib/excepty/analyzer.rb
|
25
|
+
- lib/excepty/analyzers/enviroment.rb
|
26
|
+
- lib/excepty/analyzers/error.rb
|
27
|
+
- lib/excepty/analyzers/repositoy.rb
|
28
|
+
- lib/excepty/analyzers/request.rb
|
29
|
+
- lib/excepty/connector.rb
|
30
|
+
- lib/excepty/exception_interceptor.rb
|
31
|
+
- lib/excepty/manager.rb
|
32
|
+
- lib/excepty/railtie.rb
|
33
|
+
- lib/excepty/settings.rb
|
34
|
+
- lib/excepty/version.rb
|
35
|
+
homepage: http://www.excepty.com/
|
36
|
+
licenses: []
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.3.0
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: ! 'T ODO: Write a gem summary'
|
58
|
+
test_files: []
|