Traces appear empty or stuck in progress
Last updated: March 5, 2026
Summary
Issue: Traces display empty fields or remain "in progress" indefinitely.
Cause: Application terminates before flush() completes or spans aren't properly ended, particularly in serverless/container environments.
Resolution: Explicitly call flush() before termination and ensure all spans are ended.
Applicable To
Plans: Free, Pro, Enterprise
Deployments: Braintrust Hosted, Hybrid
Use case: Logging with async batch operations in short-lived processes (serverless functions, scripts, containers)
Resolution Steps
Step 1: Use context managers (recommended)
Python
with logger.start_span(name="operation") as span:
span.log(input=input_data, output=output_data, metadata=metadata)
# span.end() called automaticallyTypeScript
await logger.traced(async (span) => {
span.log({ input: inputData, output: outputData, metadata });
// span.end() called automatically
});Step 2: Call flush() explicitly before process exit
Python
def cleanup_braintrust():
try:
project.logger.flush() # Blocks until upload completes
except Exception:
logging.exception("Failed to flush Braintrust project")TypeScript
async function cleanupBraintrust() {
try {
await project.logger.flush(); // Waits until upload completes
} catch (error) {
console.error("Failed to flush Braintrust project:", error);
}
}Key Points
flush()waits for completionContext managers automatically call
span.end()Manual spans: call
span.end()in finally blocks or they remain incompleteFor serverless functions, call
flush()before the handler returns