Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stripe instrumentation #2557

Merged
merged 1 commit into from
Jan 23, 2023
Merged

Conversation

agrobbin
Copy link
Contributor

What does this PR do?

This adds instrumentation of the stripe-ruby gem.

Motivation

While using the Stripe gem, I thought it would be really helpful to have spans show up in DataDog APM whenever we interact with Stripe!

@agrobbin agrobbin requested a review from a team January 14, 2023 19:11
@github-actions github-actions bot added integrations Involves tracing integrations tracing labels Jan 14, 2023
@agrobbin agrobbin force-pushed the stripe-instrumentation branch 6 times, most recently from 9cfac1f to 7737a98 Compare January 14, 2023 20:11
end

def tag_span(span, event)
span.resource = event.object_name if event.respond_to?(:object_name) && event.object_name
Copy link
Contributor Author

@agrobbin agrobbin Jan 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular resource configuration is dependent upon stripe/stripe-ruby#1168, which exposes object_name. I'm happy to remove this while that PR is considered if it's preferred!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be great if we could derive resource from Stripe's api resource (with your Stripe's PR).

However, I feel like having stripe.customer instead of customer would be an improvement (currently, without an object name, it is stripe.request). What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that makes a lot of sense, @TonyCTHsu. I've updated this to be "stripe.#{event.object_name}".

I have not yet heard back from Stripe on that PR, so I'm curious what you suggest doing while we wait. I'm happy to remove this to unblock the rest of this instrumentation. Then I can open a new PR here once stripe/stripe-ruby#1168 (hopefully) gets merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can merge this with a code comment referencing the Stripe's PR. What bothers me more would be a missing spec to test this condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TonyCTHsu makes sense! I've just pushed up a test that I think best exercises this. I can keep an eye on stripe/stripe-ruby#1168, and update as appropriate based on what happens with that.

@agrobbin agrobbin force-pushed the stripe-instrumentation branch 3 times, most recently from c0aef06 to 56c4455 Compare January 14, 2023 20:28
@TonyCTHsu
Copy link
Contributor

👋 @agrobbin , Thanks for your awesome contribution!

I was not particularly familiar with this gem, but at first glance, it seems fine! Let me spend some time to dig around with the gem to provide proper review.

One thing I would suggest is that, since it is supporting 5.15, we should setup our test matrix like

Ruby version Stripe version
2.3 5.x
2.4 6.x
2.5 7.x
2.6+ 8.x

@agrobbin
Copy link
Contributor Author

@TonyCTHsu I just updated this to test against various stripe versions like you asked. I set it up so that on Ruby 2.7+, it tests on the latest version of stripe. Let me know if there's anything else I can do to help with review here!

tag_span(span, event)

# Finish the span
span.finish
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think span.finish needs to be in an ensure block. If tag_span raises an error, the span will go unfinished and will not be visible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tag_span has a rescue StandardError @delner, but I see the pattern you're referring to elsewhere in the library, so I've updated this to match!

@agrobbin agrobbin force-pushed the stripe-instrumentation branch 3 times, most recently from be53688 to bd2a75d Compare January 19, 2023 13:43
@codecov-commenter
Copy link

codecov-commenter commented Jan 19, 2023

Codecov Report

Merging #2557 (1a6263b) into master (095cffb) will increase coverage by 0.00%.
The diff coverage is 99.02%.

@@           Coverage Diff            @@
##           master    #2557    +/-   ##
========================================
  Coverage   98.03%   98.04%            
========================================
  Files        1127     1135     +8     
  Lines       60859    61066   +207     
  Branches     2772     2776     +4     
========================================
+ Hits        59661    59870   +209     
+ Misses       1198     1196     -2     
Impacted Files Coverage Δ
lib/datadog/tracing/contrib/stripe/request.rb 94.11% <94.11%> (ø)
lib/datadog/tracing/contrib.rb 100.00% <100.00%> (ø)
...g/tracing/contrib/stripe/configuration/settings.rb 100.00% <100.00%> (ø)
lib/datadog/tracing/contrib/stripe/ext.rb 100.00% <100.00%> (ø)
lib/datadog/tracing/contrib/stripe/integration.rb 100.00% <100.00%> (ø)
lib/datadog/tracing/contrib/stripe/patcher.rb 100.00% <100.00%> (ø)
...datadog/tracing/contrib/stripe/integration_spec.rb 100.00% <100.00%> (ø)
...pec/datadog/tracing/contrib/stripe/patcher_spec.rb 100.00% <100.00%> (ø)
...pec/datadog/tracing/contrib/stripe/request_spec.rb 100.00% <100.00%> (ø)
...ng/contrib/active_support/cache/instrumentation.rb 86.30% <0.00%> (+0.09%) ⬆️
... and 3 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@TonyCTHsu TonyCTHsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 @agrobbin, Great job!

end

def tag_span(span, event)
span.resource = event.object_name if event.respond_to?(:object_name) && event.object_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be great if we could derive resource from Stripe's api resource (with your Stripe's PR).

However, I feel like having stripe.customer instead of customer would be an improvement (currently, without an object name, it is stripe.request). What do you think?

@agrobbin agrobbin force-pushed the stripe-instrumentation branch 2 times, most recently from 7615e60 to 5be411f Compare January 21, 2023 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrations Involves tracing integrations tracing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants