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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/goose-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["registry"] }
tokio = { version = "1.0", features = ["full"] }
include_dir = "0.7.4"
once_cell = "1.19"

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["wincred"] }
40 changes: 31 additions & 9 deletions crates/goose-bench/src/error_capture.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
use crate::eval_suites::BenchAgentError;
use chrono::Utc;
use once_cell::sync::Lazy;
use std::sync::Arc;
use std::sync::RwLock;
use tokio::sync::Mutex;
use tracing::{Event, Subscriber};
use tracing_subscriber::layer::Context;
use tracing_subscriber::Layer;

pub struct ErrorCaptureLayer {
errors: Arc<Mutex<Vec<BenchAgentError>>>,
// Type alias to reduce complexity
type ErrorRegistry = RwLock<Option<Arc<Mutex<Vec<BenchAgentError>>>>>;

// Global registry for error vectors
static ERROR_REGISTRY: Lazy<ErrorRegistry> = Lazy::new(|| RwLock::new(None));

pub struct ErrorCaptureLayer;

impl Default for ErrorCaptureLayer {
fn default() -> Self {
Self
}
}

impl ErrorCaptureLayer {
pub fn new(errors: Arc<Mutex<Vec<BenchAgentError>>>) -> Self {
Self { errors }
pub fn new() -> Self {
Self
}

pub fn register_error_vector(errors: Arc<Mutex<Vec<BenchAgentError>>>) {
if let Ok(mut registry) = ERROR_REGISTRY.write() {
*registry = Some(errors);
}
}
}

Expand All @@ -33,11 +51,15 @@ where
timestamp: Utc::now(),
};

let errors = self.errors.clone();
tokio::spawn(async move {
let mut errors = errors.lock().await;
errors.push(error);
});
// Get the current error vector from the registry
if let Ok(registry) = ERROR_REGISTRY.read() {
if let Some(errors) = registry.clone() {
tokio::spawn(async move {
let mut errors = errors.lock().await;
errors.push(error);
});
}
}
}
}
}
Expand Down
18 changes: 4 additions & 14 deletions crates/goose-cli/src/commands/bench.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
use crate::logging;
use crate::session::build_session;
use crate::Session;
use async_trait::async_trait;
use goose::config::Config;
use goose::message::Message;
use goose_bench::bench_work_dir::BenchmarkWorkDir;
use goose_bench::error_capture::ErrorCaptureLayer;
use goose_bench::eval_suites::{BenchAgent, BenchAgentError, Evaluation, EvaluationSuiteFactory};
use goose_bench::reporting::{BenchmarkResults, EvaluationResult, SuiteResult};
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::Once;
use tokio::sync::Mutex;
use tracing_subscriber::layer::SubscriberExt;

// Used to ensure we only set up tracing once
static INIT: Once = Once::new();

pub struct BenchSession {
session: Session,
Expand All @@ -26,14 +21,9 @@ impl BenchSession {
pub fn new(session: Session) -> Self {
let errors = Arc::new(Mutex::new(Vec::new()));

// Create and register the error capture layer only once
INIT.call_once(|| {
let error_layer = ErrorCaptureLayer::new(errors.clone());
let subscriber = tracing_subscriber::Registry::default().with(error_layer);

tracing::subscriber::set_global_default(subscriber)
.expect("Failed to set tracing subscriber");
});
// Initialize logging with error capture
logging::setup_logging(Some("bench"), Some(errors.clone()))
.expect("Failed to initialize logging");

Self { session, errors }
}
Expand Down
2 changes: 1 addition & 1 deletion crates/goose-cli/src/commands/mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tokio::io::{stdin, stdout};

pub async fn run_server(name: &str) -> Result<()> {
// Initialize logging
crate::logging::setup_logging(Some(&format!("mcp-{name}")))?;
crate::logging::setup_logging(Some(&format!("mcp-{name}")), None)?;

tracing::info!("Starting MCP server");

Expand Down
Loading
Loading