rails-profiler 0.44.21 → 0.44.23

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.
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "mcp"
4
+ require "net/http"
4
5
  require_relative "http_guard"
5
6
 
6
7
  module Profiler
@@ -467,7 +468,7 @@ module Profiler
467
468
  ::MCP::Tool.define(name: name, description: description, input_schema: input_schema) do |server_context: nil, **args|
468
469
  result = handler.call(args.transform_keys(&:to_s))
469
470
  result.is_a?(::MCP::Tool::Response) ? result : ::MCP::Tool::Response.new(result)
470
- rescue Profiler::Storage::Unavailable::Error, Profiler::Error => e
471
+ rescue Profiler::Storage::Unavailable::Error, Profiler::Error, SystemCallError, Net::OpenTimeout, Net::ReadTimeout => e
471
472
  ::MCP::Tool::Response.new([{ type: "text", text: e.message }], error: true)
472
473
  end
473
474
  end
@@ -400,9 +400,10 @@ module Profiler
400
400
  if http_data["requests"] && !http_data["requests"].empty?
401
401
  lines << "### Request List"
402
402
  http_data["requests"].each_with_index do |req, index|
403
- flag = req["duration"] >= threshold ? " [SLOW]" : ""
404
- err = req["status"] >= 400 || req["status"] == 0 ? " [ERROR]" : ""
405
- lines << "\n**#{index + 1}. #{req['method']} #{req['url']}** - #{req['status'] == 0 ? 'error' : req['status']} - #{req['duration'].round(2)} ms#{flag}#{err}"
403
+ flag = (req["duration"] || 0).to_f >= threshold ? " [SLOW]" : ""
404
+ status = req["status"].to_i
405
+ err = status >= 400 || status == 0 ? " [ERROR]" : ""
406
+ lines << "\n**#{index + 1}. #{req['method']} #{req['url']}** - #{status == 0 ? 'error' : status} - #{(req['duration'] || 0).to_f.round(2)} ms#{flag}#{err}"
406
407
 
407
408
  if req["request_body"] && !req["request_body"].empty?
408
409
  lines << "**Request Body:**"
@@ -76,15 +76,16 @@ module Profiler
76
76
  if requests && !requests.empty?
77
77
  lines << "## Request Details"
78
78
  requests.each_with_index do |req, i|
79
- slow_flag = req["duration"] >= threshold ? " [SLOW]" : ""
80
- err_flag = req["status"] >= 400 || req["status"] == 0 ? " [ERROR]" : ""
79
+ slow_flag = (req["duration"] || 0).to_f >= threshold ? " [SLOW]" : ""
80
+ status = req["status"].to_i
81
+ err_flag = status >= 400 || status == 0 ? " [ERROR]" : ""
81
82
  lines << "\n### Request #{i + 1}#{slow_flag}#{err_flag}"
82
83
  lines << "- **ID:** #{req['id']}" if req["id"]
83
84
  lines << "- **Started at:** #{req['started_at']}" if req["started_at"]
84
85
  lines << "- **Method:** #{req['method']}"
85
86
  lines << "- **URL:** #{req['url']}"
86
- lines << "- **Status:** #{req['status'] == 0 ? 'connection error' : req['status']}"
87
- lines << "- **Duration:** #{req['duration'].round(2)} ms"
87
+ lines << "- **Status:** #{status == 0 ? 'connection error' : status}"
88
+ lines << "- **Duration:** #{(req['duration'] || 0).to_f.round(2)} ms"
88
89
  lines << "- **Request Size:** #{req['request_size'].nil? ? 'unknown' : "#{'at least ' if req['request_size_is_minimum']}#{req['request_size']} bytes"}"
89
90
  lines << "- **Response Size:** #{req['response_size']} bytes"
90
91
  if req["request_body_not_captured"]
@@ -86,7 +86,7 @@ namespace :profiler do
86
86
  task mcp: :environment do
87
87
  require_relative "../mcp/server"
88
88
 
89
- transport = ENV["MCP_TRANSPORT"]&.to_sym || Profiler.configuration.mcp_transport
89
+ transport = ENV["MCP_TRANSPORT"]&.to_sym || :stdio
90
90
  $stderr.puts "Starting Profiler MCP server (#{transport} transport)..."
91
91
 
92
92
  server = Profiler::MCP::Server.new
@@ -165,11 +165,11 @@ module Profiler
165
165
  Profiler::TestRunner.run_store.update(run.id, pid: io.pid)
166
166
 
167
167
  begin
168
- while (chunk = io.read(256))
169
- break if chunk.empty?
170
-
168
+ while (chunk = io.readpartial(4096))
171
169
  Profiler::TestRunner.run_store.append_output(run.id, chunk)
172
170
  end
171
+ rescue EOFError
172
+ # End of stream reached
173
173
  ensure
174
174
  # The process printed everything, killed or not: what was held back can be shown.
175
175
  Profiler::TestRunner.run_store.finish_output(run.id)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Profiler
4
- VERSION = "0.44.21"
4
+ VERSION = "0.44.23"
5
5
 
6
6
  GEM_ROOT = File.expand_path("../..", __dir__)
7
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.44.21
4
+ version: 0.44.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Duplessy