Skip to content

Commit 5cfcef3

Browse files
fix(SDK + Agno): set gen_ai.tool.name on @tool() decorator and Agno tool spans (#3904)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 78d364b commit 5cfcef3

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

packages/opentelemetry-instrumentation-agno/opentelemetry/instrumentation/agno/_tool_wrappers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __call__(self, wrapped, instance, args, kwargs):
4040
span.set_attribute(SpanAttributes.TRACELOOP_SPAN_KIND,
4141
TraceloopSpanKindValues.TOOL.value)
4242
span.set_attribute(SpanAttributes.TRACELOOP_ENTITY_NAME, function_name)
43+
span.set_attribute(GenAIAttributes.GEN_AI_TOOL_NAME, function_name)
4344

4445
if hasattr(instance.function, 'description') and instance.function.description:
4546
span.set_attribute("tool.description", instance.function.description)
@@ -109,6 +110,7 @@ async def __call__(self, wrapped, instance, args, kwargs):
109110
span.set_attribute(SpanAttributes.TRACELOOP_SPAN_KIND,
110111
TraceloopSpanKindValues.TOOL.value)
111112
span.set_attribute(SpanAttributes.TRACELOOP_ENTITY_NAME, function_name)
113+
span.set_attribute(GenAIAttributes.GEN_AI_TOOL_NAME, function_name)
112114

113115
if hasattr(instance.function, 'description') and instance.function.description:
114116
span.set_attribute("tool.description", instance.function.description)

packages/opentelemetry-instrumentation-agno/tests/test_agent.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def add_numbers(a: int, b: int) -> int:
8888
# so we just check that if they exist, they have the right attributes
8989
for tool_span in tool_spans:
9090
assert tool_span.attributes.get(SpanAttributes.TRACELOOP_ENTITY_NAME) == "add_numbers"
91+
assert tool_span.attributes.get(GenAIAttributes.GEN_AI_TOOL_NAME) == "add_numbers"
9192
assert tool_span.attributes.get(GenAIAttributes.GEN_AI_SYSTEM) == "agno"
9293

9394

@@ -179,6 +180,7 @@ def multiply(a: int, b: int) -> int:
179180
tool_spans = [s for s in spans if s.name == "multiply.tool"]
180181
for tool_span in tool_spans:
181182
assert tool_span.attributes.get(SpanAttributes.TRACELOOP_ENTITY_NAME) == "multiply"
183+
assert tool_span.attributes.get(GenAIAttributes.GEN_AI_TOOL_NAME) == "multiply"
182184
assert tool_span.attributes.get(GenAIAttributes.GEN_AI_SYSTEM) == "agno"
183185

184186

@@ -244,4 +246,5 @@ def multiply(a: int, b: int) -> int:
244246
tool_spans = [s for s in spans if s.name == "multiply.tool"]
245247
for tool_span in tool_spans:
246248
assert tool_span.attributes.get(SpanAttributes.TRACELOOP_ENTITY_NAME) == "multiply"
249+
assert tool_span.attributes.get(GenAIAttributes.GEN_AI_TOOL_NAME) == "multiply"
247250
assert tool_span.attributes.get(GenAIAttributes.GEN_AI_SYSTEM) == "agno"

packages/traceloop-sdk/traceloop/sdk/decorators/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
from opentelemetry.trace.status import Status, StatusCode
1717
from opentelemetry import context as context_api
1818
from opentelemetry.semconv_ai import SpanAttributes, TraceloopSpanKindValues
19+
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import (
20+
GEN_AI_TOOL_NAME,
21+
)
1922

2023
from traceloop.sdk.tracing import get_tracer, set_workflow_name, set_agent_name
2124
from traceloop.sdk.tracing.tracing import (
@@ -141,7 +144,6 @@ def _setup_span(entity_name, tlp_span_kind, version):
141144
set_workflow_name(entity_name)
142145

143146
if tlp_span_kind == TraceloopSpanKindValues.AGENT:
144-
print(f"Setting agent name: {entity_name}")
145147
set_agent_name(entity_name)
146148

147149
span_name = f"{entity_name}.{tlp_span_kind.value}"
@@ -160,6 +162,8 @@ def _setup_span(entity_name, tlp_span_kind, version):
160162

161163
span.set_attribute(SpanAttributes.TRACELOOP_SPAN_KIND, tlp_span_kind.value)
162164
span.set_attribute(SpanAttributes.TRACELOOP_ENTITY_NAME, entity_name)
165+
if tlp_span_kind == TraceloopSpanKindValues.TOOL:
166+
span.set_attribute(GEN_AI_TOOL_NAME, entity_name)
163167
if version:
164168
span.set_attribute(SpanAttributes.TRACELOOP_ENTITY_VERSION, version)
165169

0 commit comments

Comments
 (0)