forge_ops_tracker 0.20.0 → 0.22.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: d0c84fc309e7191793314f8b54488442383610eefe41df5f793cbfeb660bd9d5
4
- data.tar.gz: e0cb23777cadde88f2c47180d86beede097d904f592e344b20703c4cc1a19541
3
+ metadata.gz: e7d188230dabf677fd36901f2dc5fa06087a101a2a6a1cac1254926f8908692b
4
+ data.tar.gz: adf0303ee68a7f629efb58fed79b03d9b44f94f8a1be3f3b66c8192ef1a02f91
5
5
  SHA512:
6
- metadata.gz: d0be76c8e1855c31d3949e7c8ef337bf90a34067c78be75c30498a8b0624083c2df69a61ecae76f793cfe15e30552ca66410dc2a527a6d18768760247621573b
7
- data.tar.gz: 7345a1130c32bc7cc8a261d2c1d0f3940edf3b92f99a8472521211805d6a282a65e445d6b03e12819516b89537c292c8fe9f0800a9117afb944073b3f465044d
6
+ metadata.gz: ca4daee44d94287061c5ca2acd2eb99e723e5e2b8703b318a13d9a756a1f378cfea3fdaf750bd29eacfb03dc8457167a7f5e81b05b772138c2325d4dde3a2802
7
+ data.tar.gz: 2d4b2b0fc99fd80bf9b3dc1e8c97d958ed140e830a8a9969f990b6b92f1538960cbb951212fb341b5c4af5d4b284f8990ec5fba3148aaa588126a6aa17761b93
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.22.0 (2026-10-28)
4
+
5
+ - `config.trace_ignore_paths`: requests whose path starts with one of these prefixes are never traced, however
6
+ slow, for health checks or anything else not worth a trace.
7
+
8
+ ## 0.21.0 (2026-10-23)
9
+
10
+ - PII scrubbing catches card numbers however they're grouped (bare, 4-4-4-4, Amex's 4-6-5, or next to a
11
+ security code) when the digits have a card network's prefix and pass the Luhn check, so long ids stay
12
+ readable; IBANs, compact or in groups of four, by their own check digits; and fields named `iban`,
13
+ `account_number`, `routing_number` or `bank_account`. The rules are in sdks/PII_SCRUBBING.md, the same in
14
+ every SDK.
15
+
3
16
  ## 0.20.0 (2026-10-22)
4
17
 
5
18
  - Strict privacy: the message fingerprint now also replaces email addresses with `<email>` and quoted
data/README.md CHANGED
@@ -446,6 +446,7 @@ A fast, successful request never sends anything.
446
446
  ForgeOpsTracker.configure do |config|
447
447
  config.track_tracing = false # opt out of recording spans entirely
448
448
  config.trace_capture_threshold_ms = 500 # default 1000
449
+ config.trace_ignore_paths = [ "/health" ] # never trace requests under these path prefixes
449
450
  end
450
451
  ```
451
452
 
@@ -16,7 +16,7 @@ module ForgeOpsTracker
16
16
  attr_accessor :track_failures, :failure_event_flush_interval
17
17
  attr_accessor :metric_flush_interval, :infrastructure_metric_flush_interval
18
18
  attr_accessor :gauge_poll_interval
19
- attr_accessor :track_tracing, :trace_capture_threshold_ms
19
+ attr_accessor :track_tracing, :trace_capture_threshold_ms, :trace_ignore_paths
20
20
  attr_accessor :explain_slow_queries, :explain_threshold_ms
21
21
  attr_accessor :propagate_traces, :trace_propagation_targets
22
22
  attr_accessor :detect_changes, :track_env_var_names
@@ -129,6 +129,10 @@ module ForgeOpsTracker
129
129
  # PerformanceSample-derived threshold elsewhere in this gem: those describe a trend across
130
130
  # many requests, this describes a single one being outright slow.
131
131
  @trace_capture_threshold_ms = 1_000
132
+ # Requests whose path starts with one of these are never traced at all. For an app that
133
+ # reports to itself (ForgeOps on ForgeOps), its own ingestion endpoints: storing a slow trace
134
+ # is a slow request, whose trace would be sent back to be stored, and so on.
135
+ @trace_ignore_paths = []
132
136
  # Opt-in: for a SELECT on PostgreSQL that took at least explain_threshold_ms, ask Postgres for
133
137
  # its plan (plain EXPLAIN, never EXPLAIN ANALYZE, so the query is never run again) and send
134
138
  # it, masked, so ForgeOps can show why the query was slow. Off by default because it runs one
@@ -34,6 +34,7 @@ module ForgeOpsTracker
34
34
 
35
35
  def call(env)
36
36
  return app.call(env) unless configuration.track_tracing && configuration.enabled?
37
+ return app.call(env) if ignored_path?(env)
37
38
 
38
39
  state = RequestState.for(env)
39
40
  buffer = SpanBuffer.new(trace_id: state.trace_id, parent_span_id: state.parent_span_id)
@@ -49,6 +50,11 @@ module ForgeOpsTracker
49
50
  private
50
51
  attr_reader :app, :configuration
51
52
 
53
+ def ignored_path?(env)
54
+ path = env["PATH_INFO"].to_s
55
+ Array(configuration.trace_ignore_paths).any? { |prefix| path.start_with?(prefix) }
56
+ end
57
+
52
58
  def send_trace?(buffer, state)
53
59
  return true if buffer.slow?(configuration.trace_capture_threshold_ms)
54
60
 
@@ -22,6 +22,7 @@ module ForgeOpsTracker
22
22
  secret apisecret clientsecret secretkey
23
23
  token accesstoken refreshtoken apikey apitoken authorization authtoken bearer sessiontoken csrftoken
24
24
  creditcard cardnumber cardnum cvv cvv2 cvc
25
+ iban accountnumber routingnumber bankaccount
25
26
  ssn socialsecuritynumber socialsecurity
26
27
  privatekey
27
28
  ].freeze
@@ -37,6 +38,12 @@ module ForgeOpsTracker
37
38
  "GITHUB TOKEN" => /\bgh[pousr]_[A-Za-z0-9]{20,}\b/
38
39
  }.freeze
39
40
 
41
+ # Card numbers in any other shape, and IBANs: see sdks/PII_SCRUBBING.md, which every SDK follows,
42
+ # and sdks/pii_scrubbing_vectors.json (a copy is in spec/fixtures), which pins the results.
43
+ DIGIT_RUN = /(?<![A-Za-z0-9_])\d(?:[ -]?\d)*(?![A-Za-z0-9_])/
44
+ CARD_PREFIXES = /\A(?:4|5[1-5]|2(?:22[1-9]|2[3-9]\d|[3-6]\d\d|7[01]\d|720)|3[47]|6011|64[4-9]|65|35(?:2[89]|[3-8]\d)|36|30[0-5]|62)/
45
+ IBAN = /(?<![A-Za-z0-9_])[A-Z]{2}[0-9]{2}(?:[A-Z0-9]{11,30}|(?: [A-Z0-9]{4}){2,7}(?: [A-Z0-9]{1,4})?)(?![A-Za-z0-9_])/
46
+
40
47
  def self.scrub(value, key: nil)
41
48
  if sensitive_key?(key) && !value.nil?
42
49
  REDACTED
@@ -63,8 +70,64 @@ module ForgeOpsTracker
63
70
  private_class_method :sensitive_key?
64
71
 
65
72
  def self.scrub_string(string)
66
- PATTERNS.reduce(string) { |scrubbed, (label, pattern)| scrubbed.gsub(pattern, "[#{label} FILTERED]") }
73
+ # IBANs first: a spaced IBAN's middle groups look like a formatted card number.
74
+ scrubbed = string.gsub(IBAN) { |candidate| iban?(candidate) ? "[IBAN FILTERED]" : candidate }
75
+ scrubbed = PATTERNS.reduce(scrubbed) { |text, (label, pattern)| text.gsub(pattern, "[#{label} FILTERED]") }
76
+ scrubbed.gsub(DIGIT_RUN) { |run| scrub_card_numbers_in(run) }
67
77
  end
68
78
  private_class_method :scrub_string
79
+
80
+ # From each group of the run on, the longest stretch of whole groups that is a card number is
81
+ # replaced, so a card followed by its CVV, two cards in a row, and Amex's 4-6-5 are all found.
82
+ def self.scrub_card_numbers_in(run)
83
+ groups = run.split(/([ -])/)
84
+ digits = groups.each_slice(2).map(&:first)
85
+ separators = groups.each_slice(2).map { |pair| pair[1] }
86
+ out = +""
87
+ i = 0
88
+ while i < digits.length
89
+ j = (digits.length - 1).downto(i).find { |last| card_number?(digits[i..last].join) }
90
+ if j
91
+ out << "[CREDIT CARD FILTERED]" << separators[j].to_s
92
+ i = j + 1
93
+ else
94
+ out << digits[i] << separators[i].to_s
95
+ i += 1
96
+ end
97
+ end
98
+ out
99
+ end
100
+ private_class_method :scrub_card_numbers_in
101
+
102
+ def self.card_number?(digits)
103
+ digits.length.between?(13, 19) && digits.match?(CARD_PREFIXES) && luhn?(digits)
104
+ end
105
+ private_class_method :card_number?
106
+
107
+ def self.luhn?(digits)
108
+ sum = digits.reverse.each_char.with_index.sum do |char, index|
109
+ value = char.to_i
110
+ next value if index.even?
111
+
112
+ doubled = value * 2
113
+ doubled > 9 ? doubled - 9 : doubled
114
+ end
115
+ (sum % 10).zero?
116
+ end
117
+ private_class_method :luhn?
118
+
119
+ # The IBAN check, a digit at a time: the first four characters moved to the end, letters as two
120
+ # digits (A is 10), and the remainder by 97 is 1.
121
+ def self.iban?(candidate)
122
+ compact = candidate.delete(" ")
123
+ return false unless compact.length.between?(15, 34)
124
+
125
+ rearranged = compact[4..] + compact[0, 4]
126
+ remainder = rearranged.each_char.reduce(0) do |acc, char|
127
+ (char.match?(/[A-Z]/) ? (char.ord - 55).to_s : char).each_char.reduce(acc) { |r, digit| (r * 10 + digit.to_i) % 97 }
128
+ end
129
+ remainder == 1
130
+ end
131
+ private_class_method :iban?
69
132
  end
70
133
  end
@@ -1,3 +1,3 @@
1
1
  module ForgeOpsTracker
2
- VERSION = "0.20.0"
2
+ VERSION = "0.22.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.20.0
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ForgeOps