stripe 3.30.0 → 3.31.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 +5 -5
- data/.gitignore +1 -0
- data/.rubocop_todo.yml +1 -1
- data/CHANGELOG.md +3 -0
- data/VERSION +1 -1
- data/lib/stripe.rb +10 -0
- data/lib/stripe/stripe_client.rb +26 -1
- data/lib/stripe/version.rb +1 -1
- data/test/stripe/stripe_client_test.rb +45 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 52baaa63153c557126fa6561e14c544fc5fbbb40
|
|
4
|
+
data.tar.gz: 89e88d7e7730d54188f73270e354b4027ff3ca2e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db6c1475916245fe94df52771b1a954a25653278e3af489310bbbdf598bf49f4b97db0f7a3dfd0665bc24979c006388c70490e6909678e0e3388a9c54172127a
|
|
7
|
+
data.tar.gz: 58930d60e01262bc61a80953784a6f6b8bab7224f97af80fc550a39982cd663b76b6cf4e99896915f74d1f68b561cb8b84e4ed0db264626e63d89d5f25a24215
|
data/.gitignore
CHANGED
data/.rubocop_todo.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.31.0 - 2018-11-12
|
|
4
|
+
* [#696](https://github.com/stripe/stripe-ruby/pull/696) Add configurable telemetry to gather information on client-side request latency
|
|
5
|
+
|
|
3
6
|
## 3.30.0 - 2018-11-08
|
|
4
7
|
* [#693](https://github.com/stripe/stripe-ruby/pull/693) Add new API endpoints for the `Invoice` resource.
|
|
5
8
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.
|
|
1
|
+
3.31.0
|
data/lib/stripe.rb
CHANGED
|
@@ -124,6 +124,8 @@ module Stripe
|
|
|
124
124
|
@open_timeout = 30
|
|
125
125
|
@read_timeout = 80
|
|
126
126
|
|
|
127
|
+
@enable_telemetry = false
|
|
128
|
+
|
|
127
129
|
class << self
|
|
128
130
|
attr_accessor :stripe_account, :api_key, :api_base, :verify_ssl_certs, :api_version, :client_id, :connect_base, :uploads_base,
|
|
129
131
|
:open_timeout, :read_timeout
|
|
@@ -225,6 +227,14 @@ module Stripe
|
|
|
225
227
|
@max_network_retries = val.to_i
|
|
226
228
|
end
|
|
227
229
|
|
|
230
|
+
def self.enable_telemetry?
|
|
231
|
+
@enable_telemetry
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def self.enable_telemetry=(val)
|
|
235
|
+
@enable_telemetry = val
|
|
236
|
+
end
|
|
237
|
+
|
|
228
238
|
# Sets some basic information about the running application that's sent along
|
|
229
239
|
# with API requests. Useful for plugin authors to identify their plugin when
|
|
230
240
|
# communicating with Stripe.
|
data/lib/stripe/stripe_client.rb
CHANGED
|
@@ -12,6 +12,7 @@ module Stripe
|
|
|
12
12
|
def initialize(conn = nil)
|
|
13
13
|
self.conn = conn || self.class.default_conn
|
|
14
14
|
@system_profiler = SystemProfiler.new
|
|
15
|
+
@last_request_metrics = nil
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
def self.active_client
|
|
@@ -113,7 +114,6 @@ module Stripe
|
|
|
113
114
|
|
|
114
115
|
def execute_request(method, path,
|
|
115
116
|
api_base: nil, api_key: nil, headers: {}, params: {})
|
|
116
|
-
|
|
117
117
|
api_base ||= Stripe.api_base
|
|
118
118
|
api_key ||= Stripe.api_key
|
|
119
119
|
|
|
@@ -218,6 +218,9 @@ module Stripe
|
|
|
218
218
|
resp = yield
|
|
219
219
|
context = context.dup_from_response(resp)
|
|
220
220
|
log_response(context, request_start, resp.status, resp.body)
|
|
221
|
+
if Stripe.enable_telemetry?
|
|
222
|
+
@last_request_metrics = StripeRequestMetrics.new(context.request_id, Time.now - request_start)
|
|
223
|
+
end
|
|
221
224
|
|
|
222
225
|
# We rescue all exceptions from a request so that we have an easy spot to
|
|
223
226
|
# implement our retry logic across the board. We'll re-raise if it's a type
|
|
@@ -425,6 +428,10 @@ module Stripe
|
|
|
425
428
|
"Content-Type" => "application/x-www-form-urlencoded",
|
|
426
429
|
}
|
|
427
430
|
|
|
431
|
+
if Stripe.enable_telemetry? && !@last_request_metrics.nil?
|
|
432
|
+
headers["X-Stripe-Client-Telemetry"] = JSON.generate(last_request_metrics: @last_request_metrics.payload)
|
|
433
|
+
end
|
|
434
|
+
|
|
428
435
|
# It is only safe to retry network failures on post and delete
|
|
429
436
|
# requests if we add an Idempotency-Key header
|
|
430
437
|
if %i[post delete].include?(method) && Stripe.max_network_retries > 0
|
|
@@ -594,5 +601,23 @@ module Stripe
|
|
|
594
601
|
}.delete_if { |_k, v| v.nil? }
|
|
595
602
|
end
|
|
596
603
|
end
|
|
604
|
+
|
|
605
|
+
# StripeRequestMetrics tracks metadata to be reported to stripe for metrics collection
|
|
606
|
+
class StripeRequestMetrics
|
|
607
|
+
# The Stripe request ID of the response.
|
|
608
|
+
attr_accessor :request_id
|
|
609
|
+
|
|
610
|
+
# Request duration
|
|
611
|
+
attr_accessor :request_duration
|
|
612
|
+
|
|
613
|
+
def initialize(request_id, request_duration)
|
|
614
|
+
self.request_id = request_id
|
|
615
|
+
self.request_duration = request_duration
|
|
616
|
+
end
|
|
617
|
+
|
|
618
|
+
def payload
|
|
619
|
+
{ request_id: request_id, request_duration: request_duration }
|
|
620
|
+
end
|
|
621
|
+
end
|
|
597
622
|
end
|
|
598
623
|
end
|
data/lib/stripe/version.rb
CHANGED
|
@@ -749,6 +749,51 @@ module Stripe
|
|
|
749
749
|
end
|
|
750
750
|
end
|
|
751
751
|
end
|
|
752
|
+
|
|
753
|
+
context "#telemetry" do
|
|
754
|
+
teardown do
|
|
755
|
+
# make sure to always set telemetry back to false
|
|
756
|
+
# to not mutate global state
|
|
757
|
+
Stripe.enable_telemetry = false
|
|
758
|
+
end
|
|
759
|
+
|
|
760
|
+
should "not send metrics if enable trace flag is not set" do
|
|
761
|
+
Stripe.enable_telemetry = false
|
|
762
|
+
|
|
763
|
+
trace_metrics_header = nil
|
|
764
|
+
stub_request(:get, "#{Stripe.api_base}/v1/charges")
|
|
765
|
+
.with do |req|
|
|
766
|
+
trace_metrics_header = req.headers["X-Stripe-Client-Telemetry"]
|
|
767
|
+
false
|
|
768
|
+
end.to_return(body: JSON.generate(object: "charge"))
|
|
769
|
+
|
|
770
|
+
Stripe::Charge.list
|
|
771
|
+
assert(trace_metrics_header.nil?)
|
|
772
|
+
|
|
773
|
+
Stripe::Charge.list
|
|
774
|
+
assert(trace_metrics_header.nil?)
|
|
775
|
+
end
|
|
776
|
+
|
|
777
|
+
should "send metrics if enabled telemetry is true" do
|
|
778
|
+
Stripe.enable_telemetry = true
|
|
779
|
+
|
|
780
|
+
trace_metrics_header = nil
|
|
781
|
+
stub_request(:get, "#{Stripe.api_base}/v1/charges")
|
|
782
|
+
.with do |req|
|
|
783
|
+
trace_metrics_header = req.headers["X-Stripe-Client-Telemetry"]
|
|
784
|
+
false
|
|
785
|
+
end.to_return(body: JSON.generate(object: "charge"))
|
|
786
|
+
|
|
787
|
+
Stripe::Charge.list
|
|
788
|
+
Stripe::Charge.list
|
|
789
|
+
|
|
790
|
+
assert(!trace_metrics_header.nil?)
|
|
791
|
+
|
|
792
|
+
trace_payload = JSON.parse(trace_metrics_header)
|
|
793
|
+
assert(trace_payload["last_request_metrics"]["request_id"] == "req_123")
|
|
794
|
+
assert(!trace_payload["last_request_metrics"]["request_duration"].nil?)
|
|
795
|
+
end
|
|
796
|
+
end
|
|
752
797
|
end
|
|
753
798
|
|
|
754
799
|
class SystemProfilerTest < Test::Unit::TestCase
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stripe
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.31.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stripe
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-11-
|
|
11
|
+
date: 2018-11-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -223,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
223
223
|
version: '0'
|
|
224
224
|
requirements: []
|
|
225
225
|
rubyforge_project:
|
|
226
|
-
rubygems_version: 2.
|
|
226
|
+
rubygems_version: 2.6.14
|
|
227
227
|
signing_key:
|
|
228
228
|
specification_version: 4
|
|
229
229
|
summary: Ruby bindings for the Stripe API
|