feat(otel): respect standard OTel env vars for exporter selection (#7144)

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Adrian Cole
2026-02-14 09:03:11 +08:00
committed by GitHub
parent f00630ad20
commit ab5407508b
12 changed files with 621 additions and 595 deletions
+3 -20
View File
@@ -6,7 +6,8 @@ use tracing_subscriber::{
Registry,
};
use goose::tracing::{langfuse_layer, otlp_layer};
use goose::otel::otlp;
use goose::tracing::langfuse_layer;
// Used to ensure we only set up tracing once
static INIT: Once = Once::new();
@@ -68,25 +69,7 @@ fn setup_logging_internal(name: Option<&str>, force: bool) -> Result<()> {
];
if !force {
if let Ok((otlp_tracing_layer, otlp_metrics_layer, otlp_logs_layer)) =
otlp_layer::init_otlp()
{
layers.push(
otlp_tracing_layer
.with_filter(otlp_layer::create_otlp_tracing_filter())
.boxed(),
);
layers.push(
otlp_metrics_layer
.with_filter(otlp_layer::create_otlp_metrics_filter())
.boxed(),
);
layers.push(
otlp_logs_layer
.with_filter(otlp_layer::create_otlp_logs_filter())
.boxed(),
);
}
layers.extend(otlp::init_otlp_layers(goose::config::Config::global()));
}
if let Some(langfuse) = langfuse_layer::create_langfuse_observer() {
+3 -22
View File
@@ -9,28 +9,9 @@ async fn main() -> Result<()> {
let result = cli().await;
// Only wait for telemetry flush if OTLP is configured
let should_wait = goose::config::Config::global()
.get_param::<String>("otel_exporter_otlp_endpoint")
.is_ok();
if should_wait {
// Use a shorter, dynamic wait with max timeout
let max_wait = tokio::time::Duration::from_millis(500);
let start = tokio::time::Instant::now();
// Give telemetry a chance to flush, but don't wait too long
while start.elapsed() < max_wait {
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
// In future, we could check if there are pending spans/metrics here
// For now, we just do a quick wait to allow batch exports to complete
if start.elapsed() >= tokio::time::Duration::from_millis(200) {
break; // Most exports should complete within 200ms
}
}
goose::tracing::shutdown_otlp();
if goose::otel::otlp::is_otlp_initialized() {
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
goose::otel::otlp::shutdown_otlp();
}
result