bitfab 0.17.1 → 0.18.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: 9dd280a2cd6afdf47b2bbbf62508dd4918dccf42c83ed276845f592497168601
4
- data.tar.gz: 224fc7cfe39e847f3bfd56e9876151ea356f7a8ad7bff66b529f9704ab360141
3
+ metadata.gz: 4401b0c7aa47516909e636557ab23f325fb0cbbd4ca8564f3d8864078e58f975
4
+ data.tar.gz: 2b11fbfee500e0e03ec7b4b61772d623e2c236479965441b659aafbed4a687a6
5
5
  SHA512:
6
- metadata.gz: 4cba57762a9ae927ba34ac70fdd1d750d118a9f8f3cc47402f30d8a09c336337f27cef601f8b36e63140e01acaa410d1a58450f160cb1c3d7e7c2c5b1a198cb3
7
- data.tar.gz: eaa0a0b2eed0c0f7c0e24a73e2128540c53a504e9a3dd4d6858355e8076aa2fa8a4913ea170b278ac1579c5e407d4333759e1bae345dbe575b9fa91b666275a1
6
+ metadata.gz: e720bb8dd79d572f4671b5f891cb1528dac2b610d2357d1f16ec5a7e04656fff0969f434e5e683be991d8745865bacbbe1e37993380e1a09d2cc9377e221eda5
7
+ data.tar.gz: c197da185d7966cd9861213c49f0db4e3246a5eab0bdb70e800d8a4a5a4e8f174b5294d833511232555d43f0ca026a7988297fa3660743a8fef94b05b17a7ca9
@@ -5,6 +5,7 @@ require "json"
5
5
  require "uri"
6
6
 
7
7
  require_relative "constants"
8
+ require_relative "serialize"
8
9
  require_relative "version"
9
10
 
10
11
  module Bitfab
@@ -32,7 +33,7 @@ module Bitfab
32
33
  http.read_timeout = request_timeout
33
34
 
34
35
  req = Net::HTTP::Post.new(uri.path, headers)
35
- req.body = JSON.generate(payload)
36
+ req.body = safe_generate(payload, endpoint)
36
37
 
37
38
  response = http.request(req)
38
39
 
@@ -166,6 +167,46 @@ module Bitfab
166
167
 
167
168
  private
168
169
 
170
+ # JSON-encode a request body without ever raising on a stray value.
171
+ #
172
+ # Upstream serialization (Serialize.serialize_value) should already have
173
+ # flattened user data. This is the boundary backstop: if anything
174
+ # non-serializable still slips through, it is run through serialize_value
175
+ # (which never raises and stubs strays) instead of letting JSON.generate
176
+ # raise and drop the whole span/trace silently. A degraded payload warns
177
+ # loudly so the trace isn't quietly left incomplete or not replayable.
178
+ def safe_generate(payload, endpoint)
179
+ JSON.generate(payload)
180
+ rescue => e
181
+ begin
182
+ warn "Bitfab: request body to #{endpoint} held a non-serializable " \
183
+ "value (#{e.message}); it was stubbed so the span still sends, " \
184
+ "but the trace may be incomplete or not replayable. Capture a " \
185
+ "JSON-safe projection of this input to make it replayable."
186
+ rescue
187
+ # Never crash the host app over a log line.
188
+ end
189
+
190
+ begin
191
+ JSON.generate(sanitize_payload(payload))
192
+ rescue
193
+ # Truly pathological. Still never drop silently: send a marker body.
194
+ JSON.generate({"error" => "payload_serialize_failed"})
195
+ end
196
+ end
197
+
198
+ # Serialize each top-level value so a bad or oversize value is stubbed in
199
+ # place while the payload keeps its object shape. Running serialize_value on
200
+ # the whole payload could collapse the entire body to a single stub string
201
+ # (oversize/cyclic), sending a JSON string instead of a span object.
202
+ def sanitize_payload(payload)
203
+ return {"error" => "payload_serialize_failed"} unless payload.is_a?(Hash)
204
+
205
+ payload.each_with_object({}) do |(k, v), acc|
206
+ acc[k.to_s] = Serialize.serialize_value(v)
207
+ end
208
+ end
209
+
169
210
  # Normalize each entry to a hash with stable string keys, accepting either
170
211
  # symbol-keyed or string-keyed hashes from callers.
171
212
  def normalize_code_change_files(files)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bitfab
4
- VERSION = "0.17.1"
4
+ VERSION = "0.18.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitfab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.1
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harvest Team