Skip to content

Commit

Permalink
Add request headers field to RequestEventEnd
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyhh committed Jan 5, 2023
1 parent e14b364 commit 8715d6c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/stripe/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class RequestEndEvent
attr_reader :path
attr_reader :request_id
attr_reader :response
attr_reader :request_header
attr_reader :request_body

# Arbitrary user-provided data in the form of a Ruby hash that's passed
Expand All @@ -43,7 +44,7 @@ class RequestEndEvent
attr_reader :user_data

def initialize(duration:, http_status:, method:, num_retries:, path:,
request_id:, user_data: nil, response: nil, request_body: nil)
request_id:, user_data: nil, response: nil, request_header: nil, request_body: nil)
@duration = duration
@http_status = http_status
@method = method
Expand All @@ -52,6 +53,7 @@ def initialize(duration:, http_status:, method:, num_retries:, path:,
@request_id = request_id
@user_data = user_data
@response = response
@request_header = request_header
@request_body = request_body
freeze
end
Expand Down
11 changes: 6 additions & 5 deletions lib/stripe/stripe_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def self.maybe_gc_connection_managers
end
end

http_resp = execute_request_with_rescues(method, api_base, context) do
http_resp = execute_request_with_rescues(method, api_base, headers, context) do
self.class
.default_connection_manager(config)
.execute_request(method, url,
Expand Down Expand Up @@ -564,7 +564,7 @@ def self.maybe_gc_connection_managers
http_status >= 400
end

private def execute_request_with_rescues(method, api_base, context)
private def execute_request_with_rescues(method, api_base, headers, context)
num_retries = 0

begin
Expand All @@ -587,7 +587,7 @@ def self.maybe_gc_connection_managers

log_response(context, request_start, http_status, resp.body, resp)
notify_request_end(context, request_duration, http_status,
num_retries, user_data, resp)
num_retries, user_data, resp, headers)

if config.enable_telemetry? && context.request_id
request_duration_ms = (request_duration * 1000).to_i
Expand All @@ -614,7 +614,7 @@ def self.maybe_gc_connection_managers
log_response_error(error_context, request_start, e)
end
notify_request_end(context, request_duration, http_status, num_retries,
user_data, resp)
user_data, resp, headers)

if self.class.should_retry?(e,
method: method,
Expand Down Expand Up @@ -657,7 +657,7 @@ def self.maybe_gc_connection_managers
end

private def notify_request_end(context, duration, http_status, num_retries,
user_data, resp)
user_data, resp, headers)
return if !Instrumentation.any_subscribers?(:request_end) &&
!Instrumentation.any_subscribers?(:request)

Expand All @@ -670,6 +670,7 @@ def self.maybe_gc_connection_managers
request_id: context.request_id,
user_data: user_data || {},
response: resp,
request_header: headers,
request_body: context.body
)
Stripe::Instrumentation.notify(:request_end, event)
Expand Down

0 comments on commit 8715d6c

Please sign in to comment.