Skip to content

Commit

Permalink
Create a ResponseContext class
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyhh committed Jan 10, 2023
1 parent 670f366 commit 89306d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
22 changes: 19 additions & 3 deletions lib/stripe/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class RequestEndEvent
attr_reader :num_retries
attr_reader :path
attr_reader :request_id
attr_reader :response
attr_reader :response_header
attr_reader :response_body
attr_reader :request_header
attr_reader :request_body

Expand All @@ -43,15 +44,17 @@ class RequestEndEvent
# in `request_end`.
attr_reader :user_data

def initialize(request_context:,
def initialize(request_context:, response_context:,
num_retries:, user_data: nil)
@duration = request_context.duration
@http_status = http_status
@http_status = response_context.http_status
@method = request_context.method
@num_retries = num_retries
@path = request_context.path
@request_id = request_context.request_id
@user_data = user_data
@response_header = response_context.header
@response_body = response_context.body
@request_header = request_context.header
@request_body = request_context.body
freeze
Expand All @@ -75,6 +78,19 @@ def initialize(duration:, context:, header:)
@header = header
end
end

class ResponseContext
attr_reader :http_status
attr_reader :body
attr_reader :header

def initialize(http_status:, response:)
@http_status = http_status
@header = response.to_hash
@body = response.body
end
end

# This class was renamed for consistency. This alias is here for backwards
# compatibility.
RequestEvent = RequestEndEvent
Expand Down
8 changes: 6 additions & 2 deletions lib/stripe/stripe_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -667,12 +667,16 @@ def self.maybe_gc_connection_managers
context: context,
header: headers
)
response_context = Stripe::Instrumentation::ResponseContext.new(
http_status: http_status,
response: resp
)

event = Instrumentation::RequestEndEvent.new(
http_status: http_status,
request_context: request_context,
response_context: response_context,
num_retries: num_retries,
user_data: user_data || {},
user_data: user_data || {}
)
Stripe::Instrumentation.notify(:request_end, event)

Expand Down

0 comments on commit 89306d8

Please sign in to comment.