BoundaryML/baml · error

Function log expected to be present (no FunctionStart event?

Error message

Function log expected to be present (no FunctionStart event?). Did you forget to track_function()?

What it means

BAML's tracing v2 storage looked up the function log entry for a traced function but found no FunctionStart event recorded for its id, so `build_function_log` failed inside `get_inner`. This is an internal invariant violation: any accessor (function_name, log_type, timing, usage, calls, raw_llm_response) on a FunctionLog requires the function to have been registered via track_function() before the event is read.

Source

Thrown at engine/baml-runtime/src/tracingv2/storage/storage.rs:545

        // Manually increment the global reference count
        BAML_TRACER.lock().unwrap().inc_ref(&id);
        let instance_id = Uuid::new_v4().to_string();

        Self {
            id,
            inner: None,
            instance_id,
        }
    }

    // Private helper to get or build the inner reference
    fn get_inner(&mut self) -> &Arc<Mutex<FunctionLogInner>> {
        if self.inner.is_none() {
            // We attempt to build or retrieve from the global tracer
            let maybe_arc = {
                let tracer = BAML_TRACER.lock().unwrap();
                build_function_log(&tracer, &self.id)
                    .expect("Function log expected to be present (no FunctionStart event?). Did you forget to track_function()?")
            };
            self.inner = Some(maybe_arc);
        }
        self.inner.as_ref().unwrap()
    }

    pub fn id(&self) -> FunctionCallId {
        self.id.clone()
    }

    // The methods below clone from the underlying data (no references).
    pub fn function_name(&mut self) -> String {
        self.get_inner().lock().unwrap().function_name.clone()
    }

    pub fn log_type(&mut self) -> String {
        self.get_inner().lock().unwrap().r#type.clone()
    }

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Ensure track_function() is called for the function id before creating or reading any FunctionLog accessors.
  2. Check that the tracing collector (BAML_TRACER) is initialized in the same process/runtime where events are emitted.
  3. Update the BAML runtime and client bindings to matching versions so FunctionStart events are emitted in the expected format.
  4. If you are integrating tracing manually, emit a FunctionStart event for the id before calling get_inner-derived accessors.

Example fix

// before
let log = FunctionLog::new(id);
let usage = log.usage(); // panics: no FunctionStart event

// after
tracer.track_function(&id, "MyFunction"); // register first
let log = FunctionLog::new(id);
let usage = log.usage();
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the function id is tracked before reading log accessors
tracer.track_function(&id, function_name);

Prevention

When it happens

Trigger: Reading properties off a FunctionLog (e.g. .usage(), .timing(), .calls()) whose id was never registered with track_function() in the BAML_TRACER; a FunctionStart tracing event was missing or dropped before the accessor ran.

Common situations: Custom runtime/embedding integrations that construct log handles manually instead of calling track_function(); tracer state lost across thread/async boundaries; version mismatches where the tracing wire protocol changed and FunctionStart events are not emitted; reading a log object for a function whose call never actually started.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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