Skip to content

Commit

Permalink
Making stripe telemetry more specific in terms of units
Browse files Browse the repository at this point in the history
  • Loading branch information
akropp-stripe committed Nov 12, 2018
1 parent ba23aa5 commit b900b16
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions lib/stripe/stripe_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ def execute_request_with_rescues(api_base, context)
context = context.dup_from_response(resp)
log_response(context, request_start, resp.status, resp.body)
if Stripe.enable_telemetry?
@last_request_metrics = StripeRequestMetrics.new(context.request_id, Time.now - request_start)
request_duration_ms = ((Time.now - request_start) * 1000).to_int

@last_request_metrics = StripeRequestMetrics.new(context.request_id, request_duration_ms)
end

# We rescue all exceptions from a request so that we have an easy spot to
Expand Down Expand Up @@ -607,16 +609,16 @@ class StripeRequestMetrics
# The Stripe request ID of the response.
attr_accessor :request_id

# Request duration
attr_accessor :request_duration
# Request duration in milliseconds
attr_accessor :request_duration_ms

def initialize(request_id, request_duration)
self.request_id = request_id
self.request_duration = request_duration
def initialize(request_id, request_duration_ms)
self.request_id = request_id
self.request_duration_ms = request_duration_ms
end

def payload
{ request_id: request_id, request_duration: request_duration }
{ request_id: request_id, request_duration_ms: request_duration_ms }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/stripe/stripe_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ class StripeClientTest < Test::Unit::TestCase

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"].nil?)
assert(!trace_payload["last_request_metrics"]["request_duration_ms"].nil?)
end
end
end
Expand Down

0 comments on commit b900b16

Please sign in to comment.