honeybadger 6.9.1 → 6.9.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 938bd913b16cb752020a666aa009ecf5fced36cf55fa1d9ffc2078857af14690
4
- data.tar.gz: 5829e029bdad75d2ce531f41b228c333246fa904fa4af1030bae9c5c29be9ad0
3
+ metadata.gz: fe7e1dc021b03b75e886083cda940bd73ac4613427229e0b9a08c4e65badf548
4
+ data.tar.gz: ea2e996262898454537f1e65e394d4d1cd93226420dab1d0d66ad8b408cac200
5
5
  SHA512:
6
- metadata.gz: 2e7434371e4456bfd1b0f8f51f540006852d3f6a776ae98b5e9b795ef6463849767a45df0eb1b9c0d5b96e8dcd99ed5e5b93a0cd77ce9226bc0a571311fee00c
7
- data.tar.gz: 4bbbf5016c7732302bf20f99ec52190be16e5ab14ef6cc54203afe7b96280c61d0d465439d49ed29e57907ed8ebd999ea39ffd13931a44afc1384e6d8c7b1c98
6
+ metadata.gz: 8ae65e4be79d6ed5761b54139488681f1d5a591f8a5f1b44185e17d4322120f2a280055704a1a56e5e0836bb12f2dcf2c91372f9e0c0c9b06a488e69089fd7ce
7
+ data.tar.gz: 8ac9bb344ab71c34de08a8eefb3bb7dc2393d7c29d6f59f6cbe289d6c428a699cc679d599088d2d6c87f8e1a6de9069cc079f156b272385299e25b2e81361002
data/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Change Log
2
2
 
3
3
 
4
+ ## [6.9.3](https://github.com/honeybadger-io/honeybadger-ruby/compare/v6.9.2...v6.9.3) (2026-09-29)
5
+
6
+
7
+ ### Bug Fixes
8
+
9
+ * propagate the Rails request ID to notices and Insights events ([#848](https://github.com/honeybadger-io/honeybadger-ruby/issues/848)) ([23edb08](https://github.com/honeybadger-io/honeybadger-ruby/commit/23edb08f4fda3b3f66fb697c5ec5502f39aeb127))
10
+
11
+ ## [6.9.2](https://github.com/honeybadger-io/honeybadger-ruby/compare/v6.9.1...v6.9.2) (2026-09-15)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * truncate very large SQL queries instead of obfuscating them ([#841](https://github.com/honeybadger-io/honeybadger-ruby/issues/841)) ([c80e046](https://github.com/honeybadger-io/honeybadger-ruby/commit/c80e0468ee167496ba7f5798aca2974463cf1af2))
17
+
4
18
  ## [6.9.1](https://github.com/honeybadger-io/honeybadger-ruby/compare/v6.9.0...v6.9.1) (2026-07-16)
5
19
 
6
20
 
@@ -579,13 +579,18 @@ module Honeybadger
579
579
  # @api private
580
580
  def with_rack_env(rack_env, &block)
581
581
  context_manager.set_rack_env(rack_env)
582
- context_manager.set_request_id(rack_env["action_dispatch.request_id"] || SecureRandom.uuid)
582
+ context_manager.set_request_id(SecureRandom.uuid)
583
583
  yield
584
584
  ensure
585
585
  context_manager.set_rack_env(nil)
586
586
  context_manager.set_request_id(nil)
587
587
  end
588
588
 
589
+ # @api private
590
+ def set_request_id(request_id)
591
+ context_manager.set_request_id(request_id)
592
+ end
593
+
589
594
  # @api private
590
595
  attr_reader :worker, :events_worker, :metrics_worker
591
596
 
@@ -20,14 +20,15 @@ module Honeybadger
20
20
  if data[:sql]
21
21
  connection = data.delete(:connection)
22
22
  adapter = connection&.adapter_name&.downcase || active_record_connection_db_config[:adapter]
23
- data[:sql] = Util::SQL.obfuscate(data[:sql], adapter)
23
+ data[:sql] = Util::SQL.obfuscate(data[:sql], adapter, max_length: Honeybadger.config[:"sql.max_length"])
24
24
  end
25
25
  data
26
26
  end,
27
27
  exclude_when: lambda do |data|
28
- # Ignore schema, begin, and commit transaction queries
28
+ # Ignore schema, begin, and commit transaction queries. Those
29
+ # statements are tiny, so skip the scan for large queries.
29
30
  data[:name] == "SCHEMA" ||
30
- (data[:sql] && (Util::SQL.force_utf_8(data[:sql].dup) =~ /^(begin|commit)( immediate)?( transaction)?$/i))
31
+ (data[:sql] && data[:sql].bytesize <= 64 && (Util::SQL.force_utf_8(data[:sql].dup) =~ /^(begin|commit)( immediate)?( transaction)?$/i))
31
32
  end
32
33
  },
33
34
 
@@ -34,7 +34,7 @@ module Honeybadger
34
34
 
35
35
  IGNORE_EVENTS_DEFAULT = [
36
36
  {event_type: "sql.active_record", query: /^(begin|commit)( immediate)?( transaction)?$/i},
37
- {event_type: "sql.active_record", query: /(solid_queue|good_job|solid_cable_messages)/i},
37
+ {event_type: "sql.active_record", query: /(solid_queue|solid_cache|good_job|solid_cable_messages)/i},
38
38
  {event_type: "sql.active_record", name: /^GoodJob/},
39
39
  {event_type: "process_action.action_controller", controller: "Rails::HealthController"},
40
40
  {event_type: "cache_read.active_support"},
@@ -153,6 +153,11 @@ module Honeybadger
153
153
  default: 100,
154
154
  type: Integer
155
155
  },
156
+ "sql.max_length": {
157
+ description: "SQL queries larger than this many bytes are truncated instead of obfuscated (in Insights events and breadcrumbs). Scanning very large queries is slow and can exceed Regexp.timeout.",
158
+ default: 1_000_000,
159
+ type: Integer
160
+ },
156
161
  plugins: {
157
162
  description: "An optional list of plugins to load. Default is to load all plugins.",
158
163
  default: nil,
@@ -2,6 +2,7 @@ require "rails"
2
2
  require "yaml"
3
3
 
4
4
  require "honeybadger/ruby"
5
+ require "honeybadger/rack/request_id"
5
6
 
6
7
  module Honeybadger
7
8
  module Init
@@ -14,8 +15,14 @@ module Honeybadger
14
15
  initializer "honeybadger.install_middleware" do |app|
15
16
  honeybadger_config = Honeybadger::Agent.instance.config
16
17
 
17
- if honeybadger_config[:"exceptions.enabled"]
18
+ # ErrorNotifier also sets up the request context that Insights events
19
+ # read. Agent#notify does nothing when exceptions are disabled.
20
+ if honeybadger_config[:"exceptions.enabled"] || honeybadger_config[:"insights.enabled"]
18
21
  app.config.middleware.insert(0, Honeybadger::Rack::ErrorNotifier)
22
+ app.config.middleware.insert_after(::ActionDispatch::RequestId, Honeybadger::Rack::RequestId)
23
+ end
24
+
25
+ if honeybadger_config[:"exceptions.enabled"]
19
26
  app.config.middleware.insert_before(Honeybadger::Rack::ErrorNotifier, Honeybadger::Rack::UserInformer) if honeybadger_config[:"user_informer.enabled"]
20
27
  app.config.middleware.insert_before(Honeybadger::Rack::ErrorNotifier, Honeybadger::Rack::UserFeedback) if honeybadger_config[:"feedback.enabled"]
21
28
  end
@@ -20,6 +20,9 @@ module Honeybadger
20
20
 
21
21
  record(name, payload)
22
22
  record_metrics(name, payload)
23
+ rescue => e
24
+ # Instrumentation must never break the instrumented code.
25
+ Honeybadger.config.logger.error("Error in Honeybadger instrumentation for #{name}: #{e.class}: #{e.message}")
23
26
  end
24
27
 
25
28
  def record(name, payload)
@@ -116,7 +119,7 @@ module Honeybadger
116
119
  class ActiveRecordSubscriber < RailsSubscriber
117
120
  def format_payload(_name, payload)
118
121
  {
119
- query: Util::SQL.obfuscate(payload[:sql], payload[:connection]&.adapter_name),
122
+ query: Util::SQL.obfuscate(payload[:sql], payload[:connection]&.adapter_name, max_length: Honeybadger.config[:"sql.max_length"]),
120
123
  cached: payload[:cached],
121
124
  async: payload[:async]
122
125
  }
@@ -100,6 +100,9 @@ module Honeybadger
100
100
  category: notification_config[:category] || :custom,
101
101
  metadata: data
102
102
  )
103
+ rescue => e
104
+ # Instrumentation must never break the instrumented code.
105
+ Honeybadger.config.logger.error("Error in Honeybadger breadcrumb for #{name}: #{e.class}: #{e.message}")
103
106
  end
104
107
 
105
108
  # @api private
@@ -0,0 +1,27 @@
1
+ require "honeybadger/ruby"
2
+
3
+ module Honeybadger
4
+ module Rack
5
+ # @api private
6
+ #
7
+ # Copies the request ID assigned by ActionDispatch::RequestId into the
8
+ # Honeybadger context. Must sit after ActionDispatch::RequestId in the
9
+ # middleware stack.
10
+ #
11
+ # No ensure/cleanup here: ErrorNotifier owns the request lifecycle and
12
+ # clears state after the stack unwinds. Clearing here would nil the ID
13
+ # before ErrorNotifier builds the notice on exception.
14
+ class RequestId
15
+ def initialize(app, agent = nil)
16
+ @app = app
17
+ @agent = agent if agent.is_a?(Agent)
18
+ end
19
+
20
+ def call(env)
21
+ request_id = env["action_dispatch.request_id"]
22
+ (@agent || Honeybadger::Agent.instance).set_request_id(request_id) if request_id
23
+ @app.call(env)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -4,20 +4,48 @@ module Honeybadger
4
4
  ESCAPE_QUOTES = /(\\"|\\')/
5
5
  SQUOTE_DATA = /'(?:[^']|'')*'/
6
6
  DQUOTE_DATA = /"(?:[^"]|"")*"/
7
- NUMBER_DATA = /\b\d+\b/
7
+ # Underscore separators are allowed in numeric literals by PostgreSQL
8
+ # 16+ and SQLite 3.46+, and \b does not match next to one.
9
+ NUMBER_DATA = /\b\d+(?:_\d+)*\b/
10
+ HEX_DATA = /\b0[xbo][0-9a-f]+(?:_[0-9a-f]+)*\b/i
8
11
  DOUBLE_QUOTERS = /(postgres|sqlite|postgis)/i
12
+ TRUNCATED_HEAD_LENGTH = 200
13
+ # Leading run of characters that can't start a string literal or a
14
+ # comment in any supported adapter: stops at ', $, /, -, #, \ and so
15
+ # on. Double quotes and backticks are kept because they quote
16
+ # identifiers; adapters that use double quotes for strings are cut
17
+ # at the first double quote in .truncate.
18
+ TRUNCATED_HEAD_SAFE = /\A[\w\s.,()=*"`]*/
9
19
 
10
- def self.obfuscate(sql, adapter)
11
- force_utf_8(sql.to_s.dup).tap do |s|
20
+ # Obfuscates literal values in a SQL query. When +max_length+ is given
21
+ # and the query is larger than that many bytes, the query is truncated
22
+ # instead (see .truncate): scanning multi-megabyte queries (e.g. an
23
+ # INSERT of a serialized cache value) is slow, and can exceed the
24
+ # Regexp.timeout that Rails 8.1+ sets by default.
25
+ def self.obfuscate(sql, adapter, max_length: nil)
26
+ sql = sql.to_s
27
+ return truncate(sql, adapter, max_length) if max_length && sql.bytesize > max_length
28
+
29
+ force_utf_8(sql.dup).tap do |s|
12
30
  s.gsub!(/\s+/, " ")
13
31
  s.gsub!(ESCAPE_QUOTES, "".freeze)
14
32
  s.gsub!(SQUOTE_DATA, "'?'".freeze)
15
33
  s.gsub!(DQUOTE_DATA, '"?"'.freeze) unless adapter.to_s.match?(DOUBLE_QUOTERS)
34
+ s.gsub!(HEX_DATA, "?".freeze)
16
35
  s.gsub!(NUMBER_DATA, "?".freeze)
17
36
  s.strip!
18
37
  end
19
38
  end
20
39
 
40
+ # Keeps only the head of the statement (up to the first quoted value or
41
+ # comment) so that no literal data leaks, and notes the original size.
42
+ def self.truncate(sql, adapter, max_length)
43
+ head = force_utf_8(sql.byteslice(0, TRUNCATED_HEAD_LENGTH)).scrub("")[TRUNCATED_HEAD_SAFE]
44
+ head = head[0, head.index('"')] if head.include?('"') && !adapter.to_s.match?(DOUBLE_QUOTERS)
45
+
46
+ "#{obfuscate(head, adapter)} ... [truncated #{sql.bytesize} bytes]"
47
+ end
48
+
21
49
  def self.force_utf_8(string)
22
50
  string.encode(
23
51
  Encoding.find("UTF-8"),
@@ -1,4 +1,4 @@
1
1
  module Honeybadger
2
2
  # The current String Honeybadger version.
3
- VERSION = "6.9.1".freeze
3
+ VERSION = "6.9.3".freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: honeybadger
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.9.1
4
+ version: 6.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Honeybadger Industries LLC
@@ -131,6 +131,7 @@ files:
131
131
  - lib/honeybadger/plugins/thor.rb
132
132
  - lib/honeybadger/plugins/warden.rb
133
133
  - lib/honeybadger/rack/error_notifier.rb
134
+ - lib/honeybadger/rack/request_id.rb
134
135
  - lib/honeybadger/rack/user_feedback.rb
135
136
  - lib/honeybadger/rack/user_informer.rb
136
137
  - lib/honeybadger/registry.rb
@@ -217,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
218
  - !ruby/object:Gem::Version
218
219
  version: "0"
219
220
  requirements: []
220
- rubygems_version: 4.1.0.dev
221
+ rubygems_version: 4.1.0.beta1
221
222
  specification_version: 4
222
223
  summary: "Full-stack error tracking, performance monitoring, logging, and more."
223
224
  test_files: []