tracebin 0.0.7
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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +42 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dump.rdb +0 -0
- data/lib/vizsla/agent.rb +87 -0
- data/lib/vizsla/background_job_instrumentation/active_job.rb +14 -0
- data/lib/vizsla/background_job_instrumentation/resque.rb +37 -0
- data/lib/vizsla/background_job_instrumentation/sidekiq.rb +19 -0
- data/lib/vizsla/background_job_instrumentation.rb +34 -0
- data/lib/vizsla/background_timer.rb +9 -0
- data/lib/vizsla/config.rb +21 -0
- data/lib/vizsla/events.rb +67 -0
- data/lib/vizsla/health_monitor.rb +24 -0
- data/lib/vizsla/helpers.rb +7 -0
- data/lib/vizsla/logger.rb +55 -0
- data/lib/vizsla/middleware.rb +51 -0
- data/lib/vizsla/patches/action_view_layout.rb +34 -0
- data/lib/vizsla/patches/mysql2.rb +22 -0
- data/lib/vizsla/patches/postgres.rb +42 -0
- data/lib/vizsla/patches/sidekiq_health.rb +27 -0
- data/lib/vizsla/patches/sinatra.rb +21 -0
- data/lib/vizsla/patches.rb +44 -0
- data/lib/vizsla/puppet_master.rb +17 -0
- data/lib/vizsla/recorder.rb +43 -0
- data/lib/vizsla/reporter.rb +74 -0
- data/lib/vizsla/storage.rb +30 -0
- data/lib/vizsla/subscribers.rb +172 -0
- data/lib/vizsla/system_health_sample.rb +187 -0
- data/lib/vizsla/timer.rb +60 -0
- data/lib/vizsla/version.rb +3 -0
- data/lib/vizsla/worker_process_monitor.rb +25 -0
- data/lib/vizsla.rb +17 -0
- data/vizsla.gemspec +29 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 17c8dde3ccebe028e63049fd73713fb0ff8e3643
|
4
|
+
data.tar.gz: eb14462756f92fb25fd81ab7968eeef96e9eac58
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a6b4a64ce5c7bae23d18a31e92f3602cfa0681358316a7095f1f67c818c86168c9e2f0e5eb3c8403313a88273a8d09c485c9a2b33543b467ebc8369057a207b
|
7
|
+
data.tar.gz: 26a297bb4a17c538ba4424fbce1f7e74b26df173d663e17ce74c322954241a19e29f3307d136f283c3d8cf1d0f40590e66e55f94acaed83ffe193c6cdcb10c32
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at tyguillen@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Tyler Guillen
|
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,42 @@
|
|
1
|
+
# Vizsla
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'vizsla'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install vizsla
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
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).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/aastronautss/vizsla. 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.
|
32
|
+
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
37
|
+
|
38
|
+
## Notes
|
39
|
+
|
40
|
+
### Storage and Reporting Strategy
|
41
|
+
|
42
|
+
Multiple threads are storing information in a thread-safe array. Every minute or so, we need to access that array, empty it, and send it to our service. If that data transfer fails (i.e., the response is not successful), that payload is simply re-added to the array and will be transmitted with the next try.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "vizsla"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/dump.rdb
ADDED
Binary file
|
data/lib/vizsla/agent.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
require 'vizsla/subscribers'
|
4
|
+
require 'vizsla/health_monitor'
|
5
|
+
require 'vizsla/worker_process_monitor'
|
6
|
+
require 'vizsla/storage'
|
7
|
+
require 'vizsla/reporter'
|
8
|
+
|
9
|
+
module Vizsla
|
10
|
+
module Agent
|
11
|
+
class << self
|
12
|
+
attr_accessor :config, :storage, :logger
|
13
|
+
|
14
|
+
def start!
|
15
|
+
logger.info "Starting Vizsla agent..."
|
16
|
+
|
17
|
+
@subscribers = Subscribers.new
|
18
|
+
@health_monitor = HealthMonitor.start
|
19
|
+
@worker_process_monitor = WorkerProcessMonitor.start
|
20
|
+
|
21
|
+
@reporter = Reporter.new(storage, config, logger)
|
22
|
+
|
23
|
+
@reporter.start!
|
24
|
+
|
25
|
+
logger.info "Vizsla agent started!"
|
26
|
+
end
|
27
|
+
|
28
|
+
def stop!
|
29
|
+
logger.info "Shutting down Vizsla agent..."
|
30
|
+
|
31
|
+
@health_monitor.stop!
|
32
|
+
@worker_process_monitor.stop!
|
33
|
+
@reporter.stop!
|
34
|
+
|
35
|
+
@started = false
|
36
|
+
|
37
|
+
logger.info "Vizsla agent stopped!"
|
38
|
+
end
|
39
|
+
|
40
|
+
def started?
|
41
|
+
@started
|
42
|
+
end
|
43
|
+
|
44
|
+
def init_logger
|
45
|
+
if defined? ::Rails
|
46
|
+
@logger = ::Rails.logger
|
47
|
+
else
|
48
|
+
@logger ||= Logger.new(STDOUT)
|
49
|
+
@logger.level = log_level
|
50
|
+
end
|
51
|
+
|
52
|
+
@logger
|
53
|
+
end
|
54
|
+
|
55
|
+
def log_level
|
56
|
+
case config.log_level.downcase
|
57
|
+
when 'debug' then Logger::DEBUG
|
58
|
+
when 'info' then Logger::INFO
|
59
|
+
when 'warn' then Logger::WARN
|
60
|
+
when 'error' then Logger::ERROR
|
61
|
+
when 'fatal' then Logger::FATAL
|
62
|
+
else Logger::INFO
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.logger
|
68
|
+
@logger || init_logger
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.storage
|
72
|
+
@storage ||= ::Vizsla::Storage.new
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.config
|
76
|
+
@config ||= Config.new
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.reset
|
80
|
+
@config = Config.new
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.configure
|
84
|
+
yield config
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'vizsla/background_timer'
|
2
|
+
require 'vizsla/puppet_master'
|
3
|
+
|
4
|
+
if defined? ::ActiveJob::Base
|
5
|
+
::ActiveJob::Base.around_perform do |job, block|
|
6
|
+
@vizsla_timer = ::Vizsla::BackgroundTimer.new job.class.name.split('::').last
|
7
|
+
@vizsla_timer.start!
|
8
|
+
|
9
|
+
block.call
|
10
|
+
|
11
|
+
@vizsla_timer.stop!
|
12
|
+
::Vizsla::PuppetMaster.new(@vizsla_timer).process
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'vizsla/background_timer'
|
2
|
+
require 'vizsla/puppet_master'
|
3
|
+
|
4
|
+
module Resque
|
5
|
+
module Plugins
|
6
|
+
module VizslaInstrumentation
|
7
|
+
module Job
|
8
|
+
def before_perform_with_vizsla(*args)
|
9
|
+
@vizsla_timer = ::Vizsla::BackgroundTimer.new
|
10
|
+
@vizsla_timer.start!
|
11
|
+
|
12
|
+
yield *args if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
def after_perform_with_vizsla(*args)
|
16
|
+
@vizsla_timer.stop!
|
17
|
+
::Vizsla::PuppetMaster.new(@vizsla_timer, logger: Resque.logger).process
|
18
|
+
|
19
|
+
yield *args if block_given?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Vizsla
|
27
|
+
module BackgroundJobInstrumentation
|
28
|
+
module ResqueInstrumentationInstaller
|
29
|
+
def payload_class
|
30
|
+
klass = super
|
31
|
+
klass.instance_eval do
|
32
|
+
extend ::Resque::Plugins::VizslaInstrumentation::Job
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'vizsla/background_timer'
|
2
|
+
require 'vizsla/puppet_master'
|
3
|
+
|
4
|
+
module Vizsla
|
5
|
+
module BackgroundJobInstrumentation
|
6
|
+
class Sidekiq
|
7
|
+
def call(worker, msg, queue, *args)
|
8
|
+
timer = BackgroundTimer.new worker.class.name.split('::').last
|
9
|
+
timer.start!
|
10
|
+
|
11
|
+
yield
|
12
|
+
|
13
|
+
timer.stop!
|
14
|
+
|
15
|
+
PuppetMaster.new(timer, logger: worker.logger).process
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Vizsla
|
2
|
+
module BackgroundJobInstrumentation
|
3
|
+
def self.install(inst_name)
|
4
|
+
self.send inst_name
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def self.sidekiq
|
10
|
+
require 'vizsla/background_job_instrumentation/sidekiq'
|
11
|
+
|
12
|
+
::Sidekiq.configure_server do |config|
|
13
|
+
config.server_middleware do |chain|
|
14
|
+
chain.add ::Vizsla::BackgroundJobInstrumentation::Sidekiq
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.resque
|
20
|
+
require 'vizsla/background_job_instrumentation/resque'
|
21
|
+
|
22
|
+
::Resque::Job.class_eval do
|
23
|
+
def self.new(*args)
|
24
|
+
super(*args).extend ::Vizsla::BackgroundJobInstrumentation::
|
25
|
+
ResqueInstrumentationInstaller
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.active_job
|
31
|
+
require 'vizsla/background_job_instrumentation/active_job'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Vizsla
|
2
|
+
class Config
|
3
|
+
DEFAULTS = {
|
4
|
+
log_level: 'info',
|
5
|
+
host: 'http://localhost:3000',
|
6
|
+
report_path: 'reports',
|
7
|
+
ignored_paths: []
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
attr_accessor *(DEFAULTS.keys + [:bin_id])
|
11
|
+
|
12
|
+
def initialize(config = {})
|
13
|
+
opts = DEFAULTS.merge config
|
14
|
+
opts.keys.each do |key|
|
15
|
+
if self.respond_to? key
|
16
|
+
self.instance_variable_set "@#{key}", opts[key]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'vizsla/helpers'
|
2
|
+
|
3
|
+
module Vizsla
|
4
|
+
class Event
|
5
|
+
include Vizsla::Helpers
|
6
|
+
|
7
|
+
attr_reader :event
|
8
|
+
|
9
|
+
def initialize(event)
|
10
|
+
@event = event
|
11
|
+
end
|
12
|
+
|
13
|
+
def recorder_type
|
14
|
+
event[0]
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def data_hash
|
22
|
+
{
|
23
|
+
event_type: type,
|
24
|
+
start: event[1],
|
25
|
+
stop: event[2],
|
26
|
+
duration: to_milliseconds(event[2] - event[1]),
|
27
|
+
data: event.last
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class SQLEvent < Event
|
33
|
+
def valid?
|
34
|
+
event.last[:name] != "SCHEMA"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def type
|
40
|
+
:sql
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class ControllerEvent < Event
|
45
|
+
private
|
46
|
+
|
47
|
+
def type
|
48
|
+
:controller_action
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class ViewEvent < Event
|
53
|
+
private
|
54
|
+
|
55
|
+
def type
|
56
|
+
:view
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class SinatraEvent < Event
|
61
|
+
private
|
62
|
+
|
63
|
+
def type
|
64
|
+
:route
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'vizsla/system_health_sample'
|
2
|
+
require 'vizsla/puppet_master'
|
3
|
+
require 'concurrent'
|
4
|
+
|
5
|
+
module Vizsla
|
6
|
+
class HealthMonitor
|
7
|
+
class << self
|
8
|
+
def start
|
9
|
+
@task = Concurrent::TimerTask.new(execution_interval: 10) do
|
10
|
+
health = SystemHealthSample.new
|
11
|
+
PuppetMaster.new(health).process
|
12
|
+
end
|
13
|
+
|
14
|
+
@task.execute
|
15
|
+
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def stop!
|
20
|
+
@task.shutdown
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Vizsla
|
2
|
+
class RequestLogger
|
3
|
+
def initialize(logger_override = nil)
|
4
|
+
@logger_override = logger_override
|
5
|
+
end
|
6
|
+
|
7
|
+
def display_payload(payload)
|
8
|
+
output = '=' * 50 + "\n"
|
9
|
+
|
10
|
+
str_append_hash output, payload
|
11
|
+
|
12
|
+
output += '=' * 50
|
13
|
+
|
14
|
+
log output
|
15
|
+
end
|
16
|
+
|
17
|
+
def str_append_hash(str, hsh, bumper = '')
|
18
|
+
hsh.keys.each do |key|
|
19
|
+
if hsh[key].is_a? Hash
|
20
|
+
str << "#{bumper}#{key}:\n"
|
21
|
+
str_append_hash str, hsh[key], bumper + ' '
|
22
|
+
elsif hsh[key].is_a? Array
|
23
|
+
str << "#{bumper}#{key}:\n"
|
24
|
+
hsh[key].each do |ele|
|
25
|
+
if ele.is_a? Hash
|
26
|
+
str_append_hash str, ele, bumper + ' '
|
27
|
+
else
|
28
|
+
str << "#{bumper}#{ele}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
else
|
32
|
+
str << "#{bumper}#{key}: #{hsh[key]}\n"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
str
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def rails_app?
|
42
|
+
defined? ::Rails
|
43
|
+
end
|
44
|
+
|
45
|
+
def log(text)
|
46
|
+
if !@logger_override.nil?
|
47
|
+
@logger_override.info text
|
48
|
+
elsif rails_app?
|
49
|
+
Rails.logger.debug text
|
50
|
+
else
|
51
|
+
puts text
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'vizsla/timer'
|
2
|
+
require 'vizsla/puppet_master'
|
3
|
+
|
4
|
+
module Vizsla
|
5
|
+
class Middleware
|
6
|
+
attr_reader :config
|
7
|
+
|
8
|
+
def initialize(app)
|
9
|
+
@app = app
|
10
|
+
@config = Vizsla::Agent.config
|
11
|
+
|
12
|
+
Vizsla::Agent.start! unless Vizsla::Agent.started?
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
dup.__call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
def __call(env)
|
20
|
+
path = env['REQUEST_PATH']
|
21
|
+
ignored_paths = config.ignored_paths.map { |root| %r{^#{root}} }
|
22
|
+
|
23
|
+
if ignored_paths.any? { |root| !!root.match(path) }
|
24
|
+
@app.call env
|
25
|
+
else
|
26
|
+
timer = Timer.new
|
27
|
+
timer.start!
|
28
|
+
|
29
|
+
status, headers, response = @app.call(env)
|
30
|
+
|
31
|
+
timer.transaction_name = fetch_endpoint_name env
|
32
|
+
|
33
|
+
timer.stop!
|
34
|
+
|
35
|
+
PuppetMaster.new(timer).process
|
36
|
+
|
37
|
+
[status, headers, response]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def fetch_endpoint_name(env)
|
44
|
+
if controller = env['action_controller.instance']
|
45
|
+
"#{controller.class}##{controller.params['action']}"
|
46
|
+
else
|
47
|
+
'RackTransaction'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
::ActionView::TemplateRenderer.class_eval do
|
2
|
+
alias_method :render_with_layout_without_tracebin, :render_with_layout
|
3
|
+
|
4
|
+
def render_with_layout(path, locals, *args, &block)
|
5
|
+
layout = nil
|
6
|
+
|
7
|
+
if path
|
8
|
+
if method(:find_layout).arity == 3
|
9
|
+
layout = find_layout(path, locals.keys, [formats.first])
|
10
|
+
else
|
11
|
+
layout = find_layout(path, locals.keys)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if layout
|
16
|
+
start_time = Time.now
|
17
|
+
render_with_layout_without_tracebin(path, locals, *args, &block)
|
18
|
+
end_time = Time.new
|
19
|
+
|
20
|
+
event_data = [
|
21
|
+
'render_layout.action_view',
|
22
|
+
start_time,
|
23
|
+
end_time,
|
24
|
+
{
|
25
|
+
identifier: layout.identifier
|
26
|
+
}
|
27
|
+
]
|
28
|
+
|
29
|
+
::Vizsla::Patches.handle_event :action_view_layout, event_data
|
30
|
+
else
|
31
|
+
render_with_layout_without_tracebin(path, locals, *args, &block)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|