Add request_id to RequestEndEvent (#993)

Co-authored-by: Richard Marmorstein <52928443+richardm-stripe@users.noreply.github.com>
This commit is contained in:
DJ Patterson 2021-08-10 00:47:46 +01:00 committed by GitHub
parent 378c71dec7
commit 85c7f52c3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 2 deletions

View File

@ -252,6 +252,7 @@ a success or error. Receives `RequestEndEvent` with the following properties:
- `path`: Request path. (`String`)
- `user_data`: A hash on which users may have set arbitrary data in
`request_begin`. See above for more information. (`Hash`)
- `request_id`. HTTP request identifier.
#### Example

View File

@ -32,6 +32,7 @@ module Stripe
attr_reader :method
attr_reader :num_retries
attr_reader :path
attr_reader :request_id
# Arbitrary user-provided data in the form of a Ruby hash that's passed
# from subscribers on `request_begin` to subscribers on `request_end`.
@ -40,12 +41,13 @@ module Stripe
attr_reader :user_data
def initialize(duration:, http_status:, method:, num_retries:, path:,
user_data: nil)
request_id:, user_data: nil)
@duration = duration
@http_status = http_status
@method = method
@num_retries = num_retries
@path = path
@request_id = request_id
@user_data = user_data
freeze
end

View File

@ -667,6 +667,7 @@ module Stripe
method: context.method,
num_retries: num_retries,
path: context.path,
request_id: context.request_id,
user_data: user_data || {}
)
Stripe::Instrumentation.notify(:request_end, event)

View File

@ -64,6 +64,7 @@ module Stripe
method: :get,
num_retries: 0,
path: "/v1/test",
request_id: "req_123",
user_data: nil
)

View File

@ -1408,7 +1408,7 @@ module Stripe
Stripe::Instrumentation.subscribe(:request_end, :test) { |event| events << event }
stub_request(:get, "#{Stripe.api_base}/v1/charges")
.to_return(body: JSON.generate(object: "charge"))
.to_return(body: JSON.generate(object: "charge"), headers: { "Request-ID": "req_123" })
Stripe::Charge.list
assert_equal(1, events.size)
@ -1418,6 +1418,7 @@ module Stripe
assert_equal(200, event.http_status)
assert(event.duration.positive?)
assert_equal(0, event.num_retries)
assert_equal("req_123", event.request_id)
end
should "notify a subscriber of a StripeError" do