Mnovich/otlp v2 (#3772)

This commit is contained in:
Max Novich
2025-08-01 12:15:12 -07:00
committed by GitHub
parent 1a8b3b1a42
commit 3b6a92b715
8 changed files with 602 additions and 35 deletions
+26 -15
View File
@@ -9,7 +9,7 @@ use tracing_subscriber::{
};
use goose::config::APP_STRATEGY;
use goose::tracing::langfuse_layer;
use goose::tracing::{langfuse_layer, otlp_layer};
/// Returns the directory where log files should be stored.
/// Creates the directory structure if it doesn't exist.
@@ -91,22 +91,33 @@ pub fn setup_logging(name: Option<&str>) -> Result<()> {
.add_directive(LevelFilter::WARN.into())
});
// Build the subscriber with required layers
let subscriber = Registry::default()
.with(file_layer.with_filter(env_filter))
.with(console_layer.with_filter(LevelFilter::INFO));
let mut layers = vec![
file_layer.with_filter(env_filter).boxed(),
console_layer.with_filter(LevelFilter::INFO).boxed(),
];
// Initialize with Langfuse if available
if let Some(langfuse) = langfuse_layer::create_langfuse_observer() {
subscriber
.with(langfuse.with_filter(LevelFilter::DEBUG))
.try_init()
.context("Failed to set global subscriber")?;
} else {
subscriber
.try_init()
.context("Failed to set global subscriber")?;
if let Ok((otlp_tracing_layer, otlp_metrics_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(),
);
}
if let Some(langfuse) = langfuse_layer::create_langfuse_observer() {
layers.push(langfuse.with_filter(LevelFilter::DEBUG).boxed());
}
let subscriber = Registry::default().with(layers);
subscriber
.try_init()
.context("Failed to set global subscriber")?;
Ok(())
}