Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/balancerd/src/bin/balancerd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn main() {
.expect("Failed building the Runtime");

let metrics_registry = MetricsRegistry::new();
let (tracing_handle, _tracing_guard) = runtime
let tracing_handle = runtime
.block_on(args.tracing.configure_tracing(
StaticTracingConfig {
service_name: "balancerd",
Expand All @@ -201,7 +201,6 @@ fn main() {
if let Err(err) = res {
panic!("balancer: fatal: {}", err.display_with_causes());
}
drop(_tracing_guard);
}

pub async fn run(args: ServiceArgs, tracing_handle: TracingHandle) -> Result<(), anyhow::Error> {
Expand Down
3 changes: 1 addition & 2 deletions src/catalog-debug/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ async fn main() {
enable_version_flag: true,
});

let (_, _tracing_guard) = args
.tracing
args.tracing
.configure_tracing(
StaticTracingConfig {
service_name: "catalog-debug",
Expand Down
2 changes: 1 addition & 1 deletion src/clusterd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub fn main() {

async fn run(args: Args) -> Result<(), anyhow::Error> {
let metrics_registry = MetricsRegistry::new();
let (tracing_handle, _tracing_guard) = args
let tracing_handle = args
.tracing
.configure_tracing(
StaticTracingConfig {
Expand Down
2 changes: 1 addition & 1 deletion src/environmentd/src/environmentd/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ fn run(mut args: Args) -> Result<(), anyhow::Error> {
};

let metrics_registry = MetricsRegistry::new();
let (tracing_handle, _tracing_guard) = runtime.block_on(args.tracing.configure_tracing(
let tracing_handle = runtime.block_on(args.tracing.configure_tracing(
StaticTracingConfig {
service_name: "environmentd",
build_info: BUILD_INFO,
Expand Down
12 changes: 4 additions & 8 deletions src/environmentd/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ use mz_ore::now::{EpochMillis, NowFn, SYSTEM_TIME};
use mz_ore::retry::Retry;
use mz_ore::task;
use mz_ore::tracing::{
OpenTelemetryConfig, StderrLogConfig, StderrLogFormat, TracingConfig, TracingGuard,
TracingHandle,
OpenTelemetryConfig, StderrLogConfig, StderrLogFormat, TracingConfig, TracingHandle,
};
use mz_persist_client::PersistLocation;
use mz_persist_client::cache::PersistClientCache;
Expand Down Expand Up @@ -680,7 +679,7 @@ impl Listeners {
orchestrator,
config.orchestrator_tracing_cli_args,
));
let (tracing_handle, tracing_guard) = if config.enable_tracing {
let tracing_handle = if config.enable_tracing {
let config = TracingConfig::<fn(&tracing::Metadata) -> sentry_tracing::EventFilter> {
service_name: "environmentd",
stderr_log: StderrLogConfig {
Expand All @@ -705,10 +704,9 @@ impl Listeners {
registry: metrics_registry.clone(),
capture: config.capture,
};
let (tracing_handle, tracing_guard) = mz_ore::tracing::configure(config).await?;
(tracing_handle, Some(tracing_guard))
mz_ore::tracing::configure(config).await?
} else {
(TracingHandle::disabled(), None)
TracingHandle::disabled()
};
let host_name = format!(
"localhost:{}",
Expand Down Expand Up @@ -800,7 +798,6 @@ impl Listeners {
metrics_registry,
_temp_dir: temp_dir,
_scratch_dir: scratch_dir,
_tracing_guard: tracing_guard,
})
}
}
Expand All @@ -812,7 +809,6 @@ pub struct TestServer {
/// The `TempDir`s are saved to prevent them from being dropped, and thus cleaned up too early.
_temp_dir: Option<TempDir>,
_scratch_dir: TempDir,
_tracing_guard: Option<TracingGuard>,
}

impl TestServer {
Expand Down
4 changes: 2 additions & 2 deletions src/orchestrator-tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use mz_ore::netio::SocketAddr;
use mz_ore::tracing::TokioConsoleConfig;
use mz_ore::tracing::{
OpenTelemetryConfig, SentryConfig, StderrLogConfig, StderrLogFormat, TracingConfig,
TracingGuard, TracingHandle,
TracingHandle,
};
use mz_tracing::CloneableEnvFilter;
use opentelemetry::KeyValue;
Expand Down Expand Up @@ -268,7 +268,7 @@ impl TracingCliArgs {
build_info,
}: StaticTracingConfig,
registry: MetricsRegistry,
) -> Result<(TracingHandle, TracingGuard), anyhow::Error> {
) -> Result<TracingHandle, anyhow::Error> {
mz_ore::tracing::configure(TracingConfig {
service_name,
stderr_log: StderrLogConfig {
Expand Down
3 changes: 1 addition & 2 deletions src/orchestratord/src/bin/orchestratord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ async fn main() {

async fn run(args: Args) -> Result<(), anyhow::Error> {
let metrics_registry = MetricsRegistry::new();
let (_, _tracing_guard) = args
.tracing
args.tracing
.configure_tracing(
StaticTracingConfig {
service_name: "orchestratord",
Expand Down
39 changes: 9 additions & 30 deletions src/ore/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,6 @@ impl std::fmt::Debug for TracingHandle {
}
}

/// A guard for the tracing infrastructure configured with [`configure`].
///
/// This guard should be kept alive for the lifetime of the program.
#[must_use = "Must hold for the lifetime of the program, otherwise tracing will be shutdown"]
pub struct TracingGuard {
_sentry_guard: Option<sentry::ClientInitGuard>,
}

impl Drop for TracingGuard {
fn drop(&mut self) {
opentelemetry::global::shutdown_tracer_provider();
}
}

impl std::fmt::Debug for TracingGuard {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("TracingGuard").finish_non_exhaustive()
}
}

// Note that the following defaults are used on startup, regardless of the
// parameters in LaunchDarkly. If we need to, we can add cli flags to control
// then going forward.
Expand Down Expand Up @@ -331,9 +311,7 @@ pub static GLOBAL_SUBSCRIBER: OnceLock<GlobalSubscriber> = OnceLock::new();
// Setting up OpenTelemetry in the background requires we are in a Tokio runtime
// context, hence the `async`.
#[allow(clippy::unused_async)]
pub async fn configure<F>(
config: TracingConfig<F>,
) -> Result<(TracingHandle, TracingGuard), anyhow::Error>
pub async fn configure<F>(config: TracingConfig<F>) -> Result<TracingHandle, anyhow::Error>
where
F: Fn(&tracing::Metadata<'_>) -> sentry_tracing::EventFilter + Send + Sync + 'static,
{
Expand Down Expand Up @@ -525,7 +503,7 @@ where
None
};

let (sentry_guard, sentry_layer, sentry_reloader): (_, _, DirectiveReloader) =
let (sentry_layer, sentry_reloader): (_, DirectiveReloader) =
if let Some(sentry_config) = config.sentry {
let guard = sentry::init((
sentry_config.dsn,
Expand All @@ -537,6 +515,10 @@ where
},
));

// Forgetting the guard ensures that the Sentry transport won't shut down for the
// lifetime of the process.
std::mem::forget(guard);

sentry::configure_scope(|scope| {
scope.set_tag("service_name", config.service_name);
scope.set_tag("build_sha", config.build_sha.to_string());
Expand Down Expand Up @@ -589,10 +571,10 @@ where
}
Ok(filter_handle.reload(filter)?)
});
(Some(guard), Some(layer), reloader)
(Some(layer), reloader)
} else {
let reloader = Arc::new(|_| Ok(()));
(None, None, reloader)
(None, reloader)
};

#[cfg(feature = "capture")]
Expand Down Expand Up @@ -627,11 +609,8 @@ where
opentelemetry: otel_reloader,
sentry: sentry_reloader,
};
let guard = TracingGuard {
_sentry_guard: sentry_guard,
};

Ok((handle, guard))
Ok(handle)
}

/// Returns the [`Level`] of a crate from an [`EnvFilter`] by performing an
Expand Down
3 changes: 1 addition & 2 deletions src/persist-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn main() {
.build()
.expect("Failed building the Runtime");

let (_, _tracing_guard) = runtime
runtime
.block_on(args.tracing.configure_tracing(
StaticTracingConfig {
service_name: "persistcli",
Expand Down Expand Up @@ -87,5 +87,4 @@ fn main() {
eprintln!("persistcli: fatal: {}", err.display_with_causes());
std::process::exit(1);
}
drop(_tracing_guard);
}
2 changes: 1 addition & 1 deletion src/sqllogictest/src/bin/sqllogictest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async fn main() -> ExitCode {
startup_log_filter: args.log_filter.clone(),
..Default::default()
};
let (tracing_handle, _tracing_guard) = tracing_args
let tracing_handle = tracing_args
.configure_tracing(
StaticTracingConfig {
service_name: "sqllogictest",
Expand Down
2 changes: 1 addition & 1 deletion src/storage/examples/upsert_open_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ fn main() {
.build()
.expect("Failed building the Runtime");

let _ = runtime
runtime
.block_on(args.tracing.configure_tracing(
StaticTracingConfig {
service_name: "upsert-open-loop",
Expand Down