-
Notifications
You must be signed in to change notification settings - Fork 27
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
macro variants that do not panic if global default client is not set #210
Comments
Thanks for the issue! I can understand that using the macros makes tests hard to write. I'm not sure about adding non-panicking versions since that seems like it would make it even harder to detect incorrect configurations (and it's already UDP in a lot of cases). I'm curious about your use case and how the macros and statsd are involved in the tests. Does the code under test make metrics calls that you'd like to verify as part of the tests? Or does it just happen to make metrics calls that you don't care about while testing? If it's the latter, there's no harm in calling |
I'm running into the same thing -- for me, at least, it's that there are metrics in code that needs to be tested, but I don't care about the metrics during the tests. As far as I can tell, my options are:
None of these are great, and I also think it might make more sense to have the macros just not panic if there's no global default set, which is what the log crate does for its logging macros. |
It might also be reasonable to have something like a feature flag that sets the default to a dummy macro. That way you could set your test modules to include that feature flag and not have to worry about it, but still get the panic behavior in production builds. |
Do you take PR's? I just tried out this change in macros.rs and it works for my needs.
This causes the macros to expand to nothing if the flag is set, then in my dev-dependencies I specify the disable_metrics feature and things just work. |
I'd rather not introduce a configuration feature for this. If the |
Thank you a lot for this library!
Would it make sense to add variants of the
statsd
macros that do not panic if the global default client is not set?When testing code makes use of the statsd macros it is sometimes awkward to have to initialize the global default client in unit tests to avoid the macros panicking.
Would be happy to contribute a PR to add such macros if you think it would make sense.
Wdyt?
The text was updated successfully, but these errors were encountered: