> ## Documentation Index
> Fetch the complete documentation index at: https://docs.braintrust.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Trace gaps when exported span context is not persisted across restarts

> [!NOTE]
>
> **Applies to:**
>
> * Plan - Any
> * Deployment - Any
> *
> * Use case: Multi-turn chatbot or agent applications that persist conversation state across server restarts or pod replacements and use parent\_span\_export to maintain trace continuity

## Summary

**Issue:** Traces for existing conversations using `span.export()` stop appearing in production logs after a server restart while new conversations continue to log correctly.

**Cause:** Exported span context is not persisted across restarts. Without it, the SDK creates an orphan span with no parent instead of continuing the existing trace.

**Resolution:** Persist exported span context to a durable store (e.g., a database) and reload it when needed to maintain trace continuity.

***

## Resolution steps

### Persist exported span context to maintain trace continuity

#### Step 1: Store exported span context in a durable location

Save the exported context to a database or persistent store after each operation.

```python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
exported_context = span.export()

# Store in database, Redis, or other persistent store
db.set(conversation_key, exported_context)
```

#### Step 2: Retrieve and use the context for subsequent operations

Load the stored context before creating new spans to maintain the trace relationship.

```python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
exported_context = db.get(conversation_key)

if exported_context:
    span = bt.start_span(name="operation", parent=exported_context)
else:
    span = bt.start_span(name="operation")

# Continue span logic before closing it and flushing
```

#### Step 3: Verify trace continuity

After implementing persistence, confirm that operations appearing after a restart continue under the existing trace rather than creating new orphaned traces.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.