Skip to main content
A tool call is one tool execution inside a run. In Lemma custom instrumentation, tool calls are child spans created around each tool invocation.

Required

Create a child span for each tool call and include the tool name:
from opentelemetry import trace

tracer = trace.get_tracer("my-agent")

async def call_weather_tool(city: str):
    with tracer.start_as_current_span("tool.call") as tool_span:
        tool_span.set_attribute("tool.name", "get_weather")
        tool_span.set_attribute("tool.args", f'{{"city":"{city}"}}')

        result = await get_weather(city)
        tool_span.set_attribute("tool.result", str(result))
        return result

Optional tool-call data

Recommended attributes:
  • tool.name
  • tool.args
  • tool.result
  • tool.status
  • tool.duration_ms (if you compute it separately)
For large payloads, store summary fields (for example, counts or IDs) instead of full bodies.

Mark a tool call as failed

with tracer.start_as_current_span("tool.call") as tool_span:
    tool_span.set_attribute("tool.name", "get_weather")
    try:
        result = await get_weather("London")
    except Exception as err:
        tool_span.record_exception(err)
        tool_span.set_attribute("tool.status", "error")
        raise

Dashboard outcome

Tool-call spans appear under the active run and show:
  • which tool was used
  • what arguments were passed
  • what result was returned
  • whether the tool failed
This makes bad arguments, retries, and unnecessary calls easy to diagnose.

Next Steps