forge_ops_tracker 0.22.0 → 0.23.0

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: e7d188230dabf677fd36901f2dc5fa06087a101a2a6a1cac1254926f8908692b
4
- data.tar.gz: adf0303ee68a7f629efb58fed79b03d9b44f94f8a1be3f3b66c8192ef1a02f91
3
+ metadata.gz: da567677dfaa2cb992609ba73ca33ed0885db4e4dad2da51b225292d9aeb3fab
4
+ data.tar.gz: c26b7679f97b332c6d61864bdcbe9fdcfde34b5aa821aefb6ee05f078e90ffc5
5
5
  SHA512:
6
- metadata.gz: ca4daee44d94287061c5ca2acd2eb99e723e5e2b8703b318a13d9a756a1f378cfea3fdaf750bd29eacfb03dc8457167a7f5e81b05b772138c2325d4dde3a2802
7
- data.tar.gz: 2d4b2b0fc99fd80bf9b3dc1e8c97d958ed140e830a8a9969f990b6b92f1538960cbb951212fb341b5c4af5d4b284f8990ec5fba3148aaa588126a6aa17761b93
6
+ metadata.gz: 73d3a3b887d600e528ed3f54ecf8c388f6a4c6059974a44a784e3c56aae3836a16495c3b775af2dfa1fb9c94649637b8cab3c50a84d5062518136594a9df1061
7
+ data.tar.gz: 25e99c026b1711ad5f3f63336d49073b5c8b97207941353a47dba436b35516d75fa6ecf7ec2179dfb4523e2fc145cd1fac68bbce53ade121590aa37520a11e78
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.23.0 (2026-11-11)
4
+
5
+ - Strict privacy no longer sends the user's raw `id`, which could be a record number that identifies a
6
+ person. Set `config.privacy_user_key` (or `FORGE_OPS_PRIVACY_USER_KEY`) and the id is sent as a keyed
7
+ hash (HMAC-SHA256 with your key, which never leaves your app), so affected customers are still counted.
8
+ Without a key, no user is sent at all.
9
+
3
10
  ## 0.22.0 (2026-10-28)
4
11
 
5
12
  - `config.trace_ignore_paths`: requests whose path starts with one of these prefixes are never traced, however
data/README.md CHANGED
@@ -237,11 +237,15 @@ trace id, and the database tables or procedures involved), never free text that
237
237
  name, an email or a diagnosis:
238
238
 
239
239
  - No error message. A `message_fingerprint` is sent instead: a one-way hash of the message with
240
- its numbers, hex ids and UUIDs taken out, computed in your process, so errors still group
240
+ its emails, quoted values, numbers, hex ids and UUIDs taken out, computed in your process, so errors still group
241
241
  without the message ever leaving it.
242
242
  - No breadcrumbs (they aren't recorded at all), no `endpoint`, no SQL statement even with
243
243
  `capture_sql_statement` on, and no source context (the source file is never read).
244
- - The user is sent by `id` only, never `email` or `username`.
244
+ - The user's `email` and `username` are never sent, and neither is the raw `id`. With
245
+ `privacy_user_key` set, the id is sent as a keyed hash (HMAC-SHA256 with your key, which never
246
+ leaves your app), so ForgeOps can still count affected customers but can't read the id. Without
247
+ a key, no user is sent at all. Keep the key the same across servers and deploys, or one customer
248
+ counts as two.
245
249
  - Context and tags only keep the top-level keys you list in `privacy_allowed_fields`, and only
246
250
  when the value is a string, number or boolean. Nothing else from them is sent.
247
251
  - Failed jobs and outbound calls keep their error class, never their error message.
@@ -256,11 +260,13 @@ name, an email or a diagnosis:
256
260
  ForgeOpsTracker.configure do |config|
257
261
  config.strict_privacy = true # default false
258
262
  config.privacy_allowed_fields = %w[error_code feature] # default []
263
+ config.privacy_user_key = ENV["MY_FORGE_OPS_USER_KEY"] # default nil: no user sent
259
264
  end
260
265
  ```
261
266
 
262
- Both can also come from the environment: `FORGE_OPS_STRICT_PRIVACY=true` and
263
- `FORGE_OPS_PRIVACY_ALLOWED_FIELDS=error_code,feature` (comma separated). A value set in
267
+ All three can also come from the environment: `FORGE_OPS_STRICT_PRIVACY=true`,
268
+ `FORGE_OPS_PRIVACY_ALLOWED_FIELDS=error_code,feature` (comma separated) and
269
+ `FORGE_OPS_PRIVACY_USER_KEY=...`. A value set in
264
270
  `configure` wins over the environment.
265
271
 
266
272
  ForgeOps applies the same rules again on arrival when the project's own Strict privacy setting is
@@ -22,6 +22,7 @@ module ForgeOpsTracker
22
22
  attr_accessor :detect_changes, :track_env_var_names
23
23
  attr_accessor :strict_privacy
24
24
  attr_reader :privacy_allowed_fields
25
+ attr_accessor :privacy_user_key
25
26
 
26
27
  def initialize
27
28
  @dsn = ENV["FORGE_OPS_DSN"]
@@ -165,7 +166,7 @@ module ForgeOpsTracker
165
166
  # Off by default. On, nothing this gem sends carries free text that could hold personal or
166
167
  # health data: no error message (a message_fingerprint is sent instead, so errors still
167
168
  # group), no breadcrumbs, no request path, no SQL statement, no source context, no user email
168
- # or username, no job failure message, and outbound HTTP spans named by method and host only.
169
+ # or username, the user's id only as a keyed hash (privacy_user_key), no job failure message, and outbound HTTP spans named by method and host only.
169
170
  # See StrictPrivacy for every rule. FORGE_OPS_STRICT_PRIVACY=true turns it on from the
170
171
  # environment; setting it here wins over that.
171
172
  @strict_privacy = self.class.env_flag(ENV["FORGE_OPS_STRICT_PRIVACY"])
@@ -174,6 +175,11 @@ module ForgeOpsTracker
174
175
  # so nothing from context or tags goes out. FORGE_OPS_PRIVACY_ALLOWED_FIELDS=error_code,feature
175
176
  # sets it from the environment.
176
177
  self.privacy_allowed_fields = ENV["FORGE_OPS_PRIVACY_ALLOWED_FIELDS"].to_s.split(",")
178
+ # Strict privacy sends the user's id only as a keyed hash (StrictPrivacy.hashed_user_id) with
179
+ # this secret, which stays in your app; unset, no user is sent at all. Keep it the same
180
+ # across deploys and servers, or the same customer counts as two. FORGE_OPS_PRIVACY_USER_KEY
181
+ # sets it from the environment.
182
+ @privacy_user_key = ENV["FORGE_OPS_PRIVACY_USER_KEY"].to_s.empty? ? nil : ENV["FORGE_OPS_PRIVACY_USER_KEY"]
177
183
  end
178
184
 
179
185
  # Accepts an Array of names or one comma-separated String; always kept as stripped Strings.
@@ -63,7 +63,7 @@ module ForgeOpsTracker
63
63
  payload = scrub(payload)
64
64
  return payload unless configuration.strict_privacy
65
65
 
66
- StrictPrivacy.event(payload, allowed_fields: configuration.privacy_allowed_fields)
66
+ StrictPrivacy.event(payload, allowed_fields: configuration.privacy_allowed_fields, user_key: configuration.privacy_user_key)
67
67
  end
68
68
 
69
69
  private
@@ -1,4 +1,5 @@
1
1
  require "digest"
2
+ require "openssl"
2
3
 
3
4
  module ForgeOpsTracker
4
5
  # What Configuration#strict_privacy changes in everything this gem sends, for apps that can't let
@@ -54,23 +55,28 @@ module ForgeOpsTracker
54
55
  # always is, rather than converted byte by byte, which would turn every non-ASCII character into
55
56
  # replacement characters and hash differently from the same text arriving as UTF-8.
56
57
  def message_fingerprint(message)
57
- normalized = normalize_message(message)
58
- normalized = normalized.dup.force_encoding(Encoding::UTF_8) if normalized.encoding == Encoding::BINARY
59
- normalized = normalized.encode(Encoding::UTF_8, invalid: :replace, undef: :replace) unless normalized.encoding == Encoding::UTF_8
60
- Digest::SHA256.hexdigest(normalized.scrub)[0, FINGERPRINT_LENGTH]
58
+ Digest::SHA256.hexdigest(utf8(normalize_message(message)))[0, FINGERPRINT_LENGTH]
59
+ end
60
+
61
+ # The text's UTF-8 bytes, which is what every SDK hashes: plain bytes are relabelled as UTF-8
62
+ # (converting would replace each non-ASCII byte), anything else is converted.
63
+ def utf8(text)
64
+ text = text.dup.force_encoding(Encoding::UTF_8) if text.encoding == Encoding::BINARY
65
+ text = text.encode(Encoding::UTF_8, invalid: :replace, undef: :replace) unless text.encoding == Encoding::UTF_8
66
+ text.scrub
61
67
  end
62
68
 
63
69
  # An error event payload (EventBuilder#build's shape, symbol keys) reduced to what strict
64
70
  # privacy sends. message is sent as "" alongside message_fingerprint, exactly what the server
65
71
  # stores for a strict project.
66
- def event(payload, allowed_fields: [])
72
+ def event(payload, allowed_fields: [], user_key: nil)
67
73
  payload.reject { |key, _value| EVENT_FIELDS_DROPPED.include?(key) }.merge(
68
74
  message: "",
69
75
  message_fingerprint: message_fingerprint(payload[:message]),
70
76
  transaction_name: transaction_name(payload[:transaction_name]),
71
77
  context: allowed(payload[:context], allowed_fields),
72
78
  tags: allowed(payload[:tags], allowed_fields),
73
- user: user(payload[:user]),
79
+ user: user(payload[:user], user_key),
74
80
  backtrace: Array(payload[:backtrace]).map { |frame| frame.reject { |key, _value| SOURCE_CONTEXT_FIELDS.include?(key) } }
75
81
  ).compact
76
82
  end
@@ -167,12 +173,22 @@ module ForgeOpsTracker
167
173
  kept unless kept.empty?
168
174
  end
169
175
 
170
- # The user's id, as a string, and nothing else; nil when there's no id.
171
- def user(user)
176
+ # Only a keyed hash of the user's id (hashed_user_id), and only when the app set
177
+ # Configuration#privacy_user_key; nil otherwise. A raw id can be a record number that identifies
178
+ # a person, and an unkeyed hash of a small number can be guessed back.
179
+ def user(user, key = nil)
172
180
  return nil unless user.is_a?(Hash)
181
+ return nil if key.nil? || key.to_s.empty?
173
182
 
174
183
  id = user[:id] || user["id"]
175
- { id: id.to_s } unless id.nil? || id.to_s.strip.empty?
184
+ { id: hashed_user_id(id, key) } unless id.nil? || id.to_s.strip.empty?
185
+ end
186
+
187
+ # "h1:" and the first 32 lowercase hex characters of HMAC-SHA256 of the id's UTF-8 text, keyed
188
+ # with the app's own secret, which ForgeOps never sees. The same id hashes the same under one
189
+ # key, so affected customers can still be counted.
190
+ def hashed_user_id(id, key)
191
+ "h1:#{OpenSSL::HMAC.hexdigest("SHA256", utf8(key.to_s), utf8(id.to_s))[0, FINGERPRINT_LENGTH]}"
176
192
  end
177
193
  end
178
194
  end
@@ -1,3 +1,3 @@
1
1
  module ForgeOpsTracker
2
- VERSION = "0.22.0"
2
+ VERSION = "0.23.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forge_ops_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ForgeOps