feat(tvix/store/bin): allow disabling OTLP at runtime

This was only possible by disabling without the otlp feature flag so
far.

Introduce the same --otlp=false mechanism that nar-bridge also supports
to be able to turn it off at runtime.

Change-Id: Ib22a364c35056ca9d8e327c0e2a79970a4cf4b2b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11135
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2024-03-11 18:49:25 +02:00 committed by clbot
parent 4ec596c8f9
commit d327bf775d

View file

@ -51,6 +51,10 @@ struct Cli {
#[arg(long)] #[arg(long)]
json: bool, json: bool,
/// Whether to configure OTLP. Set --otlp=false to disable.
#[arg(long, default_missing_value = "true", default_value = "true", num_args(0..=1), require_equals(true), action(clap::ArgAction::Set))]
otlp: bool,
#[arg(long)] #[arg(long)]
log_level: Option<Level>, log_level: Option<Level>,
@ -184,14 +188,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
), ),
); );
// Add the otlp layer (when otlp is enabled), then init the registry. // Add the otlp layer (when otlp is enabled, and it's not disabled in the CLI)
// Or if the feature is disabled, just init without adding the layer. // then init the registry.
// If the feature is feature-flagged out, just init without adding the layer.
// It's necessary to do this separately, as every with() call chains the // It's necessary to do this separately, as every with() call chains the
// layer into the type of the registry. // layer into the type of the registry.
#[cfg(feature = "otlp")] #[cfg(feature = "otlp")]
{ {
subscriber let subscriber = if cli.otlp {
.with({
let tracer = opentelemetry_otlp::new_pipeline() let tracer = opentelemetry_otlp::new_pipeline()
.tracing() .tracing()
.with_exporter(opentelemetry_otlp::new_exporter().tonic()) .with_exporter(opentelemetry_otlp::new_exporter().tonic())
@ -202,11 +206,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// https://github.com/open-telemetry/opentelemetry-rust/issues/1298 // https://github.com/open-telemetry/opentelemetry-rust/issues/1298
let resources = let resources =
SdkProvidedResourceDetector.detect(std::time::Duration::from_secs(0)); SdkProvidedResourceDetector.detect(std::time::Duration::from_secs(0));
// SdkProvidedResourceDetector currently always sets // SdkProvidedResourceDetector currently always sets
// `service.name`, but we don't like its default. // `service.name`, but we don't like its default.
if resources.get("service.name".into()).unwrap() == "unknown_service".into() if resources.get("service.name".into()).unwrap() == "unknown_service".into() {
{
resources.merge(&Resource::new([KeyValue::new( resources.merge(&Resource::new([KeyValue::new(
"service.name", "service.name",
"tvix.store", "tvix.store",
@ -218,9 +220,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.install_batch(opentelemetry_sdk::runtime::Tokio)?; .install_batch(opentelemetry_sdk::runtime::Tokio)?;
// Create a tracing layer with the configured tracer // Create a tracing layer with the configured tracer
tracing_opentelemetry::layer().with_tracer(tracer) let layer = tracing_opentelemetry::layer().with_tracer(tracer);
})
.try_init()?; subscriber.with(Some(layer))
} else {
subscriber.with(None)
};
subscriber.try_init()?;
} }
// Init the registry (when otlp is not enabled) // Init the registry (when otlp is not enabled)