From fec7343641816c7229f91b555cf609816279f9f8 Mon Sep 17 00:00:00 2001 From: Sam Lijin Date: Tue, 2 Jul 2024 15:50:54 -0700 Subject: [PATCH] wire results up --- engine/baml-runtime/src/lib.rs | 4 ++-- engine/baml-runtime/src/tracing/api_wrapper/mod.rs | 8 ++++---- engine/baml-runtime/src/tracing/mod.rs | 9 ++++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/engine/baml-runtime/src/lib.rs b/engine/baml-runtime/src/lib.rs index b01844bbf..31bf9180b 100644 --- a/engine/baml-runtime/src/lib.rs +++ b/engine/baml-runtime/src/lib.rs @@ -81,7 +81,7 @@ impl BamlRuntime { .collect(); Ok(BamlRuntime { inner: InternalBamlRuntime::from_directory(path)?, - tracer: BamlTracer::new(None, env_vars.into_iter()).into(), + tracer: BamlTracer::new(None, env_vars.into_iter())?.into(), env_vars: copy, }) } @@ -97,7 +97,7 @@ impl BamlRuntime { .collect(); Ok(BamlRuntime { inner: InternalBamlRuntime::from_file_content(root_path, files)?, - tracer: BamlTracer::new(None, env_vars.into_iter()).into(), + tracer: BamlTracer::new(None, env_vars.into_iter())?.into(), env_vars: copy, }) } diff --git a/engine/baml-runtime/src/tracing/api_wrapper/mod.rs b/engine/baml-runtime/src/tracing/api_wrapper/mod.rs index f3dc75d53..98637d498 100644 --- a/engine/baml-runtime/src/tracing/api_wrapper/mod.rs +++ b/engine/baml-runtime/src/tracing/api_wrapper/mod.rs @@ -348,12 +348,12 @@ impl BoundaryTestAPI for APIWrapper { } impl APIWrapper { - pub fn from_env_vars>(value: impl Iterator) -> Self { + pub fn from_env_vars>(value: impl Iterator) -> Result { let config = env_setup::Config::from_env_vars(value).unwrap(); if config.log_redaction_enabled { log::info!("Redaction enabled: {}", config.log_redaction_enabled); } - match (&config.secret, &config.project_id) { + Ok(match (&config.secret, &config.project_id) { (Some(api_key), Some(project_id)) => Self { config: APIConfig::Web(CompleteAPIConfig { base_url: config.base_url, @@ -362,7 +362,7 @@ impl APIWrapper { stage: config.stage, sessions_id: config.sessions_id, host_name: config.host_name, - client: create_tracing_client().unwrap(), + client: create_tracing_client()?, log_redaction_enabled: config.log_redaction_enabled, log_redaction_placeholder: config.log_redaction_placeholder, }), @@ -379,7 +379,7 @@ impl APIWrapper { log_redaction_placeholder: config.log_redaction_placeholder, }), }, - } + }) } pub fn enabled(&self) -> bool { diff --git a/engine/baml-runtime/src/tracing/mod.rs b/engine/baml-runtime/src/tracing/mod.rs index 472b9238f..2840d3285 100644 --- a/engine/baml-runtime/src/tracing/mod.rs +++ b/engine/baml-runtime/src/tracing/mod.rs @@ -65,8 +65,11 @@ impl BamlTracer { pub fn new>( options: Option, env_vars: impl Iterator, - ) -> Self { - let options = options.unwrap_or_else(|| APIWrapper::from_env_vars(env_vars)); + ) -> Result { + let options = match options { + Some(wrapper) => wrapper, + None => APIWrapper::from_env_vars(env_vars)?, + }; let tracer = BamlTracer { tracer: if options.enabled() { @@ -83,7 +86,7 @@ impl BamlTracer { n_spans_failed_before_submit: 0, })), }; - tracer + Ok(tracer) } #[cfg(not(target_arch = "wasm32"))]