File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -175,8 +175,30 @@ async def run(
175175 if save_tracing_data :
176176 self .save_tracing_file (session_id )
177177
178+ self ._print_trace_id ()
179+
178180 return final_output
179181
182+ def _print_trace_id (self ):
183+ if not isinstance (self .agent , Agent ):
184+ logger .warning (
185+ ("The agent is not an instance of VeADK Agent, no trace id provided." )
186+ )
187+ return
188+
189+ if not self .agent .tracers :
190+ logger .warning (
191+ "No tracer is configured in the agent, no trace id provided."
192+ )
193+ return
194+
195+ try :
196+ trace_id = self .agent .tracers [0 ].get_trace_id () # type: ignore
197+ logger .info (f"Trace id: { trace_id } " )
198+ except Exception as e :
199+ logger .warning (f"Get tracer id failed as { e } " )
200+ return
201+
180202 def save_tracing_file (self , session_id : str ) -> str :
181203 if not isinstance (self .agent , Agent ):
182204 logger .warning (
Original file line number Diff line number Diff line change @@ -127,6 +127,16 @@ def _init_tracer_provider(self) -> None:
127127 self ._processors .append (processor )
128128 logger .debug (f"Init OpentelemetryTracer with { len (self .exporters )} exporters." )
129129
130+ def get_trace_id (self ) -> str :
131+ if not self ._inmemory_exporter :
132+ return ""
133+ try :
134+ trace_id = hex (int (self ._inmemory_exporter ._real_exporter .trace_id ))[2 :]
135+ except Exception :
136+ return ""
137+
138+ return trace_id
139+
130140 @override
131141 def dump (
132142 self ,
You can’t perform that action at this time.
0 commit comments