How to Preserve Span Attributes in OpenTelemetry without Overwriting
what's the proper way to set attributes within a span without overwriting prev attributes from using_metadata, e.g.
with using_metadata(metadata={'foo': 'bar'}):
...
with self._tracer.start_as_current_span(
func.__class__.__name__,
openinference_span_kind="tool",
) as span:
...
span.set_input(func.model_dump()) # func is a pydantic BaseModel)
output = func.call(func_input)
span.set_output(output.response) # textual response to be fed back to LLM
# Save additional output as metadata
span.set_attribute(
key=semcov_trace.SpanAttributes.METADATA,
value=json.dumps({'x': output.metadata})
),
)it looks that the span attribute will just have {'x': output.metadata} and {'foo': 'bar'} would be gone, what's the proper way to preserve both?
