Skip to content

Commit bd17c16

Browse files
authored
Add warning about assigning the uninstaller to '_' (open-telemetry#372)
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.
1 parent 89882c6 commit bd17c16

File tree

6 files changed

+9
-1
lines changed

6 files changed

+9
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ use opentelemetry::{exporter::trace::stdout, trace::Tracer};
3737

3838
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
3939
// Create a new instrumentation pipeline
40+
// Note: uninstalling the tracer happens when the _uninstall
41+
// variable is dropped. Assigning it to _ will immediately
42+
// drop it and uninstall the tracer
4043
let (tracer, _uninstall) = stdout::new_pipeline().install();
4144

4245
tracer.in_span("doing_work", |cx| {

opentelemetry-contrib/src/trace/exporter/datadog/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,5 +285,6 @@ impl trace::SpanExporter for DatadogExporter {
285285
}
286286

287287
/// Uninstalls the Datadog pipeline on drop
288+
#[must_use]
288289
#[derive(Debug)]
289290
pub struct Uninstall(global::TracerProviderGuard);

opentelemetry-jaeger/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ pub fn new_pipeline() -> PipelineBuilder {
226226
}
227227

228228
/// Guard that uninstalls the Jaeger trace pipeline when dropped
229+
#[must_use]
229230
#[derive(Debug)]
230231
pub struct Uninstall(global::TracerProviderGuard);
231232

opentelemetry-otlp/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ impl OtlpPipelineBuilder {
232232
}
233233

234234
/// Uninstalls the OTLP pipeline on drop
235+
#[must_use]
235236
#[derive(Debug)]
236237
pub struct Uninstall(global::TracerProviderGuard);
237238

opentelemetry-zipkin/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ impl trace::SpanExporter for Exporter {
324324
}
325325

326326
/// Uninstalls the Zipkin pipeline on drop.
327+
#[must_use]
327328
#[derive(Debug)]
328329
pub struct Uninstall(global::TracerProviderGuard);
329330

opentelemetry/src/exporter/trace/stdout.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ where
147147
}
148148
}
149149

150-
/// Uninstalls the stdout pipeline on dropping.
150+
/// Uninstalls the stdout pipeline on drop.
151+
#[must_use]
151152
#[derive(Debug)]
152153
pub struct Uninstall(global::TracerProviderGuard);
153154

0 commit comments

Comments
 (0)