BoundaryML/baml · critical

Failed to create BamlTracer

Error message

Failed to create BamlTracer

What it means

Not an anyhow error but a panic: get_or_create_tracer calls BamlTracer::new(...).expect("Failed to create BamlTracer") when configuration changed and a fresh tracer must be built. If BamlTracer::new returns Err (typically invalid telemetry/logging configuration), the runtime panics with this message.

Solutions

  1. Inspect the filtered env filter/config passed to BamlTracer::new — fix invalid log levels or filter syntax (e.g. RUST_LOG-style directives).
  2. Validate telemetry/exporter settings in the BAML config before applying them.
  3. Avoid reconfiguring the runtime with unvalidated config; validate first, then set.
  4. Check BAML version changelogs for tracer config format changes.

Example fix

// before
tracer.set_logging_config(LoggingConfig { log_level: "verbose".into(), .. }); // invalid level -> panic
// after
tracer.set_logging_config(LoggingConfig { log_level: "info".into(), .. });
Defensive patterns

Strategy: validation

Validate before calling

// validate logging config before applying it to the runtime
const VALID_LEVELS = ["off", "error", "warn", "info", "debug", "trace"];
if (!VALID_LEVELS.includes(cfg.log_level)) throw new Error("Invalid log level: " + cfg.log_level);

Try / catch

// expect() panics instead of returning Err; pre-validate config so BamlTracer::new never fails
// if you control the code, prefer:
BamlTracer::new(None, filtered).map(Arc::new)?  // propagate instead of .expect(...)

Prevention

When it happens

Trigger: Changing BAML config at runtime (wasm32 path) such that the tracer cache is cleared and BamlTracer::new is invoked with filtered logger config that it rejects (e.g. invalid log level or exporter settings).

Common situations: Programmatic reconfiguration of BAML logging/telemetry with a bad log level string; OpenTelemetry exporter init failure; invalid filters syntax in configuration; re-setting client config in browser/Node WASM usage.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/7a16102313de9336. Report an issue: GitHub.

Appendix: source

Thrown at engine/baml-runtime/src/lib.rs:195

    /// Get the tracer for the given env vars, creating a new one if the config changed.
    pub fn get_or_create_tracer(&self, env_vars: &HashMap<String, String>) -> Arc<BamlTracer> {
        let filtered = Self::filter_relevant_env_vars(env_vars);
        let key = Self::env_vars_key(env_vars);

        #[cfg(target_arch = "wasm32")]
        {
            let mut tracers = self.tracers.lock().unwrap();
            if let Some(existing) = tracers.get(&key) {
                if existing.config_matches_env_vars(&filtered) {
                    return existing.clone();
                }
            }
            // Config changed, clear all and insert new
            tracers.clear();
            let new_tracer = Arc::new(
                BamlTracer::new(None, filtered.clone().into_iter())
                    .expect("Failed to create BamlTracer"),
            );
            tracers.insert(key, new_tracer.clone());
            new_tracer
        }
        #[cfg(not(target_arch = "wasm32"))]
        {
            if let Some(existing) = self.tracers.get(&key) {
                if existing.config_matches_env_vars(&filtered) {
                    let cloned = existing.clone();
                    return cloned;
                }
            }
            // Config changed, clear all and insert new
            self.tracers.clear();
            let new_tracer = Arc::new(
                BamlTracer::new(None, filtered.clone().into_iter())
                    .expect("Failed to create BamlTracer"),
            );

View on GitHub (pinned to bd85ce9dee)