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 support for telemetry #1513

Merged
merged 1 commit into from
Feb 13, 2019
Merged

Add support for telemetry #1513

merged 1 commit into from
Feb 13, 2019

Conversation

ob-stripe
Copy link
Contributor

r? @brandur-stripe @jameshageman-stripe

Add support for telemetry. The implementation is fairly similar to stripe-java's: stripe/stripe-java#661.

Copy link

@jameshageman-stripe jameshageman-stripe left a comment

Choose a reason for hiding this comment

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

Thanks for doing this @ob-stripe! As far as I can tell the implementation looks good, and the tests are fantastic.

I added one small note about the concurrent test, but it really is a nitpick more than anything else.

src/StripeTests/Functional/TelemetryTest.cs Show resolved Hide resolved
src/StripeTests/Functional/TelemetryTest.cs Outdated Show resolved Hide resolved
src/StripeTests/Functional/TelemetryTest.cs Show resolved Hide resolved
@ob-stripe
Copy link
Contributor Author

ptal @jameshageman-stripe

@ob-stripe ob-stripe force-pushed the ob-telemetry branch 2 times, most recently from 52ca0c9 to 6b9169c Compare February 13, 2019 14:27
@jameshageman-stripe
Copy link

The pr tests indicate that both of the two requests sent in the concurrent test that have telemetry are both reporting req_1:

HttpClientHandler.SendAsync(Method: GET, RequestUri: 'http://localhost:12111/v1/balance', Version: 1.1, Content: <null>, Headers:
{
  User-Agent: Stripe/v1
  User-Agent: .NetBindings/22.9.0
  Authorization: Bearer sk_test_123
  X-Stripe-Client-User-Agent: {"bindings_version":"22.9.0","lang":".net","publisher":"stripe","lang_version":".NET Core 4.6.25211.01","os_version":"Microsoft Windows 10.0.14393 "}
  Stripe-Version: 2018-11-08
  X-Stripe-Client-Telemetry: {"last_request_metrics":{"request_id":"req_1","request_duration_ms":21}}
}, CancellationToken)
HttpClientHandler.SendAsync(Method: GET, RequestUri: 'http://localhost:12111/v1/balance', Version: 1.1, Content: <null>, Headers:
{
  User-Agent: Stripe/v1
  User-Agent: .NetBindings/22.9.0
  Authorization: Bearer sk_test_123
  X-Stripe-Client-User-Agent: {"bindings_version":"22.9.0","lang":".net","publisher":"stripe","lang_version":".NET Core 4.6.25211.01","os_version":"Microsoft Windows 10.0.14393 "}
  Stripe-Version: 2018-11-08
  X-Stripe-Client-Telemetry: {"last_request_metrics":{"request_id":"req_1","request_duration_ms":22}}
}, CancellationToken)

Don't suspect that this.prevRequestMetrics.TryDequeue(out requestMetrics) is the issue, so maybe theres another subtler problem with the test?

ptal @ob-stripe

@ob-stripe
Copy link
Contributor Author

Ah yes, I think there's a potential race condition in the test itself. Incrementing invocationCount and generating the request ID string isn't an atomic operation, so two concurrent requests may end up with the same request ID. I'll try to fix this.

@ob-stripe
Copy link
Contributor Author

Okay, I've factorized the code for setting up the requests in a FakeServer class and added a lock when incrementing the counter and generating the request ID string to fix the race condition.

ptal @jameshageman-stripe

@jameshageman-stripe
Copy link

@ob-stripe LGTM, thanks!

@ob-stripe ob-stripe merged commit 29a4624 into integration-v23 Feb 13, 2019
@ob-stripe ob-stripe deleted the ob-telemetry branch February 13, 2019 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants