The recommended way to add a unique identifier to a span in Phoenix is to use the `using_metadata` context manager or decorator, not `using_tags`. Metadata is designed for key-value pairs and is easily queryable in `SpanQuery`. For example:
```
from openinference.instrumentation import using_metadata
import uuid
@using_metadata({"conversation_id": str(uuid.uuid4())})
def my_function():
...
```
You can then query with:
```
query = SpanQuery().where(
"metadata['conversation_id'] == 'cd273007-cd71-4c49-b7....'"
)
```
This approach is explicitly supported and documented for associating custom identifiers with spans and querying them later, while tags are intended for simple string lists, not key-value pairs. See <https://docs.arize.com/phoenix/tracing/how-to-tracing/add-metadata/customize-spans#P:6|Customize Spans: Specifying Metadata> and <https://docs.arize.com/phoenix/tracing/how-to-tracing/importing-and-exporting-traces/extract-data-from-spans#B:8|SpanQuery filtering on metadata>.
Would you like more detail or code examples?
Sources:
- <https://arize-ai.slack.com/archives/C04R3GXC8HK/p1713943466.583669|https://arize-ai.slack.com/archives/C04R3GXC8HK/p1713943466.583669>
- <https://github.com/Arize-ai/phoenix/blob/main/docs/tracing/how-to-tracing/customize-spans.md|https://github.com/Arize-ai/phoenix/blob/main/docs/tracing/how-to-tracing/customize-spans.md>