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 warning about assigning the uninstaller to '_' #372

Merged
merged 3 commits into from Dec 2, 2020

Conversation

arlyon
Copy link
Contributor

@arlyon arlyon commented Nov 28, 2020

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.

@arlyon arlyon requested a review from a team as a code owner November 28, 2020 13:21
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 28, 2020

CLA Signed

The committers are authorized under a signed CLA.

@codecov
Copy link

codecov bot commented Nov 28, 2020

Codecov Report

Merging #372 (62f322b) into master (89882c6) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #372   +/-   ##
=======================================
  Coverage   53.52%   53.52%           
=======================================
  Files          72       72           
  Lines        6117     6117           
=======================================
  Hits         3274     3274           
  Misses       2843     2843           
Impacted Files Coverage Δ
opentelemetry/src/exporter/trace/stdout.rs 17.64% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 89882c6...62f322b. Read the comment docs.

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.
Copy link
Member

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.

Copy link
Contributor Author

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.

@jtescher
Copy link
Member

Would be nice if a must assign was available here, but a good step would be to find all of the exporter's Uninstall structs and add #[must_use] to them. At least this would prevent calling install without assigning it to anything, even if assigning them to _ still is a footgun.

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.
Copy link
Member

@jtescher jtescher left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@jtescher jtescher merged commit bd17c16 into open-telemetry:master Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants