def instrument_resume(agent: Agent, *, tracer: Tracer) -> Agent:
# Instrument `a_resume` as a resumed conversation span
if hasattr(agent, "a_resume") and not hasattr(agent.a_resume, "__otel_wrapped__"):
old_a_resume = agent.a_resume
async def a_resume_traced(
*args: Any,
**kwargs: Any,
) -> Any:
with tracer.start_as_current_span(f"conversation {agent.name}") as span:
span.set_attribute("ag2.span.type", SpanType.CONVERSATION.value)
span.set_attribute("gen_ai.operation.name", "conversation")
span.set_attribute("gen_ai.agent.name", agent.name)
span.set_attribute("gen_ai.conversation.resumed", True)
return await old_a_resume(*args, **kwargs)
a_resume_traced.__otel_wrapped__ = True
agent.a_resume = a_resume_traced
return agent