Hi, we use span.set_attribute(SpanAttributes.METADATA, json.dumps(...)) to set metadata. Just found that any subsequent call to span.set_attribute(SpanAttributes.METADATA, json.dumps(...)) will override the previous metadata. We cannot combine these as they are from 2 unrelated parts of the code operating on the same span. How should we handle this?
Setting span.set_attribute(SpanAttributes.METADATA, ...) multiple times will overwrite the previous value, as span attributes are key-value pairs and not merged automatically. There is no built-in support in Phoenix or OpenInference for merging metadata from multiple sources into a single attribute; each call replaces the previous value (customize spans docs, OpenInference context managers).To avoid overwriting, you must aggregate all metadata into a single dictionary before setting the attribute, or use distinct keys for each metadata source (e.g., metadata.part1, metadata.part2). There is no documented mechanism to merge or append to the same attribute key from different code locations (customize spans docs).Would you like more detail or example code for aggregating metadata?Sources:
- https://arize.com/docs/phoenix/tracing/how-to-tracing/add-metadata/customize-spans#python-3
- https://github.com/Arize-ai/phoenix/blob/main/docs/tracing/how-to-tracing/add-metadata/customize-spans.md
💡 Hint: Mention RunLLM in the thread for followups.
RunLLM attributes are not overwritten with subsequent calls right? Only metadata is overwritten?
All span attributes—including metadata—are overwritten on subsequent calls to span.set_attribute(key, value) for the same key. This is standard OpenTelemetry and Phoenix behavior: setting the same attribute key again replaces the previous value, regardless of whether the key is metadata or any other attribute (OpenTelemetry attribute spec, customize spans docs).So, any attribute (not just metadata) will be overwritten if set multiple times with the same key.Would you like more detail or examples?Sources:
- https://arize.com/docs/phoenix/tracing/how-to-tracing/add-metadata/customize-spans#python-3
- OpenTelemetry attribute spec
💡 Hint: Mention RunLLM in the thread for followups.
I see, so this gets overwritten since SpanAttribute.METADATA is used as the key. Makes sense. RunLLM (or any humans 🙇) are there examples of how to query in phoenix using custom attributes? Because of the overwriting issue, I cannot use metadata for filtering and I can't find any example in phoenix docs to filter using custom attributes.
Yes, you can filter spans in Phoenix using any custom attribute by referencing its key directly in the query/filter expression. For example, if you set a custom attribute like span.set_attribute("customerID.name", "12345"), you can filter with customerID.name == "12345" in the Phoenix UI or in a SpanQuery (custom spans docs, filter spans docs).Example: LBKSfrom phoenix.trace.dsl import SpanQueryLBKSquery = SpanQuery().where('customerID.name == "12345"') df = px.Client().query_spans(query)LBKSOr in the UI search bar: customerID.name == "12345"Would you like more detail or more code examples?Sources:
- https://arize.com/docs/phoenix/how-to/extract-data-from-spans#how-to-apply-filters-ui
💡 Hint: Mention RunLLM in the thread for followups.
