debugbar 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/app/controllers/debugbar/polling_controller.rb +23 -0
- data/app/helpers/debugbar/tag_helpers.rb +7 -0
- data/build_demo.sh +13 -0
- data/build_fixtures.rb +32 -0
- data/config/routes.rb +4 -1
- data/lib/debugbar/buffers/request_buffer.rb +0 -15
- data/lib/debugbar/engine.rb +3 -1
- data/lib/debugbar/middlewares/quiet_routes.rb +23 -0
- data/lib/debugbar/middlewares/track_current_request.rb +5 -2
- data/lib/debugbar/version.rb +1 -1
- data/lib/debugbar.rb +12 -4
- data/public/debugbar.js +18 -18
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d27d82c0937dc9a2ca971fd88759a82cfafc559dc8401983b4204b2d09d13f8
|
4
|
+
data.tar.gz: b9a9c4e3e202e6abb49b5ff60656bcf3ca24c918fc6c06fb85f10cb247712268
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f8063ca1547cf52310b078ed206fe4b58f96b24366796ef0d20c04e990d332cdfde512da0b40e5a99bb21a3e9e7e51e0ece460eb3a064c9e60004c928529ae9
|
7
|
+
data.tar.gz: 713327fb6e02c53566063b2232ee1aa82770b7784e54b5d852cdde46f5a31a743c9305e2e4a8bdf945267271cbeef3db3991b4a8bb9c688d1c903d5eb8c04d64
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## v0.2.0 - 2024-02-28
|
4
|
+
|
5
|
+
* Introduce polling in case someone cannot use ActiveCable - See [8b262be7](https://github.com/julienbourdeau/debugbar/commit/8b262be7b644c7b587a6c3348bb02076053a344f)
|
6
|
+
* https://debugbar.dev/docs/polling-mode
|
7
|
+
* Show more timings information (total time, DB runtime and CPU time) - See [c02531ed](https://github.com/julienbourdeau/debugbar/commit/c02531ed6e9d9c74df11d4d8c30e3fb7bf970852)
|
8
|
+
* Move main middleware higher in the chain - See [7ca51c10](https://github.com/julienbourdeau/debugbar/commit/7ca51c10c5999f7ad14a303c92083614551de134)
|
9
|
+
* Silence debugbar routes for quieter logs - See [efe491bd](https://github.com/julienbourdeau/debugbar/commit/efe491bde9e0544e5fb891597bb2af47854c1169)
|
10
|
+
|
11
|
+
### Breaking changes
|
12
|
+
|
13
|
+
The frontend configuration was slightly modified. If you customized the prefix for the debugbar routes or the channelName, you must update your config.
|
14
|
+
Prefix is at the root, and channelName is nested under the cable key.
|
15
|
+
|
16
|
+
```diff
|
17
|
+
- <%= debugbar_javascript channelName: "something_else", cable: {prefix: "custom-prefix"} %>
|
18
|
+
+ <%= debugbar_javascript prefix: "custom-prefix", cable: {channelName: "something_else"} %>
|
19
|
+
```
|
20
|
+
|
21
|
+
## v0.1.0 - 2024-02-13
|
22
|
+
|
23
|
+
* Initial release 🎉
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Debugbar
|
2
|
+
class PollingController < ApplicationController
|
3
|
+
skip_before_action :verify_authenticity_token, only: [:confirm]
|
4
|
+
before_action :cors_set_access_control_headers
|
5
|
+
|
6
|
+
def poll
|
7
|
+
render json: RequestBuffer.all.map(&:to_h)
|
8
|
+
end
|
9
|
+
|
10
|
+
def confirm
|
11
|
+
RequestBuffer.remove params[:ids]
|
12
|
+
head :ok
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def cors_set_access_control_headers
|
18
|
+
response.headers['Access-Control-Allow-Origin'] = '*'
|
19
|
+
response.headers['Access-Control-Allow-Headers'] = 'Content-Type'
|
20
|
+
response.headers['Access-Control-Allow-Methods'] = 'POST, GET'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,5 +1,12 @@
|
|
1
1
|
module Debugbar::TagHelpers
|
2
2
|
def debugbar_javascript(opt = {})
|
3
|
+
opt = ActiveSupport::HashWithIndifferentAccess.new(opt)
|
4
|
+
|
5
|
+
# See https://github.com/julienbourdeau/debugbar/issues/8
|
6
|
+
if !defined?(ActionCable) && opt[:mode].nil?
|
7
|
+
opt[:mode] = 'poll'
|
8
|
+
end
|
9
|
+
|
3
10
|
html = <<-HTML
|
4
11
|
<div id="__debugbar"></div>
|
5
12
|
HTML
|
data/build_demo.sh
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
ruby ./build_fixtures.rb
|
4
|
+
rm -rf client/dist-demo
|
5
|
+
(cd client/ && VITE_DEMO_MODE=true npm run build)
|
6
|
+
|
7
|
+
if [ -d "../debugbar.dev/source/assets/debugbar" ]; then
|
8
|
+
echo
|
9
|
+
echo "debugbar.dev found in parent directory"
|
10
|
+
echo " -> Copying assets"
|
11
|
+
rm -f ../debugbar.dev/source/assets/debugbar/*
|
12
|
+
cp ./client/dist-demo/assets/* ../debugbar.dev/source/assets/debugbar/
|
13
|
+
fi
|
data/build_fixtures.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
fixtures_dir = File.expand_path('../fixtures/requests', __FILE__)
|
5
|
+
|
6
|
+
puts "Deleting old fixtures in #{fixtures_dir}"
|
7
|
+
Dir.glob("#{fixtures_dir}/*").each { |p| File.delete(p) }
|
8
|
+
|
9
|
+
Net::HTTP.start('127.0.0.1', 3000) do |http|
|
10
|
+
[
|
11
|
+
'/post-list',
|
12
|
+
'/slow-page',
|
13
|
+
'/random',
|
14
|
+
'/post/240',
|
15
|
+
'/api/jobs?name=refresh&post_id=123',
|
16
|
+
'/api/jobs?name=send_email&post_id=123',
|
17
|
+
'/api/errors?code=500',
|
18
|
+
].each do |path|
|
19
|
+
puts "Requesting #{path}"
|
20
|
+
http.request Net::HTTP::Get.new(path)
|
21
|
+
sleep 0.5
|
22
|
+
end
|
23
|
+
|
24
|
+
puts "Requesting debugbar data"
|
25
|
+
response = http.request Net::HTTP::Get.new('/_debugbar/poll')
|
26
|
+
data = JSON.parse(response.body)
|
27
|
+
data.each_with_index do |item, idx|
|
28
|
+
name = ("%03d" % (idx +1)) + '-' + item['meta']['controller'] + '-' + item['meta']['action']
|
29
|
+
File.write("#{fixtures_dir}/#{name}.json", JSON.pretty_generate(item))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
Debugbar::Engine.routes.draw do
|
2
2
|
mount ActionCable.server => '/cable'
|
3
3
|
|
4
|
-
|
4
|
+
get 'poll' => "polling#poll"
|
5
|
+
options 'poll/confirm' => "polling#confirm"
|
6
|
+
post 'poll/confirm' => "polling#confirm"
|
7
|
+
|
5
8
|
get 'assets/script' => "assets#js"
|
6
9
|
end
|
@@ -2,24 +2,9 @@ module Debugbar
|
|
2
2
|
class RequestBuffer
|
3
3
|
class << self
|
4
4
|
def init(adapter)
|
5
|
-
@enabled = false
|
6
5
|
@adapter = adapter
|
7
6
|
end
|
8
7
|
|
9
|
-
def enable!
|
10
|
-
@enabled = true
|
11
|
-
send_all
|
12
|
-
end
|
13
|
-
|
14
|
-
def disable!
|
15
|
-
@enabled = false
|
16
|
-
end
|
17
|
-
|
18
|
-
def send_all
|
19
|
-
data = @collection.values.map(&:to_h)
|
20
|
-
ActionCable.server.broadcast("debugbar_channel", data)
|
21
|
-
end
|
22
|
-
|
23
8
|
%w(push each all remove clear!).each do |name|
|
24
9
|
define_method(name) do |*args, &block|
|
25
10
|
ret = @adapter.send(name, *args, &block)
|
data/lib/debugbar/engine.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'config'
|
2
|
+
require_relative 'middlewares/quiet_routes'
|
2
3
|
require_relative 'middlewares/track_current_request'
|
3
4
|
require_relative '../../app/helpers/debugbar/tag_helpers'
|
4
5
|
|
@@ -37,7 +38,8 @@ module Debugbar
|
|
37
38
|
|
38
39
|
initializer 'debugbar.inject_middlewares' do |app|
|
39
40
|
next unless Debugbar.config.enabled?
|
40
|
-
app.middleware.insert_after ActionDispatch::
|
41
|
+
app.middleware.insert_after ActionDispatch::Executor, Debugbar::TrackCurrentRequest
|
42
|
+
app.middleware.insert_after Sprockets::Rails::QuietAssets, Debugbar::QuietRoutes
|
41
43
|
end
|
42
44
|
|
43
45
|
initializer 'debugbar.subscribe' do
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# This middleware silences the Rails logger for requests to the Debugbar routes.
|
2
|
+
# The poll route can be *very* noisy.
|
3
|
+
# Rails already does this for the /assets route, see Sprockets::Rails::QuietAssets.
|
4
|
+
#
|
5
|
+
# @see Sprockets::Rails::QuietAssets
|
6
|
+
# @see Rails::Rack::Logger#silence
|
7
|
+
#
|
8
|
+
module Debugbar
|
9
|
+
class QuietRoutes
|
10
|
+
def initialize(app)
|
11
|
+
@app = app
|
12
|
+
@route_regex = %r(\A/{0,2}#{::Debugbar.config.prefix})
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
if env['PATH_INFO'] =~ @route_regex
|
17
|
+
::Rails.logger.silence { @app.call(env) }
|
18
|
+
else
|
19
|
+
@app.call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -9,12 +9,15 @@ module Debugbar
|
|
9
9
|
|
10
10
|
return @app.call(env) if Debugbar::Current.ignore?
|
11
11
|
|
12
|
-
Debugbar::Current.new_request!(
|
12
|
+
Debugbar::Current.new_request!(SecureRandom.uuid)
|
13
13
|
|
14
14
|
res = @app.call(env)
|
15
15
|
|
16
16
|
# TODO: Remove this if statement?
|
17
|
-
|
17
|
+
# We check meta because the frontend doesn't support request without meta yet.
|
18
|
+
# It might happen with ActionController::Live where the following code
|
19
|
+
# will run BEFORE ActionControllerEventSubscriber.process_action is called
|
20
|
+
if Debugbar::Current.request&.meta
|
18
21
|
# filename = "#{Time.now.to_i}--#{Debugbar::Current.request.meta.dig(:params, :controller)}_#{Debugbar::Current.request.meta.dig(:params, :action).gsub('/', '_')}.json"
|
19
22
|
# File.open(Rails.root.join('_requests', filename), "w") do |f|
|
20
23
|
# f.write(Debugbar::Current.request.to_json)
|
data/lib/debugbar/version.rb
CHANGED
data/lib/debugbar.rb
CHANGED
@@ -16,17 +16,25 @@ module Debugbar
|
|
16
16
|
|
17
17
|
SETTERS.each do |m|
|
18
18
|
define_method("#{m}=") do |val|
|
19
|
-
if Current.
|
19
|
+
return if Debugbar::Current.ignore?
|
20
|
+
|
21
|
+
if Current.request
|
22
|
+
return Current.request.send("#{m}=", val)
|
23
|
+
end
|
24
|
+
|
25
|
+
if Current.request.nil? && ENV["DEBUGBAR_VERBOSE_MODE"] == "true"
|
20
26
|
# TODO: Much, much better logging needed
|
21
|
-
puts "The current request is not set yet. Was trying to set #{m}=
|
22
|
-
|
23
|
-
|
27
|
+
puts "The current request is not set yet. Was trying to set #{m} = #{val.class.name}."
|
28
|
+
pp val
|
29
|
+
nil
|
24
30
|
end
|
25
31
|
end
|
26
32
|
end
|
27
33
|
|
28
34
|
METHODS.each do |m|
|
29
35
|
define_method(m) do |*args, &block|
|
36
|
+
return if Debugbar::Current.ignore?
|
37
|
+
|
30
38
|
if Current.request
|
31
39
|
return Current.request.send(m, *args, &block)
|
32
40
|
end
|