honeybadger 6.9.1 → 6.9.2

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: 3a87b6390eaeefa3027fa561efe5c289817d3bf7785d5e9f7ba0d56bf0937141
4
+ data.tar.gz: a191e258298fbe566e6a7914fef8647f3b3dfb3c0ab83dfa0aaa1689ba4f30d7
5
5
  SHA512:
6
- metadata.gz: 2e7434371e4456bfd1b0f8f51f540006852d3f6a776ae98b5e9b795ef6463849767a45df0eb1b9c0d5b96e8dcd99ed5e5b93a0cd77ce9226bc0a571311fee00c
7
- data.tar.gz: 4bbbf5016c7732302bf20f99ec52190be16e5ab14ef6cc54203afe7b96280c61d0d465439d49ed29e57907ed8ebd999ea39ffd13931a44afc1384e6d8c7b1c98
6
+ metadata.gz: dd5b1e3392c7d74312d66bf50a9a80ae7534526a717fbc68e851283bd0ff02f2f9d578bd6730b32364d4e9ca1dd1b3031e52191aa148c1da72634733c9a3a16b
7
+ data.tar.gz: f3c484065df9a52ef468140d725681238cf8701a5bf819f80fd06e36b0f515eea94245d42ab9682c44801ede8036fe227b7b546deca7c90fb2fa7bd0cf28790e
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Change Log
2
2
 
3
3
 
4
+ ## [6.9.2](https://github.com/honeybadger-io/honeybadger-ruby/compare/v6.9.1...v6.9.2) (2026-09-15)
5
+
6
+
7
+ ### Bug Fixes
8
+
9
+ * 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))
10
+
4
11
  ## [6.9.1](https://github.com/honeybadger-io/honeybadger-ruby/compare/v6.9.0...v6.9.1) (2026-07-16)
5
12
 
6
13
 
@@ -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,
@@ -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
@@ -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.2".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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Honeybadger Industries LLC
@@ -217,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
217
  - !ruby/object:Gem::Version
218
218
  version: "0"
219
219
  requirements: []
220
- rubygems_version: 4.1.0.dev
220
+ rubygems_version: 4.1.0.beta1
221
221
  specification_version: 4
222
222
  summary: "Full-stack error tracking, performance monitoring, logging, and more."
223
223
  test_files: []