Skip to main content
Applies to:
  • Plan -
  • Deployment -

Summary

Issue: The error Mismatch 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 with set_current=True, Braintrust uses one global context for all spans. The error occurs with multiple projects because:
  • Multiple loggers require set_current=False to prevent overwriting each other’s state
  • Without a global context, spans need explicit parent-child relationships
  • Parent spans from init_logger() export as project_logs type
  • Child spans from experiments expect experiment type 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: BraintrustCallbackHandler attaches to the active parent context. If the parent originated from init_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 one init_logger() with set_current=True: