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 +4 -4
- data/lib/bitfab/http_client.rb +42 -1
- data/lib/bitfab/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4401b0c7aa47516909e636557ab23f325fb0cbbd4ca8564f3d8864078e58f975
|
|
4
|
+
data.tar.gz: 2b11fbfee500e0e03ec7b4b61772d623e2c236479965441b659aafbed4a687a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e720bb8dd79d572f4671b5f891cb1528dac2b610d2357d1f16ec5a7e04656fff0969f434e5e683be991d8745865bacbbe1e37993380e1a09d2cc9377e221eda5
|
|
7
|
+
data.tar.gz: c197da185d7966cd9861213c49f0db4e3246a5eab0bdb70e800d8a4a5a4e8f174b5294d833511232555d43f0ca026a7988297fa3660743a8fef94b05b17a7ca9
|
data/lib/bitfab/http_client.rb
CHANGED
|
@@ -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 =
|
|
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)
|
data/lib/bitfab/version.rb
CHANGED