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

Report usage of StripeClient #1698

Closed
wants to merge 11 commits into from

Conversation

richardm-stripe
Copy link
Contributor

@richardm-stripe richardm-stripe commented Nov 30, 2023

Changelog

  • Reports use of the new StripeClient in X-Stripe-Client-Telemetry. (You can disable telemetry via Stripe.enableTelemetry = false;, see the README.)

Details

  • Gives LiveStripeResponseGetter a mutable "usage" that it will set on all requests it creates.
  • Causes the StripeClient constructor to set usage on its LiveStripeResponseGetter to ["stripe_client"].
  • Modifies RequestTelemetry to accept usage and set it appropriately on X-Stripe-Client-Telemetry. Had to add a parameter to a public method, so I made a new overload and deprecated the old one. Had to disable a linter rule to do this.

Testing

src/test/java/com/stripe/functional/StripeClientTest.java
and src/test/java/com/stripe/functional/LiveStripeResponseGetterTest.java mock at the HttpClient level.

@richardm-stripe richardm-stripe force-pushed the richardm-stripe-client-usage branch from 2cf8397 to e2ece8d Compare November 30, 2023 23:11
@richardm-stripe richardm-stripe marked this pull request as ready for review December 1, 2023 21:51
@@ -121,6 +121,9 @@ public void setUpStripeMockUsage() {
httpClientSpy = Mockito.spy(new HttpURLConnectionClient());
networkSpy = Mockito.spy(new LiveStripeResponseGetter(null, httpClientSpy));
mockClient = new StripeClient(networkSpy);
// The StripeClient constructor calls .setUsage on networkSpy, let's reset that so
// in the test cases we can just verify the calls we care about.
Mockito.reset(networkSpy);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we change our test infra to have 2 spies / separate LiveStripeResponseGetters for APIResource and StripeClient?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My worry with that, is that we would then need to make copies of all the other helper functions here that use networkSpy and it might be a bad experience when you're writing a test to have to choose between them and select the right one, and I hesitated to make the experience worse in 95% of cases for an edge case that only affects usage-related tests.

I was on the fence though, let me know what you prefer.

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.

2 participants