Skip to content

Instantly share code, notes, and snippets.

@frewsxcv
Created February 6, 2020 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frewsxcv/d3ebe3b174059d8cc7b612fc02ebe4fb to your computer and use it in GitHub Desktop.
Save frewsxcv/d3ebe3b174059d8cc7b612fc02ebe4fb to your computer and use it in GitHub Desktop.
Stripe + Datadog Tracing integration
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