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

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

export const plans_0 = "Any"

export const deployments_0 = "Any"

export const data_plane_version_0 = undefined

export const use_case_0 = "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"

<Note>
  **Applies to:**

  * Plan - {plans_0}
  * Deployment - {deployments_0}
  * {data_plane_version_0}
  * {use_case_0}
</Note>

## 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.
