Applies to:
- Plan:
- Deployment:
Summary
Issue: The errorMismatch between expected span parent object type project_logs and provided type experiment occurs when mixing logger and experiment contexts in the same trace hierarchy.
Cause: init_logger() creates project_logs spans while braintrust.init() creates experiment spans — these cannot be mixed as parent/child spans in the same trace.
Resolution: Use separate instances for logging and experiments, ensuring child spans match their parent’s container type.
Why this happens with multiple projects
When using a single project withset_current=True, Braintrust uses one global context for all spans. The error occurs with multiple projects because:
- Multiple loggers require
set_current=Falseto prevent overwriting each other’s state - Without a global context, spans need explicit parent-child relationships
- Parent spans from
init_logger()export asproject_logstype - Child spans from experiments expect
experimenttype parents - The type mismatch triggers the assertion error
Resolution steps
If you only need logging
Step 1: Initialize with login
Step 2: Use logger instances directly
If you only need experiments
Step 1: Use init for experiments
Step 2: Create experiment spans
If you need both logging and experiments
Step 1: Maintain separate instances per context type
Step 2: Route to correct instance at runtime
Warning:BraintrustCallbackHandlerattaches to the active parent context. If the parent originated frominit_logger()but you’re inside an experiment trace, the mismatch error will occur.
Alternative: Use single logger only
If experiment tracking isn’t required, use oneinit_logger() with set_current=True: