diff --git a/History.txt b/CHANGELOG similarity index 67% rename from History.txt rename to CHANGELOG index 3262cba..837c854 100644 --- a/History.txt +++ b/CHANGELOG @@ -1,4 +1,17 @@ -== HEAD +== 0.5.0 / 2012-08-29 - transition to rack_insight + + * Compatibility + + * Restructure gem so Insight is inside a namespace, because I have classes named Insight that are obscured by + logical_insight gem when loaded. Logical also seemed like it may be a class name somewhere, hence going back to + the Rack namespace a la rack-bug. Keeping the (now nested) Insight namespace as well, because - genetics. + + *Other + + * Fix spelling of retreive => retrieve (Peter Boling) + * Remove redundant time method from cache_panel/stats.rb + +== 0.4.X - last of logical_insight * New features @@ -21,7 +34,7 @@ * Refactoring and code cleanup (Tim Connor) * Testing cleanup - better isolation of Rails vs. non-Rails in tests (Tim Connor) - + == 0.3.0 / 2010-05-28 * New features diff --git a/Gemfile.lock b/Gemfile.lock index a8af349..3bfddde 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,46 +1,19 @@ PATH remote: . specs: - logical-insight (0.4.7) - sqlite3 (~> 1.3.3) - uuid (~> 2.3.1) + rack-insight (0.5.0) + rack + sqlite3 (>= 1.3.3) + uuidtools (>= 2.1.2) GEM remote: http://gemcutter.org/ specs: archive-tar-minitar (0.5.2) - chunky_png (1.2.5) columnize (0.3.4) - compass (0.12.1) - chunky_png (~> 1.2) - fssm (>= 0.2.7) - sass (~> 3.1) - corundum (0.0.17) - bundler (~> 1.1.0) - compass (>= 0.12.1) - mailfactory (~> 1.4.0) - mattock (>= 0.2.11) - nokogiri - rake-rubygems (>= 0.2.0) - rdoc - rspec (>= 2.0) - sass (>= 3.1) - simplecov (>= 0.5.4) - yard diff-lcs (1.1.3) - fssm (0.2.9) - json (1.7.3) linecache19 (0.5.12) ruby_core_source (>= 0.1.4) - macaddr (1.6.0) - systemu (~> 2.2.0) - mailfactory (1.4.0) - mime-types (>= 1.13.1) - mattock (0.2.12) - tilt (> 0) - valise (>= 0.6) - mime-types (1.18) - multi_json (1.3.5) nokogiri (1.5.2) rack (1.3.5) rack-protection (1.1.4) @@ -48,11 +21,16 @@ GEM rack-test (0.6.1) rack (>= 1.0) rake (0.9.2.2) - rake-rubygems (0.2.0) - rake (>= 0.8.7) - rdoc (3.12) - json (~> 1.4) redcarpet (2.1.1) + reek (1.2.12) + ripper_ruby_parser (~> 0.0.7) + ruby2ruby (~> 1.2.5) + ruby_parser (~> 2.0) + sexp_processor (~> 3.0) + ripper_ruby_parser (0.0.8) + sexp_processor (~> 3.0) + roodi (2.1.0) + ruby_parser rspec (2.10.0) rspec-core (~> 2.10.0) rspec-expectations (~> 2.10.0) @@ -69,36 +47,35 @@ GEM columnize (>= 0.3.1) linecache19 (>= 0.5.11) ruby-debug-base19 (>= 0.11.19) + ruby2ruby (1.2.5) + ruby_parser (~> 2.0) + sexp_processor (~> 3.0) ruby_core_source (0.1.5) archive-tar-minitar (>= 0.5.2) - sass (3.1.18) - simplecov (0.6.4) - multi_json (~> 1.0) - simplecov-html (~> 0.5.3) - simplecov-html (0.5.3) + ruby_parser (2.3.1) + sexp_processor (~> 3.0) + sexp_processor (3.2.0) sinatra (1.3.1) rack (~> 1.3, >= 1.3.4) rack-protection (~> 1.1, >= 1.1.2) tilt (~> 1.3, >= 1.3.3) sqlite3 (1.3.6) - systemu (2.2.0) tilt (1.3.3) - uuid (2.3.5) - macaddr (~> 1.0) - valise (0.6) + uuidtools (2.1.3) webrat (0.7.3) nokogiri (>= 1.2.0) rack (>= 1.0) rack-test (>= 0.5.3) - yard (0.8.1) PLATFORMS ruby DEPENDENCIES - corundum (~> 0.0.13) - logical-insight! + rack-insight! + rake redcarpet + reek (>= 1.2.8) + roodi (>= 2.1.0) rspec ruby-debug19 sinatra diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..831196f --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +Copyright (c) 2012 Peter H. Boling as rack-insight +Copyright (c) 2011-12 LR Design as logical-insight +Copyright (c) 2009 Bryan Helmkamp as rack-bug + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/MIT-LICENSE.txt b/MIT-LICENSE.txt deleted file mode 100644 index e2463e6..0000000 --- a/MIT-LICENSE.txt +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2009 Bryan Helmkamp - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/README.md b/README.md index 4d62c6c..64edfb9 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,26 @@ -Insight +Rack::Insight ========= -Insight began life as an LRDesign fork of Rack::Bug by brynary. We started a -fork because, at the time, the main project wasn't making progress on Rails 3 -support. Since then we've rewritten a lot of the code to make it more modular, -easier to extend, and to store information about multiple requests so you can -use it to inspect your AJAX requests (or any past request), not just previous -page loads. +Rack::Insight began life as an fork of Logical::Insight by LRDesign. I started a +fork because LogicalInsight was namespaced as "Insight", which is causing namespace +collisions everywhere I have an Insight model. I had to re-namespace all the code. +I also needed to build a few extension gems with additional panels, and added the +Config class to allow for custom panel load paths, and other future extensions +that don't work in the *use Middleware* declaration. It should be *even* easier +to extend than LogicalInsight was, because extension gems can access the Config class +and truly bolt-on cleanly. -Having made really significant architectural changes, we'll be keeping Insight +Having made really significant architectural changes, I'll be keeping Rack::Insight a separate project for the forseeable future. -* Forked From: [rack-bug](http://github.com/brynary/rack-bug) - -* [Full documentation](http://lrdesign.github.com/logical-insight/) +* Forked From: [logical-insight](http://github.com/LRDesign/logical-insight), [documentation](http://lrdesign.github.com/rack-insight/) +* Which Was Forked From: [rack-bug](http://github.com/brynary/rack-bug) Description ----------- -Insight adds a diagnostics toolbar to Rack apps. When enabled, it injects a floating div -allowing exploration of logging, database queries, template rendering times, etc. Insight +Rack::Insight adds a diagnostics toolbar to Rack apps. When enabled, it injects a floating div +allowing exploration of logging, database queries, template rendering times, etc. Rack::Insight stores debugging info over many requests, incuding AJAX requests. Features @@ -27,7 +28,7 @@ Features * Password-based security * IP-based security -* Insight instrumentation/reporting is broken up into panels. +* Rack::Insight instrumentation/reporting is broken up into panels. * Panels in default configuration: * Rails Info * Timer @@ -54,22 +55,22 @@ Rails quick start --------------------------- Add this to your Gemfile - gem "logical-insight" + gem "rack-insight" In config/environments/development.rb, add: - config.middleware.use "Insight::App", + config.middleware.use "Rack::Insight::App", :secret_key => "someverylongandveryhardtoguesspreferablyrandomstring" -Any environment with Insight loaded will have a link to "Insight" added to as +Any environment with Rack::Insight loaded will have a link to "Rack::Insight" added to as the last child of BODY to normal responses. Clicking that link will load the -toolbar. It's set with an id of "logical-insight-enabler", so it can be styled +toolbar. It's set with an id of "rack-insight-enabler", so it can be styled to go somewhere more noticeable. E.g. "position: absolute; top: 0; left: 0" Using with non-Rails Rack apps ------------------------------ -Just 'use Insight' as any other middleware. See the SampleApp in the +Just 'use Rack::Insight' as any other middleware. See the SampleApp in the spec/fixtures folder for an example Sinatra app. If you wish to use the logger panel define the LOGGER constant that is a ruby @@ -80,9 +81,9 @@ Configuring custom panels Specify the set of panels you want, in the order you want them to appear: - require "logical-insight" + require "rack-insight" - ActionController::Dispatcher.middleware.use "Insight::App", + ActionController::Dispatcher.middleware.use "Rack::Insight::App", :secret_key => "someverylongandveryhardtoguesspreferablyrandomstring", :panel_files => %w[ timer_panel @@ -93,14 +94,30 @@ Specify the set of panels you want, in the order you want them to appear: memory_panel ] -Files are looked up by prepending "insight/panels/" and requiring them. -Subclasses of Insight::Panel are loaded and added to the toolbar. This makes -it easier to work with the configuration and extend Insight with plugin gems. +By default panel files are looked up by prepending "rack/insight/panels/" and requiring them. +Subclasses of Rack::Insight::Panel are loaded and added to the toolbar. This makes +it easier to work with the configuration and extend Rack::Insight with plugin gems. + +If you need to customize the load paths where Rack::Insight will look for panels you can configure the load paths in an +initializer. Example config/initializers/rack_insight.rb: + + Rack::Insight::Config.configure do |config| + + # Note: The parent directory of the 'special' directory must already be in Ruby's load path. + config[:panel_load_paths] = File.join('special','path') + + # Example 1: Do not load any of the regular Rack::Insight panels: + config[:panel_load_paths] = File.join('my','custom','panel','directory') + + # Example 2: Add your custom path to the existing load paths, to have your panels join the party! + config[:panel_load_paths] << 'custom/panels' + + end -Running Insight in staging or production +Running Rack::Insight in staging or production ------------------------------------------ -We have have found that Insight is fast enough to run in production for specific troubleshooting efforts. +We have have found that Rack::Insight is fast enough to run in production for specific troubleshooting efforts. ### Configuration #### @@ -113,23 +130,23 @@ Restrict access to particular IP addresses: require "ipaddr" - ActionController::Dispatcher.middleware.use "Insight::App" + ActionController::Dispatcher.middleware.use "Rack::Insight::App" :secret_key => "someverylongandveryhardtoguesspreferablyrandomstring", :ip_masks => [IPAddr.new("2.2.2.2/0")] Restrict access using a password: - ActionController::Dispatcher.middleware.use "Insight::App", + ActionController::Dispatcher.middleware.use "Rack::Insight::App", :secret_key => "someverylongandveryhardtoguesspreferablyrandomstring", :password => "yourpassword" #### custom file path for the logging database #### -Logical Insight uses SQLite to store data from requests, and outputs a database +Logical Rack::Insight uses SQLite to store data from requests, and outputs a database file in the root directory. If you need the file to be created at another location (i.e. Heroku), you can pass a custom file path. - ActionController::Dispatcher.middleware.use "Insight::App" + ActionController::Dispatcher.middleware.use "Rack::Insight::App" :secret_key => "someverylongandveryhardtoguesspreferablyrandomstring", :database_path => "tmp/my_insight_db.sqlite" @@ -142,15 +159,31 @@ Authors Thanks ------ -Insight owes a lot to Rack::Bug, as the basis project. There's a lot of smart -in there. Many thanks to Bryan for building it. +Rack::Insight owes a lot to both LogicalInsight and Rack::Bug, as the basis projects. There's a lot of smart +in there. Many thanks to Evan, Judson, and Bryan for building them. Inspiration for Rack::Bug is primarily from the Django debug toolbar. Additional ideas from Rails footnotes, Rack's ShowException middleware, Oink, and Rack::Cache - License ------- -See MIT-LICENSE.txt in this directory. +See LICENSE.txt in this directory. + +Notes +----- + +Legacy files: would like to re-include them, but they need work + + lib/insight/views/panels/mongo.html.erb + lib/insight/panels/mongo_panel/mongo_extension.rb + lib/insight/panels/mongo_panel/stats.rb + lib/insight/panels/mongo_panel.rb + + lib/insight/views/panels/sphinx.html.erb + lib/insight/panels/sphinx_panel/stats.rb + lib/insight/panels/sphinx_panel.rb + +This one is mostly just a curiosity + lib/insight/panels/speedtracer_panel/profiling.rb diff --git a/Rakefile b/Rakefile index b36960a..ca57272 100644 --- a/Rakefile +++ b/Rakefile @@ -1,31 +1,27 @@ -require 'yaml' -require 'corundum' -require 'corundum/tasklibs' +#!/usr/bin/env rake +require "bundler/gem_tasks" -module Corundum - tk = Toolkit.new do |tk| - end +require 'rake' - tk.in_namespace do - sanity = GemspecSanity.new(tk) - rspec = RSpec.new(tk) - cov = SimpleCov.new(tk, rspec) do |cov| - cov.threshold = 90 - end - gem = GemBuilding.new(tk) - cutter = GemCutter.new(tk,gem) - email = Email.new(tk) - vc = Git.new(tk) do |vc| - vc.branch = "master" - end - task tk.finished_files.build => vc["is_checked_in"] - yd = YARDoc.new(tk) do |yd| - yd.options = %w[--exclude lib/insight/views --exclude lib/insight/public] - end - all_docs = DocumentationAssembly.new(tk, yd, rspec, cov) do |da| - da.external_docs["The Wiki"] = "https://github.com/LRDesign/logical-insight/wiki" - da.external_docs["Github page"] = "https://github.com/LRDesign/logical-insight/" - end - pages = GithubPages.new(all_docs) - end +require 'rspec/core' +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new(:spec) do |spec| + spec.pattern = FileList['spec/**/*_spec.rb'] end + +require 'reek/rake/task' +Reek::Rake::Task.new do |t| + t.fail_on_error = true + t.verbose = false + t.source_files = 'lib/**/*.rb' +end + +require 'roodi' +require 'roodi_task' +RoodiTask.new do |t| + t.verbose = false +end + +task :default => :spec + +Bundler::GemHelper.install_tasks diff --git a/Thorfile b/Thorfile deleted file mode 100644 index 350a83c..0000000 --- a/Thorfile +++ /dev/null @@ -1,113 +0,0 @@ -module GemHelpers - - def generate_gemspec - $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "lib"))) - require "rack/bug" - - Gem::Specification.new do |s| - s.name = "rack-bug" - s.version = Rack::Bug::VERSION - s.author = "Bryan Helmkamp" - s.email = "bryan@brynary.com" - s.homepage = "http://github.com/brynary/rack-bug" - s.summary = "Debugging toolbar for Rack applications implemented as middleware" - # s.description = "TODO" - s.rubyforge_project = "rack-bug" - - require "git" - repo = Git.open(".") - - s.files = normalize_files(repo.ls_files.keys - repo.lib.ignored_files) - s.test_files = normalize_files(Dir['spec/**/*.rb'] - repo.lib.ignored_files) - - s.has_rdoc = true - s.extra_rdoc_files = %w[README.md MIT-LICENSE.txt] - - s.add_dependency "rack", ">= 1.0" - s.add_development_dependency "webrat" - s.add_development_dependency "rspec" - s.add_development_dependency "sinatra" - s.add_development_dependency "git" - end - end - - def normalize_files(array) - # only keep files, no directories, and sort - array.select do |path| - File.file?(path) - end.sort - end - - # Adds extra space when outputting an array. This helps create better version - # control diffs, because otherwise it is all on the same line. - def prettyify_array(gemspec_ruby, array_name) - gemspec_ruby.gsub(/s\.#{array_name.to_s} = \[.+?\]/) do |match| - leadin, files = match[0..-2].split("[") - leadin + "[\n #{files.split(",").join(",\n ")}\n ]" - end - end - - def read_gemspec - @read_gemspec ||= eval(File.read("rack-bug.gemspec")) - end - - def sh(command) - puts command - system command - end -end - -class Default < Thor - include GemHelpers - - desc "gemspec", "Regenerate rack-bug.gemspec" - def gemspec - File.open("rack-bug.gemspec", "w") do |file| - gemspec_ruby = generate_gemspec.to_ruby - gemspec_ruby = prettyify_array(gemspec_ruby, :files) - gemspec_ruby = prettyify_array(gemspec_ruby, :test_files) - gemspec_ruby = prettyify_array(gemspec_ruby, :extra_rdoc_files) - - file.write gemspec_ruby - end - - puts "Wrote gemspec to rack-bug.gemspec" - read_gemspec.validate - end - - desc "build", "Build a rack-bug gem" - def build - sh "gem build rack-bug.gemspec" - FileUtils.mkdir_p "pkg" - FileUtils.mv read_gemspec.file_name, "pkg" - end - - desc "install", "Install the latest built gem" - def install - sh "gem install --local pkg/#{read_gemspec.file_name}" - end - - desc "release", "Release the current branch to GitHub and Gemcutter" - def release - gemspec - build - Release.new.tag - Release.new.gem - end -end - -class Release < Thor - include GemHelpers - - desc "tag", "Tag the gem on the origin server" - def tag - release_tag = "v#{read_gemspec.version}" - sh "git tag -a #{release_tag} -m 'Tagging #{release_tag}'" - sh "git push origin #{release_tag}" - end - - desc "gem", "Push the gem to Gemcutter" - def gem - sh "gem push pkg/#{read_gemspec.file_name}" - end -end diff --git a/lib/insight.rb b/lib/insight.rb deleted file mode 100644 index a9d095c..0000000 --- a/lib/insight.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Insight - class << self - def enable - Thread.current["insight.enabled"] = true - end - - def disable - Thread.current["insight.enabled"] = false - end - - def enabled? - Thread.current["insight.enabled"] == true - end - end -end - -require 'insight/app' diff --git a/lib/insight/instrumentation.rb b/lib/insight/instrumentation.rb deleted file mode 100644 index 05b30ea..0000000 --- a/lib/insight/instrumentation.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Insight - module Instrumentation; end -end -require 'insight/instrumentation/instrument' -require 'insight/instrumentation/probe' -require 'insight/instrumentation/client' -require 'insight/instrumentation/setup' -require 'insight/instrumentation/package-definition' -require 'insight/instrumentation/probe-definition' diff --git a/lib/logical-insight.rb b/lib/logical-insight.rb deleted file mode 100644 index df38de0..0000000 --- a/lib/logical-insight.rb +++ /dev/null @@ -1 +0,0 @@ -require 'insight' diff --git a/lib/rack-insight.rb b/lib/rack-insight.rb new file mode 100644 index 0000000..06a2be5 --- /dev/null +++ b/lib/rack-insight.rb @@ -0,0 +1 @@ +require 'rack/insight' diff --git a/lib/rack/insight.rb b/lib/rack/insight.rb new file mode 100644 index 0000000..85ec9b4 --- /dev/null +++ b/lib/rack/insight.rb @@ -0,0 +1,19 @@ +require 'rack/insight/app' + +module Rack + module Insight + class << self + def enable + Thread.current["rack-insight.enabled"] = true + end + + def disable + Thread.current["rack-insight.enabled"] = false + end + + def enabled? + Thread.current["rack-insight.enabled"] == true + end + end + end +end diff --git a/lib/insight/app.rb b/lib/rack/insight/app.rb similarity index 71% rename from lib/insight/app.rb rename to lib/rack/insight/app.rb index fdf1e33..6db733c 100644 --- a/lib/insight/app.rb +++ b/lib/rack/insight/app.rb @@ -1,24 +1,24 @@ -require "rack" +require 'rack' require "digest/sha1" -require "insight/filtered_backtrace" -require "insight/options" -require "insight/logger" -require "insight/panel" -require "insight/panel_app" -require "insight/params_signature" -require "insight/rack_static_bug_avoider" -require "insight/redirect_interceptor" -require "insight/render" -require "insight/toolbar" -require "insight/enable-button" -require "insight/path-filter" -require 'insight/logger' -require 'insight/request-recorder' -require 'insight/instrumentation/setup' -require 'insight/panels-content' -require 'insight/panels-header' - -module Insight +require "rack/insight/config" +require "rack/insight/logger" +require "rack/insight/filtered_backtrace" +require "rack/insight/options" +require "rack/insight/panel" +require "rack/insight/panel_app" +require "rack/insight/params_signature" +require "rack/insight/rack_static_bug_avoider" +require "rack/insight/redirect_interceptor" +require "rack/insight/render" +require "rack/insight/toolbar" +require "rack/insight/enable-button" +require "rack/insight/path-filter" +require 'rack/insight/request-recorder' +require 'rack/insight/instrumentation/setup' +require 'rack/insight/panels-content' +require 'rack/insight/panels-header' + +module Rack::Insight class App include Options INSIGHT_ROOT = "/__insight__" @@ -36,7 +36,7 @@ def initialize(app, options = {}, &block) instance_eval(&block) if block_given? @logger = Logger.new(read_option(:log_level), read_option(:log_path)) - Thread.current['insight.logger'] = @logger + Thread.current['rack-insight.logger'] = @logger build_normal_stack build_debug_stack if options[:on_initialize] @@ -52,11 +52,11 @@ def call(env) @env = env self.options = @default_options - env['insight.logger'] = @logger - Thread.current['insight.logger'] = @logger + env['rack-insight.logger'] = @logger + Thread.current['rack-insight.logger'] = @logger - Insight.enable - env["insight.panels"] = [] + Rack::Insight.enable + env["rack-insight.panels"] = [] @debug_stack.call(env) else @normal_stack.call(env) @@ -68,13 +68,13 @@ def reset(new_options=nil) @env = nil initialize_options(new_options) - Insight::Instrumentation::ClassProbe::all_probes.each do |probe| + Rack::Insight::Instrumentation::ClassProbe::all_probes.each do |probe| probe.clear_collectors end - Insight::Instrumentation::InstanceProbe::all_probes.each do |probe| + Rack::Insight::Instrumentation::InstanceProbe::all_probes.each do |probe| probe.clear_collectors end - Insight::Instrumentation::PackageDefinition.clear_collectors + Rack::Insight::Instrumentation::PackageDefinition.clear_collectors build_debug_stack end @@ -162,16 +162,16 @@ def public_path end def toolbar_requested? - @original_request.cookies["insight_enabled"] + @original_request.cookies["rack-insight_enabled"] end def ip_authorized? - return true unless options["insight.ip_masks"] + return true unless options["rack-insight.ip_masks"] logger.debug{ "Checking #{@original_request.ip} against ip_masks" } ip = IPAddr.new(@original_request.ip) - mask = options["insight.ip_masks"].find do |ip_mask| + mask = options["rack-insight.ip_masks"].find do |ip_mask| ip_mask.include?(ip) end if mask @@ -184,12 +184,12 @@ def ip_authorized? end def password_authorized? - return true unless options["insight.password"] + return true unless options["rack-insight.password"] logger.debug{"Checking password"} - expected_sha = Digest::SHA1.hexdigest ["insight", options["insight.password"]].join(":") - actual_sha = @original_request.cookies["insight_password"] + expected_sha = Digest::SHA1.hexdigest ["rack-insight", options["rack-insight.password"]].join(":") + actual_sha = @original_request.cookies["rack-insight_password"] logger.debug{"Password result: #{actual_sha == expected_sha}"} actual_sha == expected_sha diff --git a/lib/rack/insight/config.rb b/lib/rack/insight/config.rb new file mode 100644 index 0000000..b3febef --- /dev/null +++ b/lib/rack/insight/config.rb @@ -0,0 +1,30 @@ +module Rack::Insight + class Config + class << self + attr_accessor :config + end + + DEFAULTS = { + # You can augment or replace the default set of panel load paths. + # These are the paths where rack-insight will look for panels. + # A rack-insight extension gem could place panels in: + # lib/foo/bar/ + # Since gems' lib/ is automatically shifted onto Ruby load path, this will make the custom panels discoverable: + # Rack::Insight::Config.configure do |config| + # config[:panel_load_paths] << File::join('foo', 'bar') + # end + :panel_load_paths => [File::join('rack', 'insight', 'panels')] + } + + #cattr_reader :config + #cattr_writer :config + + @config ||= DEFAULTS + def self.configure &block + yield @config + unless config[:panel_load_paths].kind_of?(Array) + raise "Rack::Insight::Config.config[:panel_load_paths] is invalid: Expected kind of Array but got #{config[:panel_load_paths].class}" + end + end + end +end diff --git a/lib/insight/database.rb b/lib/rack/insight/database.rb similarity index 94% rename from lib/insight/database.rb rename to lib/rack/insight/database.rb index 5718c75..f688677 100644 --- a/lib/insight/database.rb +++ b/lib/rack/insight/database.rb @@ -1,8 +1,8 @@ -require 'insight' +#require 'rack-insight' require 'sqlite3' require 'base64' -module Insight +module Rack::Insight class Database module RequestDataClient def key_sql_template(sql) @@ -18,7 +18,7 @@ def table_setup(name, *keys) def store(env, *keys_and_value) return if env.nil? - request_id = env["insight.request-id"] + request_id = env["rack-insight.request-id"] return if request_id.nil? value = keys_and_value[-1] @@ -41,7 +41,7 @@ class << self include Logging def database_path=(value) - @database_path = value || "insight.sqlite" + @database_path = value || "rack-insight.sqlite" end def database_path @@ -69,7 +69,7 @@ def open_database if defined?(PhusionPassenger) PhusionPassenger.on_event(:starting_worker_process) do |forked| - Insight::Database::open_database if forked + Rack::Insight::Database::open_database if forked end end end @@ -78,7 +78,7 @@ class Table include Logging def db - Insight::Database.db + Rack::Insight::Database.db end def create_keys_clause diff --git a/lib/insight/enable-button.rb b/lib/rack/insight/enable-button.rb similarity index 97% rename from lib/insight/enable-button.rb rename to lib/rack/insight/enable-button.rb index 6b8fd1f..b787c85 100644 --- a/lib/insight/enable-button.rb +++ b/lib/rack/insight/enable-button.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class EnableButton include Render diff --git a/lib/insight/filtered_backtrace.rb b/lib/rack/insight/filtered_backtrace.rb similarity index 98% rename from lib/insight/filtered_backtrace.rb rename to lib/rack/insight/filtered_backtrace.rb index 9b10095..4a60188 100644 --- a/lib/insight/filtered_backtrace.rb +++ b/lib/rack/insight/filtered_backtrace.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight module FilteredBacktrace def backtrace diff --git a/lib/rack/insight/instrumentation.rb b/lib/rack/insight/instrumentation.rb new file mode 100644 index 0000000..1d4b506 --- /dev/null +++ b/lib/rack/insight/instrumentation.rb @@ -0,0 +1,9 @@ +module Rack::Insight + module Instrumentation; end +end +require 'rack/insight/instrumentation/instrument' +require 'rack/insight/instrumentation/probe' +require 'rack/insight/instrumentation/client' +require 'rack/insight/instrumentation/setup' +require 'rack/insight/instrumentation/package-definition' +require 'rack/insight/instrumentation/probe-definition' diff --git a/lib/insight/instrumentation/backstage.rb b/lib/rack/insight/instrumentation/backstage.rb similarity index 83% rename from lib/insight/instrumentation/backstage.rb rename to lib/rack/insight/instrumentation/backstage.rb index 3711740..ec59085 100644 --- a/lib/insight/instrumentation/backstage.rb +++ b/lib/rack/insight/instrumentation/backstage.rb @@ -1,4 +1,4 @@ -module Insight::Instrumentation +module Rack::Insight::Instrumentation module Backstage def backstage Thread.current["instrumented_backstage"] = true diff --git a/lib/insight/instrumentation/client.rb b/lib/rack/insight/instrumentation/client.rb similarity index 62% rename from lib/insight/instrumentation/client.rb rename to lib/rack/insight/instrumentation/client.rb index 79420f1..d6c2085 100644 --- a/lib/insight/instrumentation/client.rb +++ b/lib/rack/insight/instrumentation/client.rb @@ -1,8 +1,8 @@ -require 'insight/instrumentation/package-definition' -module Insight::Instrumentation +require 'rack/insight/instrumentation/package-definition' +module Rack::Insight::Instrumentation module Client def probe(collector, &block) - ::Insight::Instrumentation::PackageDefinition::probe(collector, &block) + ::Rack::Insight::Instrumentation::PackageDefinition::probe(collector, &block) end def request_start(env, start) diff --git a/lib/insight/instrumentation/instrument.rb b/lib/rack/insight/instrumentation/instrument.rb similarity index 97% rename from lib/insight/instrumentation/instrument.rb rename to lib/rack/insight/instrumentation/instrument.rb index 45722c1..1bee7a3 100644 --- a/lib/insight/instrumentation/instrument.rb +++ b/lib/rack/insight/instrumentation/instrument.rb @@ -1,7 +1,7 @@ -require 'insight/instrumentation/backstage' -require 'insight/logger' +require 'rack/insight/instrumentation/backstage' +require 'rack/insight/logger' -module Insight +module Rack::Insight module Instrumentation class Instrument MethodCall = Struct.new(:call_number, :backtrace, :file, :line, :object, :context, :kind, :method, :thread) diff --git a/lib/insight/instrumentation/package-definition.rb b/lib/rack/insight/instrumentation/package-definition.rb similarity index 96% rename from lib/insight/instrumentation/package-definition.rb rename to lib/rack/insight/instrumentation/package-definition.rb index 3163d31..a70e1b4 100644 --- a/lib/insight/instrumentation/package-definition.rb +++ b/lib/rack/insight/instrumentation/package-definition.rb @@ -1,4 +1,4 @@ -module Insight::Instrumentation +module Rack::Insight::Instrumentation class PackageDefinition class << self def start diff --git a/lib/insight/instrumentation/probe-definition.rb b/lib/rack/insight/instrumentation/probe-definition.rb similarity index 92% rename from lib/insight/instrumentation/probe-definition.rb rename to lib/rack/insight/instrumentation/probe-definition.rb index f8e6d53..6e83e4d 100644 --- a/lib/insight/instrumentation/probe-definition.rb +++ b/lib/rack/insight/instrumentation/probe-definition.rb @@ -1,4 +1,4 @@ -module Insight::Instrumentation +module Rack::Insight::Instrumentation class ProbeDefinition def initialize(package, target_name) @package = package diff --git a/lib/insight/instrumentation/probe.rb b/lib/rack/insight/instrumentation/probe.rb similarity index 98% rename from lib/insight/instrumentation/probe.rb rename to lib/rack/insight/instrumentation/probe.rb index 792fd89..f76e7c2 100644 --- a/lib/insight/instrumentation/probe.rb +++ b/lib/rack/insight/instrumentation/probe.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight module Instrumentation class Probe module Interpose @@ -16,7 +16,7 @@ def probe_run(object, context = "::", kind=:instance, args=[], called_at=caller[ ##{method_name}" unless method_name.to_sym == :add return yield end - instrument = Thread.current['insight.instrument'] + instrument = Thread.current['rack-insight.instrument'] result = nil if instrument.nil? backstage do diff --git a/lib/insight/instrumentation/setup.rb b/lib/rack/insight/instrumentation/setup.rb similarity index 57% rename from lib/insight/instrumentation/setup.rb rename to lib/rack/insight/instrumentation/setup.rb index 082bec3..882d924 100644 --- a/lib/insight/instrumentation/setup.rb +++ b/lib/rack/insight/instrumentation/setup.rb @@ -1,4 +1,4 @@ -module Insight::Instrumentation +module Rack::Insight::Instrumentation class Setup def initialize(app) @app = app @@ -10,16 +10,16 @@ def setup(env) PackageDefinition.start instrument.start(env) - env["insight.instrument"] = instrument - Thread::current["insight.instrument"] = instrument + env["rack-insight.instrument"] = instrument + Thread::current["rack-insight.instrument"] = instrument end def teardown(env, status, headers, body) - instrument, env["insight.instrument"] = env["insight.instrument"], nil + instrument, env["rack-insight.instrument"] = env["rack-insight.instrument"], nil instrument.finish(env, status, headers, body) - Thread::current["insight.instrument"] = nil + Thread::current["rack-insight.instrument"] = nil - env["insight.duration"] = instrument.duration + env["rack-insight.duration"] = instrument.duration end def call(env) diff --git a/lib/insight/logger.rb b/lib/rack/insight/logger.rb similarity index 78% rename from lib/insight/logger.rb rename to lib/rack/insight/logger.rb index f0d69e6..faa146c 100644 --- a/lib/insight/logger.rb +++ b/lib/rack/insight/logger.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class Logger def initialize(level, path) @level = level @@ -20,7 +20,7 @@ def log(severity, message) return unless severity >= @level if defined? Rails and Rails.respond_to?(:logger) and not Rails.logger.nil? - Rails.logger.add(severity, "[Insight]: " + message) + Rails.logger.add(severity, "[Rack::Insight]: " + message) end logfile.puts(message) @@ -43,9 +43,9 @@ def unknown; log(UNKNOWN, yield) end module Logging def logger(env = nil) if env.nil? - Thread.current['insight.logger'] ||= Logger.new(Logger::DEBUG, "") + Thread.current['rack-insight.logger'] ||= Rack::Insight::Logger.new(Logger::DEBUG, "") else - env["insight.logger"] + env["rack-insight.logger"] ||= Rack::Insight::Logger.new(Logger::DEBUG, "") end end module_function :logger diff --git a/lib/insight/options.rb b/lib/rack/insight/options.rb similarity index 69% rename from lib/insight/options.rb rename to lib/rack/insight/options.rb index 8c9f824..97a106a 100644 --- a/lib/insight/options.rb +++ b/lib/rack/insight/options.rb @@ -1,6 +1,6 @@ require 'ipaddr' -module Insight +module Rack::Insight module Options class << self private @@ -66,37 +66,37 @@ def write_option(key, value) def option_name(key) case key - when Symbol ; "insight.#{key}" + when Symbol ; "rack-insight.#{key}" when String ; key else raise ArgumentError end end def process_options - if(file_list = read_option('insight.panel_files')) - class_list = read_option('insight.panel_classes') || [] + if(file_list = read_option('rack-insight.panel_files')) + class_list = read_option('rack-insight.panel_classes') || [] file_list.each do |file| - class_list |= Insight::Panel.from_file(file) + class_list |= Rack::Insight::Panel.from_file(file) end - write_option('insight.panel_classes', class_list) + write_option('rack-insight.panel_classes', class_list) end - Insight::Database.database_path = read_option('insight.database_path') + Rack::Insight::Database.database_path = read_option('rack-insight.database_path') end def initialize_options(options=nil) @default_options = { - 'insight.ip_masks' => [IPAddr.new("127.0.0.1")], - 'insight.password' => nil, - 'insight.verbose' => nil, - 'insight.secret_key' => nil, - 'insight.intercept_redirects' => false, - 'insight.panels' => [], - 'insight.path_filters' => %w{/assets/}, - 'insight.log_level' => Logger::INFO, - 'insight.log_path' => "log/insight.log", - 'insight.database_path' => "insight.sqlite", - 'insight.panel_files' => %w{ + 'rack-insight.ip_masks' => [IPAddr.new("127.0.0.1")], + 'rack-insight.password' => nil, + 'rack-insight.verbose' => nil, + 'rack-insight.secret_key' => nil, + 'rack-insight.intercept_redirects' => false, + 'rack-insight.panels' => [], + 'rack-insight.path_filters' => %w{/assets/}, + 'rack-insight.log_level' => Logger::INFO, + 'rack-insight.log_path' => "log/rack-insight.log", + 'rack-insight.database_path' => "rack-insight.sqlite", + 'rack-insight.panel_files' => %w{ rails_info_panel timer_panel request_variables_panel diff --git a/lib/insight/panel.rb b/lib/rack/insight/panel.rb similarity index 52% rename from lib/insight/panel.rb rename to lib/rack/insight/panel.rb index 41a4ab7..930b10e 100644 --- a/lib/insight/panel.rb +++ b/lib/rack/insight/panel.rb @@ -1,17 +1,18 @@ require "erb" -require 'insight/database' -require 'insight/instrumentation' -require 'insight/render' +require "rack/insight/logger" +require 'rack/insight/database' +require 'rack/insight/instrumentation' +require 'rack/insight/render' -module Insight +module Rack::Insight # Panels are also Rack middleware class Panel - include Render include ERB::Util - include Database::RequestDataClient - include Logging - include Instrumentation::Client + include Rack::Insight::Logging + include Rack::Insight::Render + include Rack::Insight::Database::RequestDataClient + include Rack::Insight::Instrumentation::Client attr_reader :request @@ -27,22 +28,35 @@ def panel_exclusion end def from_file(rel_path) - old_rel, Thread::current['panel_file'] = Thread::current['panel_file'], rel_path - require File::join('insight', 'panels', rel_path) + old_rel, Thread::current['rack-panel_file'] = Thread::current['rack-panel_file'], rel_path + Rack::Insight::Config.config[:panel_load_paths].each do |load_path| + begin + require File::join(load_path, rel_path) + rescue LoadError => e + end + end return (file_index[rel_path] - panel_exclusion) ensure - Thread::current['panel_file'] = old_rel + Thread::current['rack-panel_file'] = old_rel end def current_panel_file - return Thread::current['panel_file'] || + return Thread::current['rack-panel_file'] || begin file_name = nil + matched_line = nil caller.each do |line| - md = %r{^[^:]*insight/panels/([^:]*)\.rb:}.match line - unless md.nil? - file_name = md[1] + # First make sure we are not matching rack-insight's own panel class, which will be in the caller stack, + # and which may match some custom load path added (try adding 'rack' as a custom load path!) + next if line =~ /rack-insight.*\/lib\/rack\/insight\/panel.rb:/ + Rack::Insight::Config.config[:panel_load_paths].each do |load_path| + regex = %r{^[^:]*#{load_path}/([^:]*)\.rb:} + md = regex.match line + file_name = md[1] unless md.nil? + matched_line = line unless file_name.nil? + break unless file_name.nil? end + break unless file_name.nil? end file_name end @@ -52,7 +66,7 @@ def inherited(sub) if filename = current_panel_file Panel::file_index[current_panel_file] << sub else - warn "Insight::Panel inherited by #{sub.name} outside of an insight/panels/* file. Discarded" + warn "Rack::Insight::Panel inherited by #{sub.name} outside rack-insight's :panel_load_paths. Discarded. Configured panel load paths are: #{Rack::Insight::Config.config[:panel_load_paths].inspect}" end end @@ -79,7 +93,7 @@ def call(env) @request = Rack::Request.new(env) logger.debug{ "After call: #{self.name}" } after(env, status, headers, body) - env["insight.panels"] << self + env["rack-insight.panels"] << self return [status, headers, body] end diff --git a/lib/insight/panel_app.rb b/lib/rack/insight/panel_app.rb similarity index 88% rename from lib/insight/panel_app.rb rename to lib/rack/insight/panel_app.rb index 19d988c..582c9ca 100644 --- a/lib/insight/panel_app.rb +++ b/lib/rack/insight/panel_app.rb @@ -1,7 +1,7 @@ -module Insight +module Rack::Insight class PanelApp - include Insight::Render + include Rack::Insight::Render attr_reader :request diff --git a/lib/insight/panels-content.rb b/lib/rack/insight/panels-content.rb similarity index 97% rename from lib/insight/panels-content.rb rename to lib/rack/insight/panels-content.rb index 07f55ac..e07eba0 100644 --- a/lib/insight/panels-content.rb +++ b/lib/rack/insight/panels-content.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class PanelsContent < PanelApp def initialize(insight_app) @insight_app = insight_app diff --git a/lib/insight/panels-header.rb b/lib/rack/insight/panels-header.rb similarity index 96% rename from lib/insight/panels-header.rb rename to lib/rack/insight/panels-header.rb index 371b9a0..d8867e0 100644 --- a/lib/insight/panels-header.rb +++ b/lib/rack/insight/panels-header.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class PanelsHeader < PanelApp def initialize(insight_app) @insight_app = insight_app diff --git a/lib/insight/panels/active_record_panel.rb b/lib/rack/insight/panels/active_record_panel.rb similarity index 91% rename from lib/insight/panels/active_record_panel.rb rename to lib/rack/insight/panels/active_record_panel.rb index 547f3fd..4cf99fb 100644 --- a/lib/insight/panels/active_record_panel.rb +++ b/lib/rack/insight/panels/active_record_panel.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class ActiveRecordPanel < Panel def initialize(app) super @@ -37,7 +37,7 @@ def heading_for_request(number) end def content_for_request(number) - records = retreive(number).first.to_a.sort_by { |key, value| value }.reverse + records = retrieve(number).first.to_a.sort_by { |key, value| value }.reverse render_template "panels/active_record", :records => records end diff --git a/lib/insight/panels/active_resource_panel.rb b/lib/rack/insight/panels/active_resource_panel.rb similarity index 85% rename from lib/insight/panels/active_resource_panel.rb rename to lib/rack/insight/panels/active_resource_panel.rb index f07a186..4f550f4 100644 --- a/lib/insight/panels/active_resource_panel.rb +++ b/lib/rack/insight/panels/active_resource_panel.rb @@ -1,10 +1,10 @@ require "digest" -module Insight +module Rack::Insight class ActiveResourcePanel < Panel - require 'insight/panels/active_resource_panel/query' - #require "insight/panels/sql_panel/panel_app" - #require "insight/panels/sql_panel/query" + require 'rack/insight/panels/active_resource_panel/query' + #require "rack/insight/panels/sql_panel/panel_app" + #require "rack/insight/panels/sql_panel/query" def initialize(app) super diff --git a/lib/insight/panels/active_resource_panel/query.rb b/lib/rack/insight/panels/active_resource_panel/query.rb similarity index 89% rename from lib/insight/panels/active_resource_panel/query.rb rename to lib/rack/insight/panels/active_resource_panel/query.rb index 11e4e11..509e70f 100644 --- a/lib/insight/panels/active_resource_panel/query.rb +++ b/lib/rack/insight/panels/active_resource_panel/query.rb @@ -1,7 +1,7 @@ -module Insight +module Rack::Insight class ActiveResourcePanel class RequestResult - include Insight::FilteredBacktrace + include Rack::Insight::FilteredBacktrace attr_reader :path, :args, :result, :time alias results result diff --git a/lib/insight/panels/cache_panel.rb b/lib/rack/insight/panels/cache_panel.rb similarity index 85% rename from lib/insight/panels/cache_panel.rb rename to lib/rack/insight/panels/cache_panel.rb index 9cb6c0b..765e6f9 100644 --- a/lib/insight/panels/cache_panel.rb +++ b/lib/rack/insight/panels/cache_panel.rb @@ -1,9 +1,9 @@ -module Insight +module Rack::Insight class CachePanel < Panel - require "insight/panels/cache_panel/panel_app" - require "insight/panels/cache_panel/stats" + require "rack/insight/panels/cache_panel/panel_app" + require "rack/insight/panels/cache_panel/stats" def initialize(app) super @@ -31,7 +31,6 @@ def request_start(env, start) end def request_finish(env, st, hd, bd, timing) - logger(env).debug{ "Stats: #@stats" } store(env, @stats) end @@ -53,14 +52,14 @@ def name end def heading_for_request(number) - stats = retreive(number).first + stats = retrieve(number).first "Cache: %.2fms (#{stats.queries.size} calls)" % stats.time end def content_for_request(number) logger.debug{{ :req_num => number }} - stats = retreive(number).first + stats = retrieve(number).first render_template "panels/cache", :stats => stats end diff --git a/lib/insight/panels/cache_panel/panel_app.rb b/lib/rack/insight/panels/cache_panel/panel_app.rb similarity index 93% rename from lib/insight/panels/cache_panel/panel_app.rb rename to lib/rack/insight/panels/cache_panel/panel_app.rb index 844b737..4a1032d 100644 --- a/lib/insight/panels/cache_panel/panel_app.rb +++ b/lib/rack/insight/panels/cache_panel/panel_app.rb @@ -1,7 +1,7 @@ -module Insight +module Rack::Insight class CachePanel - class PanelApp < ::Insight::PanelApp + class PanelApp < ::Rack::Insight::PanelApp def dispatch case request.path_info diff --git a/lib/insight/panels/cache_panel/stats.rb b/lib/rack/insight/panels/cache_panel/stats.rb similarity index 89% rename from lib/insight/panels/cache_panel/stats.rb rename to lib/rack/insight/panels/cache_panel/stats.rb index a596e8f..5667bf0 100644 --- a/lib/insight/panels/cache_panel/stats.rb +++ b/lib/rack/insight/panels/cache_panel/stats.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class CachePanel class Stats @@ -25,9 +25,7 @@ def display_keys end end - attr_reader :calls - attr_reader :keys - attr_reader :queries + attr_reader :calls, :keys, :queries, :time def initialize @queries = [] @@ -52,12 +50,6 @@ def display_time "%.2fms" % time end - def time - @queries.inject(0) do |memo, query| - memo + query.time - end - end - def gets count_queries(:get) end diff --git a/lib/insight/panels/log_panel.rb b/lib/rack/insight/panels/log_panel.rb similarity index 98% rename from lib/insight/panels/log_panel.rb rename to lib/rack/insight/panels/log_panel.rb index d300a67..e1e42ed 100644 --- a/lib/insight/panels/log_panel.rb +++ b/lib/rack/insight/panels/log_panel.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class LogPanel < Panel class LogEntry attr_reader :level, :time, :message diff --git a/lib/insight/panels/memory_panel.rb b/lib/rack/insight/panels/memory_panel.rb similarity index 97% rename from lib/insight/panels/memory_panel.rb rename to lib/rack/insight/panels/memory_panel.rb index 376180b..a6513fe 100644 --- a/lib/insight/panels/memory_panel.rb +++ b/lib/rack/insight/panels/memory_panel.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class MemoryPanel < Panel def initialize(app) diff --git a/lib/insight/panels/mongo_panel.rb b/lib/rack/insight/panels/mongo_panel.rb similarity index 66% rename from lib/insight/panels/mongo_panel.rb rename to lib/rack/insight/panels/mongo_panel.rb index 80239c8..8756dbf 100644 --- a/lib/insight/panels/mongo_panel.rb +++ b/lib/rack/insight/panels/mongo_panel.rb @@ -1,11 +1,11 @@ -module Insight +module Rack::Insight class MongoPanel < Panel - require "insight/panels/mongo_panel/mongo_extension" - require "insight/panels/mongo_panel/stats" + require "rack/insight/panels/mongo_panel/mongo_extension" + require "rack/insight/panels/mongo_panel/stats" def self.record(command, &block) - return block.call unless Insight.enabled? + return block.call unless Rack::Insight.enabled? start_time = Time.now result = block.call @@ -15,11 +15,11 @@ def self.record(command, &block) end def self.reset - Thread.current["insight.mongo"] = Stats.new + Thread.current["rack-insight.mongo"] = Stats.new end def self.stats - Thread.current["insight.mongo"] ||= Stats.new + Thread.current["rack-insight.mongo"] ||= Stats.new end def name diff --git a/lib/insight/panels/mongo_panel/mongo_extension.rb b/lib/rack/insight/panels/mongo_panel/mongo_extension.rb similarity index 84% rename from lib/insight/panels/mongo_panel/mongo_extension.rb rename to lib/rack/insight/panels/mongo_panel/mongo_extension.rb index 1b83a4d..00b5b73 100644 --- a/lib/insight/panels/mongo_panel/mongo_extension.rb +++ b/lib/rack/insight/panels/mongo_panel/mongo_extension.rb @@ -3,14 +3,14 @@ Mongo::Connection.class_eval do def send_message_with_insight(operation, message, log_message=nil) - Insight::MongoPanel.record(log_message || message) do + Rack::Insight::MongoPanel.record(log_message || message) do send_message_without_insight(operation, message, log_message) end end alias_method_chain :send_message, :insight def send_message_with_safe_check_with_insight(operation, message, db_name, log_message=nil, last_error_params=false) - Insight::MongoPanel.record(log_message || message) do + Rack::Insight::MongoPanel.record(log_message || message) do send_message_with_safe_check_without_insight(operation, message, db_name, log_message, last_error_params) end end diff --git a/lib/insight/panels/mongo_panel/stats.rb b/lib/rack/insight/panels/mongo_panel/stats.rb similarity index 97% rename from lib/insight/panels/mongo_panel/stats.rb rename to lib/rack/insight/panels/mongo_panel/stats.rb index 466efe0..7912a5e 100644 --- a/lib/insight/panels/mongo_panel/stats.rb +++ b/lib/rack/insight/panels/mongo_panel/stats.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class MongoPanel class Stats diff --git a/lib/insight/panels/rails_info_panel.rb b/lib/rack/insight/panels/rails_info_panel.rb similarity index 94% rename from lib/insight/panels/rails_info_panel.rb rename to lib/rack/insight/panels/rails_info_panel.rb index 6f46f47..ea166ff 100644 --- a/lib/insight/panels/rails_info_panel.rb +++ b/lib/rack/insight/panels/rails_info_panel.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class RailsInfoPanel < Panel def name diff --git a/lib/insight/panels/redis_panel.rb b/lib/rack/insight/panels/redis_panel.rb similarity index 68% rename from lib/insight/panels/redis_panel.rb rename to lib/rack/insight/panels/redis_panel.rb index 174de8f..2847833 100644 --- a/lib/insight/panels/redis_panel.rb +++ b/lib/rack/insight/panels/redis_panel.rb @@ -1,12 +1,12 @@ -module Insight +module Rack::Insight class RedisPanel < Panel - require "insight/panels/redis_panel/redis_extension" + require "rack/insight/panels/redis_panel/redis_extension" - require "insight/panels/redis_panel/stats" + require "rack/insight/panels/redis_panel/stats" def self.record(redis_command_args, backtrace, &block) - return block.call unless Insight.enabled? + return block.call unless Rack::Insight.enabled? start_time = Time.now result = block.call @@ -16,11 +16,11 @@ def self.record(redis_command_args, backtrace, &block) end def self.reset - Thread.current["insight.redis"] = Stats.new + Thread.current["rack-insight.redis"] = Stats.new end def self.stats - Thread.current["insight.redis"] ||= Stats.new + Thread.current["rack-insight.redis"] ||= Stats.new end def name diff --git a/lib/insight/panels/redis_panel/redis_extension.rb b/lib/rack/insight/panels/redis_panel/redis_extension.rb similarity index 88% rename from lib/insight/panels/redis_panel/redis_extension.rb rename to lib/rack/insight/panels/redis_panel/redis_extension.rb index afe6cb6..5247abb 100644 --- a/lib/insight/panels/redis_panel/redis_extension.rb +++ b/lib/rack/insight/panels/redis_panel/redis_extension.rb @@ -2,7 +2,7 @@ Redis.class_eval do if Redis.methods.include?('call_command') # older versions of redis-rb def call_command_with_insight(*argv) - Insight::RedisPanel.record(argv, Kernel.caller) do + Rack::Insight::RedisPanel.record(argv, Kernel.caller) do call_command_without_insight(*argv) end end diff --git a/lib/insight/panels/redis_panel/stats.rb b/lib/rack/insight/panels/redis_panel/stats.rb similarity index 92% rename from lib/insight/panels/redis_panel/stats.rb rename to lib/rack/insight/panels/redis_panel/stats.rb index af70576..ea175ea 100644 --- a/lib/insight/panels/redis_panel/stats.rb +++ b/lib/rack/insight/panels/redis_panel/stats.rb @@ -1,9 +1,9 @@ -module Insight +module Rack::Insight class RedisPanel class Stats class Query - include Insight::FilteredBacktrace + include Rack::Insight::FilteredBacktrace attr_reader :time attr_reader :command diff --git a/lib/insight/panels/request_variables_panel.rb b/lib/rack/insight/panels/request_variables_panel.rb similarity index 94% rename from lib/insight/panels/request_variables_panel.rb rename to lib/rack/insight/panels/request_variables_panel.rb index 8bb9fcd..386aff2 100644 --- a/lib/insight/panels/request_variables_panel.rb +++ b/lib/rack/insight/panels/request_variables_panel.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class RequestVariablesPanel < Panel def initialize(app) super @@ -57,7 +57,7 @@ def split_and_filter_env(env) env.each do |k,v| if k.index("rack.") == 0 rack[k] = v - elsif k.index("insight") == 0 or k.index("insight") == 0 + elsif k.index("rack-insight") == 0 or k.index("rack-insight") == 0 #don't output the insight variables - especially secret_key else server[k] = v diff --git a/lib/insight/panels/speedtracer_panel.rb b/lib/rack/insight/panels/speedtracer_panel.rb similarity index 82% rename from lib/insight/panels/speedtracer_panel.rb rename to lib/rack/insight/panels/speedtracer_panel.rb index 730b2a8..46431e7 100644 --- a/lib/insight/panels/speedtracer_panel.rb +++ b/lib/rack/insight/panels/speedtracer_panel.rb @@ -3,17 +3,17 @@ rescue LoadError #Means no Chrome Speedtracer... end -require 'uuid' -require 'insight/panels/speedtracer_panel/trace-app' -require 'insight/panels/speedtracer_panel/tracer' +require 'uuidtools' +require 'rack/insight/panels/speedtracer_panel/trace-app' +require 'rack/insight/panels/speedtracer_panel/tracer' -module Insight +module Rack::Insight module SpeedTracer - class Panel < ::Insight::Panel + class Panel < ::Rack::Insight::Panel def initialize(app) @app = app - @uuid = UUID.new + @uuid = UUIDTools::UUID.random_create.to_s table_setup("speedtracer", "uuid") key_sql_template("'%s'") @@ -54,12 +54,12 @@ def initialize(app) def call(env) - env['insight.speedtracer-id'] = @uuid.generate + env['rack-insight.speedtracer-id'] = @uuid status, headers, body = @app.call(env) - store(env, env['insight.speedtracer-id'], env['insight.speedtracer-record']) - headers['X-TraceUrl'] = '__insight__/speedtracer?id=' + env['insight.speedtracer-id'] + store(env, env['rack-insight.speedtracer-id'], env['rack-insight.speedtracer-record']) + headers['X-TraceUrl'] = '__insight__/speedtracer?id=' + env['rack-insight.speedtracer-id'] return [status, headers, body] end diff --git a/lib/insight/panels/speedtracer_panel/profiling.rb b/lib/rack/insight/panels/speedtracer_panel/profiling.rb similarity index 97% rename from lib/insight/panels/speedtracer_panel/profiling.rb rename to lib/rack/insight/panels/speedtracer_panel/profiling.rb index 2b8fe31..6bb1d90 100644 --- a/lib/insight/panels/speedtracer_panel/profiling.rb +++ b/lib/rack/insight/panels/speedtracer_panel/profiling.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight #Variant of the Speed Tracer Panel that performs a nearly complete profile of diff --git a/lib/insight/panels/speedtracer_panel/trace-app.rb b/lib/rack/insight/panels/speedtracer_panel/trace-app.rb similarity index 98% rename from lib/insight/panels/speedtracer_panel/trace-app.rb rename to lib/rack/insight/panels/speedtracer_panel/trace-app.rb index 3534602..832bd72 100644 --- a/lib/insight/panels/speedtracer_panel/trace-app.rb +++ b/lib/rack/insight/panels/speedtracer_panel/trace-app.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight module SpeedTracer class TraceApp include Database::RequestDataClient diff --git a/lib/insight/panels/speedtracer_panel/tracer.rb b/lib/rack/insight/panels/speedtracer_panel/tracer.rb similarity index 96% rename from lib/insight/panels/speedtracer_panel/tracer.rb rename to lib/rack/insight/panels/speedtracer_panel/tracer.rb index 35f7d8c..e710a2f 100644 --- a/lib/insight/panels/speedtracer_panel/tracer.rb +++ b/lib/rack/insight/panels/speedtracer_panel/tracer.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight module SpeedTracer class Tracer def initialize(table) @@ -8,12 +8,12 @@ def initialize(table) end def request_start(env, start) - id, method, uri = env.values_at("insight.speedtracer-id", "REQUEST_METHOD", "PATH_INFO") + id, method, uri = env.values_at("rack-insight.speedtracer-id", "REQUEST_METHOD", "PATH_INFO") @pstack.push RequestRecord.new(id, method, uri) end def request_finish(env, status, headers, body, timing) - env["insight.speedtracer-record"] = @pstack.pop + env["rack-insight.speedtracer-record"] = @pstack.pop end def before_detect(method_call, arguments) diff --git a/lib/insight/panels/sphinx_panel.rb b/lib/rack/insight/panels/sphinx_panel.rb similarity index 67% rename from lib/insight/panels/sphinx_panel.rb rename to lib/rack/insight/panels/sphinx_panel.rb index 684a22c..28c3d07 100644 --- a/lib/insight/panels/sphinx_panel.rb +++ b/lib/rack/insight/panels/sphinx_panel.rb @@ -1,11 +1,11 @@ -module Insight +module Rack::Insight class SphinxPanel < Panel - require "insight/panels/sphinx_panel/sphinx_extension" - require "insight/panels/sphinx_panel/stats" + require "rack/insight/panels/sphinx_panel/sphinx_extension" + require "rack/insight/panels/sphinx_panel/stats" def self.record(*sphinx_command_args, &block) - return block.call unless Insight.enabled? + return block.call unless Rack::Insight.enabled? start_time = Time.now result = block.call @@ -15,11 +15,11 @@ def self.record(*sphinx_command_args, &block) end def self.reset - Thread.current["insight.sphinx"] = Stats.new + Thread.current["rack-insight.sphinx"] = Stats.new end def self.stats - Thread.current["insight.sphinx"] ||= Stats.new + Thread.current["rack-insight.sphinx"] ||= Stats.new end def name diff --git a/lib/insight/panels/sphinx_panel/stats.rb b/lib/rack/insight/panels/sphinx_panel/stats.rb similarity index 99% rename from lib/insight/panels/sphinx_panel/stats.rb rename to lib/rack/insight/panels/sphinx_panel/stats.rb index 06cf27c..1d64c4c 100644 --- a/lib/insight/panels/sphinx_panel/stats.rb +++ b/lib/rack/insight/panels/sphinx_panel/stats.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class SphinxPanel class Stats diff --git a/lib/insight/panels/sql_panel.rb b/lib/rack/insight/panels/sql_panel.rb similarity index 89% rename from lib/insight/panels/sql_panel.rb rename to lib/rack/insight/panels/sql_panel.rb index 144621f..204873d 100644 --- a/lib/insight/panels/sql_panel.rb +++ b/lib/rack/insight/panels/sql_panel.rb @@ -1,11 +1,11 @@ require "digest" -module Insight +module Rack::Insight class SQLPanel < Panel - require "insight/panels/sql_panel/panel_app" - require "insight/panels/sql_panel/query" + require "rack/insight/panels/sql_panel/panel_app" + require "rack/insight/panels/sql_panel/query" def initialize(app) super diff --git a/lib/insight/panels/sql_panel/panel_app.rb b/lib/rack/insight/panels/sql_panel/panel_app.rb similarity index 87% rename from lib/insight/panels/sql_panel/panel_app.rb rename to lib/rack/insight/panels/sql_panel/panel_app.rb index 119c232..a684f48 100644 --- a/lib/insight/panels/sql_panel/panel_app.rb +++ b/lib/rack/insight/panels/sql_panel/panel_app.rb @@ -1,9 +1,9 @@ -require 'insight/panels/sql_panel/query' +require 'rack/insight/panels/sql_panel/query' -module Insight +module Rack::Insight class SQLPanel - class PanelApp < ::Insight::PanelApp + class PanelApp < ::Rack::Insight::PanelApp def dispatch case request.path_info diff --git a/lib/insight/panels/sql_panel/query.rb b/lib/rack/insight/panels/sql_panel/query.rb similarity index 96% rename from lib/insight/panels/sql_panel/query.rb rename to lib/rack/insight/panels/sql_panel/query.rb index 85f3433..9f20850 100644 --- a/lib/insight/panels/sql_panel/query.rb +++ b/lib/rack/insight/panels/sql_panel/query.rb @@ -1,8 +1,8 @@ -module Insight +module Rack::Insight class SQLPanel class QueryResult - include Insight::FilteredBacktrace + include Rack::Insight::FilteredBacktrace attr_reader :sql attr_reader :time diff --git a/lib/insight/panels/templates_panel.rb b/lib/rack/insight/panels/templates_panel.rb similarity index 93% rename from lib/insight/panels/templates_panel.rb rename to lib/rack/insight/panels/templates_panel.rb index c2c05c2..ebcae21 100644 --- a/lib/insight/panels/templates_panel.rb +++ b/lib/rack/insight/panels/templates_panel.rb @@ -1,7 +1,7 @@ -module Insight +module Rack::Insight class TemplatesPanel < Panel - require "insight/panels/templates_panel/rendering" + require "rack/insight/panels/templates_panel/rendering" def initialize(app) super diff --git a/lib/insight/panels/templates_panel/rendering.rb b/lib/rack/insight/panels/templates_panel/rendering.rb similarity index 98% rename from lib/insight/panels/templates_panel/rendering.rb rename to lib/rack/insight/panels/templates_panel/rendering.rb index b518268..ccb4d23 100644 --- a/lib/insight/panels/templates_panel/rendering.rb +++ b/lib/rack/insight/panels/templates_panel/rendering.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class TemplatesPanel class Rendering diff --git a/lib/insight/panels/timer_panel.rb b/lib/rack/insight/panels/timer_panel.rb similarity index 92% rename from lib/insight/panels/timer_panel.rb rename to lib/rack/insight/panels/timer_panel.rb index f74c9b5..b29df5a 100644 --- a/lib/insight/panels/timer_panel.rb +++ b/lib/rack/insight/panels/timer_panel.rb @@ -1,6 +1,6 @@ require 'benchmark' -module Insight +module Rack::Insight class TimerPanel < Panel def initialize(app) super @@ -28,7 +28,7 @@ def call(env) end def heading_for_request(number) - measurements = retreive(number).first + measurements = retrieve(number).first measurements.last.last end diff --git a/lib/insight/params_signature.rb b/lib/rack/insight/params_signature.rb similarity index 94% rename from lib/insight/params_signature.rb rename to lib/rack/insight/params_signature.rb index 11a8026..c9c0b05 100644 --- a/lib/insight/params_signature.rb +++ b/lib/rack/insight/params_signature.rb @@ -1,6 +1,6 @@ require "digest" -module Insight +module Rack::Insight class ParamsSignature extend ERB::Util @@ -25,7 +25,7 @@ def initialize(request) end def secret_key - @request.env['insight.secret_key'] + @request.env['rack-insight.secret_key'] end def secret_key_blank? diff --git a/lib/insight/path-filter.rb b/lib/rack/insight/path-filter.rb similarity index 76% rename from lib/insight/path-filter.rb rename to lib/rack/insight/path-filter.rb index 4f4eb15..1e52311 100644 --- a/lib/insight/path-filter.rb +++ b/lib/rack/insight/path-filter.rb @@ -1,6 +1,6 @@ -require 'insight/logger' +require 'rack/insight/logger' -module Insight +module Rack::Insight class PathFilter include Logging def initialize(app) @@ -8,7 +8,7 @@ def initialize(app) end def call(env) - filters = env['insight.path_filters'].map do |string| + filters = env['rack-insight.path_filters'].map do |string| %r{^#{string}} end diff --git a/lib/insight/public/__insight__/bookmarklet.html b/lib/rack/insight/public/__insight__/bookmarklet.html similarity index 91% rename from lib/insight/public/__insight__/bookmarklet.html rename to lib/rack/insight/public/__insight__/bookmarklet.html index 9ed8b4a..c8d2a98 100644 --- a/lib/insight/public/__insight__/bookmarklet.html +++ b/lib/rack/insight/public/__insight__/bookmarklet.html @@ -4,7 +4,7 @@