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

# Clear Context

> Clear a previously attached context and optionally flush pending spans.

> [!WARNING]
>
> You are reading the docs of Galtea 5.11. [Read this page in the latest version](https://docs.galtea.ai/sdk/api/span/clear-context.md).

## Returns

This method returns `None`.

## Example

```python theme={"system"}
clear_context(span_context)
```

## Parameters

**token** `object` *required*

The context token returned by `set_context()`.

**flush** `bool`

If `True` (default), export any pending spans associated with the current trace to the telemetry exporter before detaching the context.

> [!NOTE]
>
> Always use `clear_context()` in a `finally` block to ensure proper cleanup, even if an exception occurs.


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