{"record":{"id":"7a16102313de9336","repo":"BoundaryML/baml","slug":"failed-to-create-bamltracer","errorCode":null,"errorMessage":"Failed to create BamlTracer","messagePattern":"Failed to create BamlTracer","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"engine/baml-runtime/src/lib.rs","lineNumber":195,"sourceCode":"\n    /// Get the tracer for the given env vars, creating a new one if the config changed.\n    pub fn get_or_create_tracer(&self, env_vars: &HashMap<String, String>) -> Arc<BamlTracer> {\n        let filtered = Self::filter_relevant_env_vars(env_vars);\n        let key = Self::env_vars_key(env_vars);\n\n        #[cfg(target_arch = \"wasm32\")]\n        {\n            let mut tracers = self.tracers.lock().unwrap();\n            if let Some(existing) = tracers.get(&key) {\n                if existing.config_matches_env_vars(&filtered) {\n                    return existing.clone();\n                }\n            }\n            // Config changed, clear all and insert new\n            tracers.clear();\n            let new_tracer = Arc::new(\n                BamlTracer::new(None, filtered.clone().into_iter())\n                    .expect(\"Failed to create BamlTracer\"),\n            );\n            tracers.insert(key, new_tracer.clone());\n            new_tracer\n        }\n        #[cfg(not(target_arch = \"wasm32\"))]\n        {\n            if let Some(existing) = self.tracers.get(&key) {\n                if existing.config_matches_env_vars(&filtered) {\n                    let cloned = existing.clone();\n                    return cloned;\n                }\n            }\n            // Config changed, clear all and insert new\n            self.tracers.clear();\n            let new_tracer = Arc::new(\n                BamlTracer::new(None, filtered.clone().into_iter())\n                    .expect(\"Failed to create BamlTracer\"),\n            );","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/lib.rs#L177-L213","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Inspect the filtered env filter/config passed to BamlTracer::new — fix invalid log levels or filter syntax (e.g. RUST_LOG-style directives).","Validate telemetry/exporter settings in the BAML config before applying them.","Avoid reconfiguring the runtime with unvalidated config; validate first, then set.","Check BAML version changelogs for tracer config format changes."],"exampleFix":"// before\ntracer.set_logging_config(LoggingConfig { log_level: \"verbose\".into(), .. }); // invalid level -> panic\n// after\ntracer.set_logging_config(LoggingConfig { log_level: \"info\".into(), .. });","handlingStrategy":"validation","validationCode":"// validate logging config before applying it to the runtime\nconst VALID_LEVELS = [\"off\", \"error\", \"warn\", \"info\", \"debug\", \"trace\"];\nif (!VALID_LEVELS.includes(cfg.log_level)) throw new Error(\"Invalid log level: \" + cfg.log_level);","typeGuard":null,"tryCatchPattern":"// expect() panics instead of returning Err; pre-validate config so BamlTracer::new never fails\n// if you control the code, prefer:\nBamlTracer::new(None, filtered).map(Arc::new)?  // propagate instead of .expect(...)","preventionTips":["Validate log level/filter strings against the supported set before configuring BAML.","Test runtime reconfiguration paths with the same config users will ship.","Pin and review BAML versions for tracer config format changes."],"tags":["panic","tracer","telemetry","configuration"],"backgroundTag":"module-init-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}