Skip to content

Commit

Permalink
Omit usage if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Dec 1, 2023
1 parent 0455e39 commit b442111
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/stripe/stripe_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,11 @@ def initialize(request_id, request_duration_ms, usage: [])
end

def payload
{ request_id: request_id, request_duration_ms: request_duration_ms, usage: usage }
ret = { request_id: request_id, request_duration_ms: request_duration_ms}
if !usage.nil? && !usage.empty?
ret[:usage] = usage
end
ret
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions test/stripe/stripe_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1416,9 +1416,17 @@ class StripeClientTest < Test::Unit::TestCase
assert(!trace_metrics_header.nil?)

trace_payload = JSON.parse(trace_metrics_header)

assert(trace_payload["last_request_metrics"]["request_id"] == "req_123")
assert(!trace_payload["last_request_metrics"]["request_duration_ms"].nil?)
assert(trace_payload["last_request_metrics"]["usage"] == ["save"])

Stripe::Charge.list
trace_payload = JSON.parse(trace_metrics_header)
assert(trace_payload["last_request_metrics"]["request_id"] == "req_123")
assert(!trace_payload["last_request_metrics"]["request_duration_ms"].nil?)
assert(trace_payload["last_request_metrics"]["usage"].nil?)

end
end

Expand Down

0 comments on commit b442111

Please sign in to comment.