Skip to content

Commit ed2af0b

Browse files
committed
fix: Remove the judgment of the Agent type
1 parent c7ef73f commit ed2af0b

1 file changed

Lines changed: 20 additions & 27 deletions

File tree

veadk/tracing/telemetry/telemetry.py

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ def trace_send_data(): ...
5757
def set_common_attributes(
5858
invocation_context: InvocationContext, current_span: _Span, **kwargs
5959
) -> None:
60-
from veadk.agent import Agent
61-
6260
if current_span.context:
6361
current_span_id = current_span.context.trace_id
6462
else:
@@ -67,31 +65,26 @@ def set_common_attributes(
6765
)
6866
return
6967

70-
if isinstance(invocation_context.agent, Agent):
71-
try:
72-
spans = _INMEMORY_EXPORTER_INSTANCE.processor.spans # # type: ignore
73-
74-
spans_in_current_trace = [
75-
span
76-
for span in spans
77-
if span.context and span.context.trace_id == current_span_id
78-
]
79-
80-
common_attributes = ATTRIBUTES.get("common", {})
81-
for span in spans_in_current_trace:
82-
if span.name.startswith("invocation"):
83-
span.set_attribute("gen_ai.operation.name", "chain")
84-
elif span.name.startswith("agent_run"):
85-
span.set_attribute("gen_ai.operation.name", "agent")
86-
for attr_name, attr_extractor in common_attributes.items():
87-
value = attr_extractor(**kwargs)
88-
span.set_attribute(attr_name, value)
89-
except Exception as e:
90-
logger.error(f"Failed to set common attributes for spans: {e}")
91-
else:
92-
logger.warning(
93-
"Failed to set common attributes for spans as your agent is not VeADK Agent. Skip this."
94-
)
68+
try:
69+
spans = _INMEMORY_EXPORTER_INSTANCE.processor.spans # # type: ignore
70+
71+
spans_in_current_trace = [
72+
span
73+
for span in spans
74+
if span.context and span.context.trace_id == current_span_id
75+
]
76+
77+
common_attributes = ATTRIBUTES.get("common", {})
78+
for span in spans_in_current_trace:
79+
if span.name.startswith("invocation"):
80+
span.set_attribute("gen_ai.operation.name", "chain")
81+
elif span.name.startswith("agent_run"):
82+
span.set_attribute("gen_ai.operation.name", "agent")
83+
for attr_name, attr_extractor in common_attributes.items():
84+
value = attr_extractor(**kwargs)
85+
span.set_attribute(attr_name, value)
86+
except Exception as e:
87+
logger.error(f"Failed to set common attributes for spans: {e}")
9588

9689

9790
def trace_tool_call(

0 commit comments

Comments
 (0)