wildsight 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 147f74d56e7e8099f4fa924d7ddd017be25ffbaf
4
+ data.tar.gz: 2cbc9897f43db2d50fe351f96c7dcc9408723870
5
+ SHA512:
6
+ metadata.gz: 42d90f982cf2cf11779edb2f4499ba3594dcb12b4f07a1a1093dddcbe2b3378a3207180d6bbf22588c61fc242aa5f18890291effce238a0c8e2a023911ddaebc
7
+ data.tar.gz: 8ca7757976aa611b11d06a3056cd00665e08166b986d32df988773c4797e1d48ae204e96eaf533d3809344a4679c5a1e78aa0db5713d4639feb7427c212d2d76
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ *.iml
12
+ .rakeTasks
13
+ .idea
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at marek@jelen.biz. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Marek Jelen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Wildsight::Ruby
2
+
3
+ Ruby instrumentation for the Wildsight monitoring tool.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'wildsight'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install wildsight
20
+
21
+ ## Usage
22
+
23
+ Create config/wildsight.yml file
24
+
25
+ ```
26
+ url: https://some_path
27
+ key: access_key
28
+ ```
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://gitlab.com/wildsight/ruby-instrumentation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
44
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wildsight"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,97 @@
1
+ require 'securerandom'
2
+
3
+ require 'wildsight/agent/tools'
4
+ require 'wildsight/agent/config'
5
+ require 'wildsight/agent/logger'
6
+
7
+ module Wildsight
8
+ module Agent
9
+
10
+ def self.default
11
+ find
12
+ end
13
+
14
+ def self.find(name = 'default')
15
+ @agents ||= {}
16
+ @agents[name] ||= Wildsight::Agent::Agent.new
17
+ end
18
+
19
+ class Agent
20
+
21
+ include Wildsight::Tools
22
+
23
+ def initialize(config = (Wildsight::Agent::Config.load))
24
+ @config = config
25
+ setup
26
+ end
27
+
28
+ def logger
29
+ @logger
30
+ end
31
+
32
+ def context(name = nil)
33
+ name ||= SecureRandom.uuid
34
+ name = name.to_s
35
+ unless @contexts[name]
36
+ @contexts[name] = Wildsight::Context::Context.new(name, self)
37
+ self.logger.log(:debug) { "New context registered #{name}"}
38
+ end
39
+ return @contexts[name]
40
+ end
41
+
42
+ def unknown_context
43
+ context('unknown_context')
44
+ end
45
+
46
+ def unregister_context(context)
47
+ context = context.name if context.kind_of?(Wildsight::Context::Context)
48
+ name = context.to_s
49
+ self.logger.log(:debug) { "Context unregistered #{name}"}
50
+ @contexts.delete(name)
51
+ end
52
+
53
+ def event(event)
54
+ @events << event
55
+ if @events.size > @config['agent']['threshold']
56
+ self.logger.log(:debug) { 'Uploading collected data' }
57
+ upload
58
+ end
59
+ end
60
+
61
+ def upload
62
+ payload, @events = @events, []
63
+ puts payload.inspect
64
+ @transport.send(payload)
65
+ end
66
+
67
+ private
68
+
69
+ def setup
70
+ @logger = Wildsight::Agent::Logger.new(@config)
71
+ @logger.log(:debug) { 'Logger initialized' }
72
+
73
+ @events = []
74
+ @contexts = {}
75
+
76
+ @transport = Wildsight::Transport.detect.new(self, @config)
77
+ thread
78
+ end
79
+
80
+ def thread
81
+ @thread ||= Thread.new {
82
+ while true
83
+ begin
84
+ upload
85
+ sleep(@config['agent']['timeout'])
86
+ rescue Exception => e
87
+ puts e.message
88
+ puts e.backtrace
89
+ end
90
+ end
91
+ }.run
92
+ end
93
+
94
+ end
95
+
96
+ end
97
+ end
@@ -0,0 +1,35 @@
1
+ require 'yaml'
2
+
3
+ module Wildsight
4
+ module Agent
5
+
6
+ class Config
7
+
8
+ def self.load(file = (ENV['WILDSIGHT_CONFIG_FILE'] || 'config/wildsight.yml'))
9
+ options = YAML.load(File.read(File.expand_path('../config.yml', __FILE__)))
10
+ options = options.merge(file) if file.kind_of?(Hash)
11
+ if file.kind_of?(String) && File.exist?(file)
12
+ options = options.merge(YAML.load(File.read(file)))
13
+ end
14
+ Config.new(options)
15
+ end
16
+
17
+ def initialize(values = {})
18
+ @values = values
19
+ end
20
+
21
+ def method_missing(name, *args)
22
+ name = name.to_s
23
+ self[name]
24
+ end
25
+
26
+ def [](name)
27
+ name = name.to_s
28
+ @values[name] = Config.new(@values[name]) if @values[name].kind_of?(Hash)
29
+ @values[name]
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ agent:
2
+ timeout: 10
3
+ threshold: 100
4
+
5
+ transport:
6
+ url: ~
7
+ key: ~
8
+
9
+ logger:
10
+ stdout: false
11
+ stderr: false
12
+ file: ~
13
+ level: error
@@ -0,0 +1,47 @@
1
+ require 'logger'
2
+
3
+ module Wildsight
4
+ module Agent
5
+
6
+ class Logger
7
+
8
+ TABLE = {
9
+ :debug => ::Logger::DEBUG,
10
+ :info => ::Logger::INFO,
11
+ :warn => ::Logger::WARN,
12
+ :error => ::Logger::ERROR,
13
+ :fatal => ::Logger::FATAL,
14
+ 'debug' => ::Logger::DEBUG,
15
+ 'info' => ::Logger::INFO,
16
+ 'warn' => ::Logger::WARN,
17
+ 'error' => ::Logger::ERROR,
18
+ 'fatal' => ::Logger::FATAL
19
+ }
20
+
21
+ def initialize(config)
22
+ @config = config
23
+ @loggers = []
24
+
25
+ if @config['logger']['stdout']
26
+ @loggers << ::Logger.new(STDOUT)
27
+ end
28
+
29
+ if @config['logger']['stderr']
30
+ @loggers << ::Logger.new(STDERR)
31
+ end
32
+
33
+ if @config['logger']['file'] && @config['logger']['file'].kind_of?(String)
34
+ @loggers << ::Logger.new(@config['logger']['file'])
35
+ end
36
+
37
+ @loggers.each { |logger| logger.level = TABLE[@config['logger']['level']] }
38
+ end
39
+
40
+ def log(severity, message = nil, &block)
41
+ @loggers.each { |logger| logger.add(TABLE[severity] || ::Logger::UNKNOWN, nil, message, &block) }
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,21 @@
1
+ module Wildsight
2
+ module Tools
3
+
4
+ def extract_exception(exception)
5
+ Tools.extract_exception(exception)
6
+ end
7
+
8
+ def self.extract_exception(exception)
9
+ result = {
10
+ :message => exception.message,
11
+ :backtrace => exception.backtrace,
12
+ :name => exception.class.name
13
+ }
14
+ if exception.cause
15
+ result[:cause] = extract_exception(exception.cause)
16
+ end
17
+ return result
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,59 @@
1
+ require 'wildsight/context/rack'
2
+ require 'wildsight/context/logger'
3
+ require 'wildsight/context/sql'
4
+
5
+ module Wildsight
6
+ module Context
7
+
8
+ def self.detect(thread = Thread.current)
9
+ thread.thread_variable_get('wildsight.context') || Wildsight::Agent.default.unknown_context
10
+ end
11
+
12
+ class Context
13
+
14
+ include Wildsight::Context::Rack
15
+ include Wildsight::Context::Logs
16
+ include Wildsight::Context::Sql
17
+
18
+ attr_reader :name
19
+
20
+ def initialize(name, agent)
21
+ @name = name
22
+ @agent = agent
23
+ @data = {}
24
+ end
25
+
26
+ def event(name, data)
27
+ @agent.event({ :context => { :id => @name }, name => data })
28
+ end
29
+
30
+ def unregister
31
+ @agent.unregister_context(self)
32
+ end
33
+
34
+ def bind_thread(thread = Thread.current)
35
+ thread.thread_variable_set('wildsight.context', self)
36
+ end
37
+
38
+ def release_thread(thread = Thread.current)
39
+ thread.thread_variable_set('wildsight.context', nil)
40
+ end
41
+
42
+ def request
43
+ @data[:http_request] ||= {}
44
+ end
45
+
46
+ def self.thread_context_id(thread=Thread.current)
47
+ thread.thread_variable_get('wildsight.context')
48
+ end
49
+
50
+ def extract_exception(exception)
51
+ data = {:occurred => DateTime.now, :message => exception.message, :name => exception.class.name, :backtrace => exception.backtrace}
52
+ data[:cause] = extract_exception(exception.cause) if exception.cause
53
+ return data
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,44 @@
1
+ require 'logger'
2
+
3
+ module Wildsight
4
+ module Context
5
+
6
+ module Logs
7
+
8
+ def report_log(log)
9
+ event(:log, log)
10
+ end
11
+
12
+ end
13
+
14
+ class Logger < ::Logger
15
+
16
+ def initialize(context = nil)
17
+ @context = context
18
+ super(self)
19
+ self.formatter = self
20
+ end
21
+
22
+ def call(severity, time, progname, msg)
23
+ payload = {
24
+ :severity => severity,
25
+ :occurred => time,
26
+ :facility => progname,
27
+ :message => msg.to_s.strip
28
+ }
29
+ context = @context
30
+ context = Wildsight::Context.detect unless context
31
+ context.report_log(payload)
32
+ return nil
33
+ end
34
+
35
+ def write(message)
36
+ end
37
+
38
+ def close
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,68 @@
1
+ require 'pp'
2
+
3
+ module Wildsight
4
+ module Context
5
+
6
+ module Rack
7
+
8
+ RACK_ENV_KEY = 'wildsight.context'
9
+
10
+ INCLUDE_KEYS = ['SCRIPT_NAME', 'QUERY_STRING', 'PATH_INFO', 'REMOTE_ADDR']
11
+ EXCLUDE_KEYS = ['HTTP_COOKIE']
12
+
13
+ def self.detect_context(env)
14
+ env[RACK_ENV_KEY] || Wildsight::Context.detect
15
+ end
16
+
17
+ def report_rack_request(env)
18
+ @started = DateTime.now
19
+ env[RACK_ENV_KEY] = self
20
+
21
+ self.request[:occurred] = DateTime.now
22
+ self.request[:request_headers] = {}
23
+ self.request[:metrics] ||= {}
24
+
25
+ self.request[:request_target] = env['SCRIPT_NAME'].to_s + env['PATH_INFO'].to_s
26
+
27
+ env.each_pair do |key,value|
28
+ name = key.to_s
29
+ self.request[:request_headers][key] = value if INCLUDE_KEYS.include?(name)
30
+ self.request[:request_headers][key] = value if name.start_with?('HTTP_')
31
+ self.request[:request_headers][key] = value if name.start_with?('REQUEST_')
32
+ self.request[:request_headers][key] = value if name.start_with?('SERVER_')
33
+ end
34
+
35
+ EXCLUDE_KEYS.each { |key| self.request[:request_headers].delete(key) }
36
+
37
+ if !self.request[:session_id] && !env['rack.session'].nil? && env['rack.session'].respond_to?(:id)
38
+ self.request[:session_id] = env['rack.session'].id
39
+ end
40
+ rescue => e
41
+ @agent.logger.log(:error, e)
42
+ end
43
+
44
+ def report_rack_response(env, response = nil)
45
+ @finished = DateTime.now
46
+ env.delete(RACK_ENV_KEY)
47
+
48
+ if response
49
+ self.request[:response_code] = response[0]
50
+ self.request[:response_headers] = response[1]
51
+ end
52
+
53
+ self.request[:metrics][:request] = (@finished.to_f - @started.to_f) * 1000
54
+
55
+ exception = env['rack.exception'] || env['action_dispatch.exception'] || env['sinatra.error']
56
+
57
+ if exception
58
+ event(:exception, extract_exception(exception))
59
+ end
60
+ event(:http_request, self.request)
61
+ rescue => e
62
+ @agent.logger.log(:error, e)
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,13 @@
1
+ module Wildsight
2
+ module Context
3
+
4
+ module Sql
5
+
6
+ def report_sql_query(event)
7
+ event(:sql, event)
8
+ end
9
+
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module Wildsight
2
+ module Metrics
3
+
4
+ class Counter
5
+
6
+ def initialize(value = 0)
7
+ set(value)
8
+ end
9
+
10
+ def inc(value = 1)
11
+ @value += value
12
+ end
13
+
14
+ def set(value = 0)
15
+ @value = value
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ module Wildsight
2
+ module Metrics
3
+
4
+ class Gauge
5
+
6
+ def initialize(value = 0)
7
+ set(value)
8
+ end
9
+
10
+ def inc(value = 1)
11
+ @value += value
12
+ end
13
+
14
+ def dec(value = 1)
15
+ @value -= value
16
+ end
17
+
18
+ def set(value = 0)
19
+ @value = value
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ require 'wildsight/metrics/counter'
2
+ require 'wildsight/metrics/gauge'
3
+ require 'wildsight/metrics/statistics'
4
+
5
+ module Wildsight
6
+ module Metrics
7
+
8
+ class Metrics
9
+
10
+ def initialize
11
+ @metrics = {}
12
+ end
13
+
14
+ def counter(name)
15
+ metric(name, ::Wildsight::Metrics::Counter)
16
+ end
17
+
18
+ def gauge(name)
19
+ metric(name, ::Wildsight::Metrics::Gauge)
20
+ end
21
+
22
+ def statistics(name)
23
+ metric(name, ::Wildsight::Metrics::Statistics)
24
+ end
25
+
26
+ def histogram(name)
27
+ metric(name, ::Wildsight::Metrics::Histogram)
28
+ end
29
+
30
+ def metric(name, clazz)
31
+ @metrics[name] ||= clazz.new
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,30 @@
1
+ module Wildsight
2
+ module Metrics
3
+
4
+ class Statistics
5
+
6
+ def initialize(values = [])
7
+ reset(values)
8
+ end
9
+
10
+ def add(value = 0)
11
+ @values[:max] = values if @values[:max] == nil || @values[:max] < values
12
+ @values[:min] = values if @values[:min] == nil || @values[:min] > values
13
+ @values[:sum] += value
14
+ @values[:cnt] += 1
15
+ end
16
+
17
+ def reset(values = [])
18
+ @values = {
19
+ max: nil,
20
+ min: nil,
21
+ sum: 0,
22
+ cnt: 0
23
+ }
24
+ values.each { |value| add(value) }
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ module Wildsight
2
+ module Rack
3
+
4
+ class Middleware
5
+
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ MiddlewareContext.new(@app).call(env)
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ module Wildsight
2
+ module Rack
3
+
4
+ class MiddlewareContext
5
+
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ @context = Wildsight::Agent.default.context
12
+ @context.bind_thread
13
+ @context.report_rack_request(env)
14
+ response = @app.call(env)
15
+ rescue Exception => exception
16
+ env['rack.exception'] = exception
17
+ raise exception
18
+ ensure
19
+ @context.report_rack_response(env, response)
20
+ @context.release_thread
21
+ @context.unregister
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ module Wildsight
2
+ module Rack
3
+
4
+ class MiddlewareException
5
+
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ @app.call(env)
12
+ rescue Exception => e
13
+ env['rack.exception'] ||= e
14
+ raise e
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ module Wildsight
2
+ module Rails
3
+ module ActionController
4
+
5
+ def append_info_to_payload(payload)
6
+ super
7
+ payload[:request] = request
8
+ payload[:controller_class] = self.class.name
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Wildsight
2
+ module Rails
3
+ module ActiveRecord
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,74 @@
1
+ module Wildsight
2
+ module Rails
3
+ class Railtie < ::Rails::Railtie
4
+
5
+ initializer('wildsight.middleware') do |app|
6
+ app.config.middleware.insert_before('ActionDispatch::Executor', Wildsight::Rack::Middleware)
7
+ app.config.middleware.insert_after('ActionDispatch::DebugExceptions', Wildsight::Rack::MiddlewareException)
8
+ end
9
+
10
+ initializer('wildsight.rails.logger') do |app|
11
+ ::Rails.logger.extend(ActiveSupport::Logger.broadcast(Wildsight::Context::Logger.new))
12
+ end
13
+
14
+ initializer('wildsight.action_controller.extensions') do |app|
15
+ ActiveSupport.on_load(:action_controller) do
16
+ include Wildsight::Rails::ActionController
17
+ end
18
+ end
19
+
20
+ initializer('wildsight.action_controller.metrics') do |app|
21
+ ActiveSupport::Notifications.subscribe('process_action.action_controller') do |*args|
22
+ request = args[4][:request]
23
+
24
+ context = Wildsight::Context::Rack.detect_context(request.env)
25
+
26
+ context.request[:request_target] = args[4][:controller_class] + '#' + request.params['action']
27
+
28
+ context.request[:metrics][:rails] = (args[2] - args[1]) * 1000
29
+ context.request[:metrics][:view] = args[4][:view_runtime] || 0
30
+ context.request[:metrics][:database] = args[4][:db_runtime] || 0
31
+
32
+ context.request[:method] = args[4][:method]
33
+ context.request[:path] = args[4][:path]
34
+ context.request[:params] = args[4][:params]
35
+
36
+ context.request[:response_code] = args[4][:status]
37
+
38
+ context.request[:session_id] = request.session.id
39
+ context.request[:session] = request.session.to_hash
40
+
41
+ context.request[:url] = request.original_url
42
+ context.request[:protocol] = request.protocol
43
+ context.request[:host] = request.host_with_port
44
+
45
+ context.request[:remote_ip] = request.remote_ip
46
+ end
47
+ end
48
+
49
+ initializer('wildsight.active_record.extensions') do |app|
50
+ ActiveSupport.on_load(:active_record) do
51
+ include Wildsight::Rails::ActiveRecord
52
+ end
53
+ end
54
+
55
+ initializer('wildsight.active_record.metrics') do |app|
56
+ ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
57
+ event = {
58
+ :name => args[4][:name],
59
+ :statement => args[4][:statement_name],
60
+ :binds => args[4][:binds],
61
+ :query => args[4][:sql],
62
+ :connection => args[4][:connection_id],
63
+ :occurred => args[1],
64
+ :duration => (args[2] - args[1]) * 1000
65
+ }
66
+ context = Wildsight::Context.detect
67
+ context.report_sql_query(event)
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,30 @@
1
+ module Wildsight
2
+ module Transport
3
+
4
+ class FaradayTransport
5
+
6
+ def initialize(agent, config)
7
+ @agent = agent
8
+ @config = config
9
+ @connection = Faraday.new(:url => @config['transport']['url']) do |faraday|
10
+ faraday.request(:url_encoded)
11
+ faraday.adapter(Faraday.default_adapter)
12
+ end
13
+ @uri = File.join('ingest', @config['transport']['key'])
14
+ end
15
+
16
+ def send(payload)
17
+ begin
18
+ if payload != nil && payload.size > 0
19
+ @agent.logger.log(:debug) { @connection.post(@uri, {'payload' => MultiJson.dump(payload)}).inspect }
20
+ @agent.logger.log(:debug) { 'Uploaded' }
21
+ end
22
+ rescue Exception => e
23
+ @agent.logger.log(:error) { e }
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ require 'net/http'
2
+
3
+ module Wildsight
4
+ module Transport
5
+
6
+ class NetHttpTransport
7
+
8
+ def initialize(agent, config)
9
+ @agent = agent
10
+ @config = config
11
+ @uri = URI(File.join(@config['transport']['url'], 'ingest', @config['transport']['key']))
12
+ end
13
+
14
+ def send(payload)
15
+ begin
16
+ if payload != nil && payload.size > 0
17
+ @agent.logger.log(:debug) { Net::HTTP.post_form(@uri, 'payload' => MultiJson.dump(payload)).inspect }
18
+ end
19
+ rescue Exception => e
20
+ @agent.logger.log(:error) { e }
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ require 'multi_json'
2
+
3
+ module Wildsight
4
+ module Transport
5
+
6
+ def self.detect
7
+ return @transport if @transport
8
+ begin
9
+ require 'faraday'
10
+ require 'wildsight/transport/faraday'
11
+ return @transport = Wildsight::Transport::FaradayTransport
12
+ rescue => e
13
+ end
14
+
15
+ require 'wildsight/transport/net_http'
16
+ return @transport = Wildsight::Transport::NetHttpTransport
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Wildsight
2
+ VERSION = '0.1.8'
3
+ end
data/lib/wildsight.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'wildsight_custom'
2
+
3
+ Wildsight::Agent.default
@@ -0,0 +1,18 @@
1
+ require 'wildsight/version'
2
+
3
+ require 'wildsight/transport/transport'
4
+ require 'wildsight/metrics/metrics'
5
+ require 'wildsight/context/context'
6
+ require 'wildsight/agent/agent'
7
+
8
+ if defined?(Rack)
9
+ require 'wildsight/rack/middleware_context'
10
+ require 'wildsight/rack/middleware_exception'
11
+ require 'wildsight/rack/middleware'
12
+ end
13
+
14
+ if defined?(Rails)
15
+ require 'wildsight/rails/action_controller'
16
+ require 'wildsight/rails/active_record'
17
+ require 'wildsight/rails/railtie'
18
+ end
data/wildsight.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wildsight/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'wildsight'
8
+ spec.version = Wildsight::VERSION
9
+ spec.authors = ['Marek Jelen']
10
+ spec.email = ['marek@jelen.biz']
11
+
12
+ spec.summary = 'Multi language/framework/platform error and statistics monitor'
13
+ spec.description = 'Get complete insight into your applications across technologies'
14
+ spec.homepage = 'https://gitlab.com/wildsight/ruby-instrumentation'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'multi_json'
23
+
24
+ spec.add_development_dependency 'rails', '5.0.0.rc1'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.11'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'minitest', '~> 5.0'
29
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wildsight
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.8
5
+ platform: ruby
6
+ authors:
7
+ - Marek Jelen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 5.0.0.rc1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 5.0.0.rc1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description: Get complete insight into your applications across technologies
84
+ email:
85
+ - marek@jelen.biz
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - CODE_OF_CONDUCT.md
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/wildsight.rb
99
+ - lib/wildsight/agent/agent.rb
100
+ - lib/wildsight/agent/config.rb
101
+ - lib/wildsight/agent/config.yml
102
+ - lib/wildsight/agent/logger.rb
103
+ - lib/wildsight/agent/tools.rb
104
+ - lib/wildsight/context/context.rb
105
+ - lib/wildsight/context/logger.rb
106
+ - lib/wildsight/context/rack.rb
107
+ - lib/wildsight/context/sql.rb
108
+ - lib/wildsight/metrics/counter.rb
109
+ - lib/wildsight/metrics/gauge.rb
110
+ - lib/wildsight/metrics/metrics.rb
111
+ - lib/wildsight/metrics/statistics.rb
112
+ - lib/wildsight/rack/middleware.rb
113
+ - lib/wildsight/rack/middleware_context.rb
114
+ - lib/wildsight/rack/middleware_exception.rb
115
+ - lib/wildsight/rails/action_controller.rb
116
+ - lib/wildsight/rails/active_record.rb
117
+ - lib/wildsight/rails/railtie.rb
118
+ - lib/wildsight/transport/faraday.rb
119
+ - lib/wildsight/transport/net_http.rb
120
+ - lib/wildsight/transport/transport.rb
121
+ - lib/wildsight/version.rb
122
+ - lib/wildsight_custom.rb
123
+ - wildsight.gemspec
124
+ homepage: https://gitlab.com/wildsight/ruby-instrumentation
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.5.1
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Multi language/framework/platform error and statistics monitor
148
+ test_files: []
149
+ has_rdoc: