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

Improve request events instrumentation #1162

Merged

Conversation

nguyhh
Copy link
Contributor

@nguyhh nguyhh commented Jan 5, 2023

What are you trying to accomplish?

This is an extension of the simple instrumentation callback what has been done previously in #870.

To create our own event logs of Stripe calls, we were missing certain informations when we subscribe to Request/RequestEnd. The missing informations that we would like to have access to are:

  • Request headers and body
  • Response headers and body

What approach did you choose and why?

We simply added the missing fields to the RequestEndEvent class.

Please correct me if I am wrong, but here is my understanding on where to retrieve the missing informations.

  • Context seems to hold the information about the request
    • context.body would hold the request body information
  • Resp seems to be the response
    • resp.body holds the response body
    • resp.to_hash seems to hold the hidden response headers
  • The request headers were not exposed, so we are passing it through theexecute_request_with_rescues method

@CLAassistant
Copy link

CLAassistant commented Jan 5, 2023

CLA assistant check
All committers have signed the CLA.

@nguyhh nguyhh force-pushed the improve-request-events-instrumentation branch from 88dd9b8 to bd8d7ee Compare January 5, 2023 16:00
@anniel-stripe
Copy link
Contributor

anniel-stripe commented Jan 5, 2023

Hi @nguyhh, thanks so much for the contribution! Looks like there is a linting error, which you can fix by running bundle exec rake rubocop.

Otherwise the implementation looks reasonable to me! I'm going to have @pakrym-stripe take a look as well, since he has more experience with stripe-ruby.

lib/stripe/instrumentation.rb Outdated Show resolved Hide resolved
@nguyhh nguyhh force-pushed the improve-request-events-instrumentation branch 3 times, most recently from 380901a to 70068a6 Compare January 10, 2023 19:23
@nguyhh nguyhh force-pushed the improve-request-events-instrumentation branch from 70068a6 to 89306d8 Compare January 10, 2023 19:24
@nguyhh
Copy link
Contributor Author

nguyhh commented Jan 10, 2023

Hi!
There was a lint error saying that the list of arguments was too long. So what I did is extract the arguments and wrap them under a RequestContext and a ResponseContext object. I wasn't really sure where these classes should live so I've put them under the Instrumentation class at the moment. Please let me know if there is a better suited place. 😄

@nguyhh nguyhh force-pushed the improve-request-events-instrumentation branch from 075e6f0 to 3440d0f Compare January 10, 2023 23:37
Copy link
Contributor

@anniel-stripe anniel-stripe left a comment

Choose a reason for hiding this comment

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

Hi, thanks so much for making those changes! This LGTM :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants