Created
February 6, 2020 13:57
-
-
Save frewsxcv/d3ebe3b174059d8cc7b612fc02ebe4fb to your computer and use it in GitHub Desktop.
Stripe + Datadog Tracing integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Stripe::APIOperations::Request::ClassMethods | |
old_request = instance_method(:request) | |
define_method(:request) do |*args| | |
span = Datadog.tracer.trace('stripe.request', span_type: 'http') | |
begin | |
result = old_request.bind(self).call(*args) | |
rescue Stripe::StripeError => e | |
span.set_error(e) | |
span.set_tag(:http_status, e.http_status) | |
span.set_tag(:request_id, e.request_id) | |
raise e | |
else | |
span.set_tag(:http_status, result&.[](0)&.http_status) | |
span.set_tag(:request_id, result&.[](0)&.request_id) | |
ensure | |
span.set_tag(:method, args[0]) | |
span.set_tag(:url, args[1]) | |
span.finish | |
end | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment