Skip to content

Commit 19a989f

Browse files
committed
close tool span
1 parent d527184 commit 19a989f

File tree

1 file changed

+11
-11
lines changed
  • agentops/instrumentation/providers/openai/wrappers

1 file changed

+11
-11
lines changed

agentops/instrumentation/providers/openai/wrappers/chat.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ def _create_tool_span(parent_span: Span, tool_call_data: Dict[str, Any]) -> Span
3939
# Get the tracer for this module
4040
tracer = get_tracer(__name__)
4141

42-
# Create a child span for the tool call
43-
tool_span = tracer.start_span(
42+
# Create a child span for the tool call using a context manager
43+
with tracer.start_as_current_span(
4444
name=f"tool_call.{tool_call_data['function']['name']}",
4545
kind=SpanKind.INTERNAL,
4646
context=set_span_in_context(parent_span),
47-
)
47+
) as tool_span:
48+
# Set the span kind to TOOL
49+
tool_span.set_attribute("agentops.span.kind", AgentOpsSpanKindValues.TOOL)
4850

49-
# Set the span kind to TOOL
50-
tool_span.set_attribute("agentops.span.kind", AgentOpsSpanKindValues.TOOL)
51+
# Set tool-specific attributes
52+
tool_span.set_attribute(ToolAttributes.TOOL_NAME, tool_call_data["function"]["name"])
53+
tool_span.set_attribute(ToolAttributes.TOOL_PARAMETERS, tool_call_data["function"]["arguments"])
54+
tool_span.set_attribute("tool.call.id", tool_call_data["id"])
55+
tool_span.set_attribute("tool.call.type", tool_call_data["type"])
5156

52-
# Set tool-specific attributes
53-
tool_span.set_attribute(ToolAttributes.TOOL_NAME, tool_call_data["function"]["name"])
54-
tool_span.set_attribute(ToolAttributes.TOOL_PARAMETERS, tool_call_data["function"]["arguments"])
55-
tool_span.set_attribute("tool.call.id", tool_call_data["id"])
56-
tool_span.set_attribute("tool.call.type", tool_call_data["type"])
57-
return tool_span
57+
return tool_span
5858

5959

6060
def handle_chat_attributes(

0 commit comments

Comments
 (0)