Hi What is the best way to add a unique identifier to a span? I need this in order to query a unique span using SpanQuery. Would this be the way? Is there a better way?
@using_metadata({"conversation_id": uuid.uuid4()})
@tracer.tool()
def my_function()And then query with:
uery = SpanQuery().where(
"metadata["conversation_id"] == 'cd273007-cd71-4c49-b7....'"
)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: LBKSfrom openinference.instrumentation import using_metadata import uuidLBKS@using_metadata({"conversation_id": str(uuid.uuid4())}) def my_function(): ...LBKSYou can then query with: LBKSquery = SpanQuery().where( "metadata['conversation_id'] == 'cd273007-cd71-4c49-b7....'" )LBKSThis 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 Customize Spans: Specifying Metadata and SpanQuery filtering on metadata.Would you like more detail or code examples?Sources:
- 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
๐กย Hint: Mention RunLLM in the thread for followups.
