2828 LLMAttributesParams ,
2929 ToolAttributesParams ,
3030)
31+ from veadk .tracing .telemetry .exporters .inmemory_exporter import (
32+ _INMEMORY_EXPORTER_INSTANCE ,
33+ )
3134from veadk .utils .logger import get_logger
3235
3336logger = get_logger (__name__ )
@@ -54,8 +57,6 @@ def trace_send_data(): ...
5457def set_common_attributes (
5558 invocation_context : InvocationContext , current_span : _Span , ** kwargs
5659) -> None :
57- from veadk .agent import Agent
58-
5960 if current_span .context :
6061 current_span_id = current_span .context .trace_id
6162 else :
@@ -64,34 +65,26 @@ def set_common_attributes(
6465 )
6566 return
6667
67- if isinstance (invocation_context .agent , Agent ) and invocation_context .agent .tracers :
68- try :
69- from veadk .tracing .telemetry .opentelemetry_tracer import OpentelemetryTracer
70-
71- tracer : OpentelemetryTracer = invocation_context .agent .tracers [0 ] # type: ignore
72- spans = tracer ._inmemory_exporter .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
9790def trace_tool_call (
0 commit comments