-
Notifications
You must be signed in to change notification settings - Fork 502
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 warning about assigning the uninstaller to '_' #372
Conversation
|
Codecov Report
@@ Coverage Diff @@
## master #372 +/- ##
=======================================
Coverage 53.52% 53.52%
=======================================
Files 72 72
Lines 6117 6117
=======================================
Hits 3274 3274
Misses 2843 2843
Continue to review full report at Codecov.
|
README.md
Outdated
@@ -37,6 +37,8 @@ use opentelemetry::{exporter::trace::stdout, trace::Tracer}; | |||
|
|||
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { | |||
// Create a new instrumentation pipeline | |||
// Note: using `_` instead of assigning to a variable will immediately | |||
// drop the tracer and uninstall it so make sure to properly assign it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be clearer to have this say that it will drop the uninstall guard and make the tracer a no-op as the tracer won't be dropped unless you assign it to _
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, that is maybe not crystal clear.
Would be nice if a must assign was available here, but a good step would be to find all of the exporter's |
It is common rust convention to use _ to signify an unused variable. Because we _are_ using this (until the end of the block) it is helpful to explain the intent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
It is common rust convention to use _ to signify an unused variable which, to new users who don't understand the inner workings,
_uninstall
is.When integrating the library I spent an hour or so wondering why I was getting no logs until I realised that using
_
drops the value immediately after calling and not when the_
goes out of scope. Obviously this is my fault, but to prevent people from dealing with the same thing I thought a warning front-and-center would be nice.In the long run an alternative to the
must_use
lint (must_assign
or similar) may be a nice alternative.If anyone has some suggestions on where to put this in the code itself rather than just the readme I'm happy to include the warning in the appropriate places.