Skip to content

Commit 83f5197

Browse files
committed
Enable request latency telemetry by default
1 parent a29e90e commit 83f5197

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

README.md

+35-12
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ compile "com.stripe:stripe-java:10.1.0"
3333
You'll need to manually install the following JARs:
3434

3535
* The Stripe JAR from https://github.com/stripe/stripe-java/releases/latest
36-
* [Google Gson](https://github.com/google/gson) from <https://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.2/gson-2.8.2.jar>.
36+
* [Google Gson](https://github.com/google/gson) from <https://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.5/gson-2.8.5.jar>.
3737

38-
### [ProGuard](http://proguard.sourceforge.net/)
38+
### [ProGuard](https://www.guardsquare.com/en/products/proguard)
3939

4040
If you're planning on using ProGuard, make sure that you exclude the Stripe bindings. You can do this by adding the following to your `proguard.cfg` file:
4141

42-
-keep class com.stripe.** { *; }
42+
```
43+
-keep class com.stripe.** { *; }
44+
```
4345

4446
## Documentation
4547

@@ -86,7 +88,7 @@ For apps that need to use multiple keys during the lifetime of a process, like
8688
one that uses [Stripe Connect][connect], it's also possible to set a
8789
per-request key and/or account:
8890

89-
``` java
91+
```java
9092
RequestOptions requestOptions = new RequestOptionsBuilder()
9193
.setApiKey("sk_test_...")
9294
.setStripeAccount("acct_...")
@@ -125,36 +127,57 @@ servers.
125127
If you're writing a plugin that uses the library, we'd appreciate it if you
126128
identified using `Stripe.setAppInfo()`:
127129

128-
Stripe.setAppInfo("MyAwesomePlugin", "1.2.34", "https://myawesomeplugin.info");
130+
```java
131+
Stripe.setAppInfo("MyAwesomePlugin", "1.2.34", "https://myawesomeplugin.info");
132+
```
129133

130134
This information is passed along when the library makes calls to the Stripe
131135
API.
132136

137+
### Request latency telemetry
138+
139+
By default, the library sends request latency telemetry to Stripe. These
140+
numbers help Stripe improve the overall latency of its API for all users.
141+
142+
You can disable this behavior if you prefer:
143+
144+
```java
145+
Stripe.enableTelemetry = false;
146+
```
147+
133148
## Development
134149

135150
The test suite depends on [stripe-mock], so make sure to fetch and run it from a
136151
background terminal ([stripe-mock's README][stripe-mock] also contains
137152
instructions for installing via Homebrew and other methods):
138153

139-
go get -u github.com/stripe/stripe-mock
140-
stripe-mock
154+
```sh
155+
go get -u github.com/stripe/stripe-mock
156+
stripe-mock
157+
```
141158

142159
You must have Gradle installed. To run the tests:
143160

144-
./gradlew test
161+
```sh
162+
./gradlew test
163+
```
145164

146165
You can run particular tests by passing `--tests Class#method`. Make sure you use the fully qualified class name. For example:
147166

148-
./gradlew test --tests com.stripe.model.AccountTest
149-
./gradlew test --tests com.stripe.functional.ChargeTest
150-
./gradlew test --tests com.stripe.functional.ChargeTest.testChargeCreate
167+
```sh
168+
./gradlew test --tests com.stripe.model.AccountTest
169+
./gradlew test --tests com.stripe.functional.ChargeTest
170+
./gradlew test --tests com.stripe.functional.ChargeTest.testChargeCreate
171+
```
151172

152173
The library uses [Spotless][spotless] along with
153174
[google-java-format][google-java-format] for code formatting. Code must be
154175
formatted before PRs are submitted, otherwise CI will fail. Run the formatter
155176
with:
156177

157-
./gradlew spotlessApply
178+
```sh
179+
./gradlew spotlessApply
180+
```
158181

159182
The library uses [Project Lombok][lombok]. While it is not a requirement, you might want to install a [plugin][lombok-plugins] for your favorite IDE to facilitate development.
160183

src/main/java/com/stripe/Stripe.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class Stripe {
1717

1818
public static volatile String apiKey;
1919
public static volatile String clientId;
20-
public static volatile boolean enableTelemetry = false;
20+
public static volatile boolean enableTelemetry = true;
2121
public static volatile String partnerId;
2222

2323
// Note that URLConnection reserves the value of 0 to mean "infinite

src/test/java/com/stripe/functional/TelemetryTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ public void testTelemetryEnabled() throws StripeException, IOException, Interrup
4242
Stripe.enableTelemetry = true;
4343

4444
Balance.retrieve();
45-
RecordedRequest request1 = server.takeRequest();
46-
assertNull(request1.getHeader("X-Stripe-Client-Telemetry"));
45+
// The first request may or may not include a `X-Stripe-Client-Telemetry` header depending on
46+
// whether this test is the first to run or not. So we don't test the presence or absence of
47+
// the header for the first request.
48+
// Ideally we'd have a way of emptying the request metrics queue, but it's private and I don't
49+
// want to make it public just for tests.
4750

4851
Balance.retrieve();
4952
RecordedRequest request2 = server.takeRequest();

0 commit comments

Comments
 (0)