Skip to content

Reorganize Process to include extra global states #4195

@rami3l

Description

@rami3l

This was part of the original plan after #3803, but we probably have put it aside for a while:

In #4182 (comment), I've noticed that the current Process abstraction should probably be extended to allow the existence of a tracing_subscriber global state, so that we can handle graceful shutdown more easily.

Having noticed the clear pattern here:

#[cfg(feature = "otel")]
opentelemetry::global::set_text_map_propagator(
opentelemetry_sdk::propagation::TraceContextPropagator::new(),
);
let (subscriber, console_filter) = rustup::cli::log::tracing_subscriber(&process);
tracing::subscriber::set_global_default(subscriber)?;
let result = run_rustup(&process, console_filter).await;
// We're tracing, so block until all spans are exported.
#[cfg(feature = "otel")]
opentelemetry::global::shutdown_tracer_provider();

... it should probably be modeled as an RAII guard.

I have also noticed that this should resolve another problem, i.e. the corresponding construct in tests is simply no longer used, as these two functions no longer have a caller:

rustup/src/test.rs

Lines 235 to 250 in 52e6070

pub async fn before_test_async() {
#[cfg(feature = "otel")]
{
opentelemetry::global::set_text_map_propagator(
opentelemetry_sdk::propagation::TraceContextPropagator::new(),
);
}
}
pub async fn after_test_async() {
#[cfg(feature = "otel")]
{
// We're tracing, so block until all spans are exported.
opentelemetry::global::shutdown_tracer_provider();
}
}

This is most probably caused by the removal of rustup_macros (d60f005): indeed, the tests are passing on the CI, but sometimes one might want to run tests with otel on as well.

@djc What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions