-
Notifications
You must be signed in to change notification settings - Fork 548
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 simple instrumentation callback #870
Conversation
d1ba8ac
to
6321629
Compare
Hi @bdewater, thanks for the contribution! @brandur-stripe is most familiar with the inner workings of stripe-ruby (having written most of it) so I want him to review this just in case he has comments. Unfortunately he's currently OOO so we won't be able to merge this right away. Thanks for your patience! |
56252c8
to
206b9f6
Compare
We used to insert Faraday::Request::Instrumentation into our Faraday middleware stack to be able to instrument Stripe calls with StatsD. With Faraday being removed in version 5, this required some rework. This commit implements a simple callback system that can be used with any kind of instrumentation system.
206b9f6
to
fc0d9d1
Compare
Hey @brandur-stripe just following up on this one, any thoughts? |
Hey @Senjai, Brandur will be back next Monday. Sorry for the delay! |
This has been running in our production environment since earlier today btw, everything works. |
Hey Bart, love this implementation! Thanks a lot for taking the time to put it together. It looks like you modeled it after some prior art Active Support too, which is great. I think all the broad strokes are basically right, but here are a couple changes that I'd like to see:
Anyway, thanks again for all the work! Looking forward to this feature. Also, cc @ob-stripe -- even if this is Ruby, it may end up setting some precedent for how instrumentation callbacks in other languages end up looking, so we should try to come up with something we're all pretty happy with. |
Hi Brandur, thanks for the feedback! Those all sounds very reasonable. I have to give credit where credit is due, the immediate inspiration was from our Semian gem :) I currently don't have the bandwidth to incorporate your ideas but I should have time to circle back to this by end of next week/beginning of the week after that. |
@bdewater Ah, didn't notice you were with Shopify at first :) But sounds good! I think you got all the heavy lifting already, so I think we could get the feedback turned around pretty quickly. Let me know if you need any support. Thanks. |
... and a :request topic to subscribe to
This way the RequestLogContext object doesn't get exposed externally. Since the same value object can be received by multiple subscribers it is frozen to prevent accidental mutations across threads.
Hi @brandur-stripe I had some time on flights today 🙂 please have another look. I incorporated most of your feedback. I wasn't sure how strong you felt about your suggestion to include the original response on the instrumentation event, but after thinking it over I felt that if you need to reach into the response it means something is missing on the event itself. This PR is heavily based on keeping Shopify's specific version 4.x instrumentation working with 5.x so it's possible it's not covering someone else's use case. But the new event object approach lends itself to extension by others, so that should not stop a person from submitting a PR for this. What do you think? |
Looks amazing @bdewater.
Yep, I think this is actually the preferable approach — it's easy to expose new properties, but it's difficult to take old ones away, so let's start with something fairly minimal and grow as necessary. Anyway, thanks again for the fine work! Pulling this in. |
Released as 5.9.0. |
Awesome! Thanks for working with us on this one :D |
We used to insert
Faraday::Request::Instrumentation
(with a monkey patch) into our Faraday middleware stack to be able to instrument Stripe calls with StatsD. With Faraday being removed in version 5, this required some rework. This commit implements a simple callback system that can be used with any kind of instrumentation library.Closes #795