Shopify / statsd-instrument

A StatsD client for Ruby apps. Provides metaprogramming methods to inject StatsD instrumentation into your code.
http://shopify.github.io/statsd-instrument
MIT License
570 stars 94 forks source link

Fix new custom client not being passed to expectations bug #293

Closed marijacvetkovik closed 3 years ago

marijacvetkovik commented 3 years ago

While trying to use a custom StatsD client for our project (see https://github.com/Shopify/help/pull/24350) we discovered a bug. The new client was being set properly but the new custom client was not being passed into expectations so there ends up being a discrepancy with the result and the expectation. This is because there is no separate parameter for client when initializing a new expectation and the options that are being passed into StatsD::Instrument::Expectation do not contain the new client and so the expectation ends up defaulting to StatsD.singleton_client.

Explicitly adding the new client to the options as such, and initializing it, ensures that the new client is passed up to expectations:

expectation = StatsD::Instrument::Expectation.increment(metric_name, value, client: client, **options)