88from dataclasses import asdict , is_dataclass
99from typing import Any , Dict , Optional , Type , TypeVar , cast , get_type_hints
1010
11- from opentelemetry import trace
12- from opentelemetry .sdk .trace import TracerProvider
13- from opentelemetry .sdk .trace .export import BatchSpanProcessor
1411from pydantic import BaseModel
1512
16- from uipath .tracing import LlmOpsHttpExporter
17-
1813from ._contracts import (
1914 UiPathBaseRuntime ,
2015 UiPathErrorCategory ,
@@ -42,19 +37,6 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
4237 """
4338 await self .validate ()
4439
45- shutdown_provider = False
46- trace_provider : Optional [TracerProvider ] = None
47- span_processor : Optional [BatchSpanProcessor ] = None
48-
49- if self .context .trace_context .enabled :
50- trace_provider = trace .get_tracer_provider ()
51- if not trace_provider :
52- trace_provider = TracerProvider ()
53- trace .set_tracer_provider (trace_provider )
54- shutdown_provider = True
55- span_processor = BatchSpanProcessor (LlmOpsHttpExporter ())
56- trace_provider .add_span_processor (span_processor )
57-
5840 try :
5941 if self .context .entrypoint is None :
6042 return None
@@ -83,13 +65,6 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
8365 UiPathErrorCategory .SYSTEM ,
8466 ) from e
8567
86- finally :
87- if self .context .trace_context .enabled :
88- await span_processor .force_flush ()
89- # Only shutdown if we created the provider
90- if shutdown_provider :
91- await trace_provider .shutdown ()
92-
9368 async def validate (self ) -> None :
9469 """Validate runtime inputs."""
9570 if not self .context .entrypoint :
@@ -127,12 +102,6 @@ async def cleanup(self) -> None:
127102
128103 async def _execute_python_script (self , script_path : str , input_data : Any ) -> Any :
129104 """Execute the Python script with the given input."""
130- # parent_span = trace.get_current_span()
131- # ctx = trace.set_span_in_context(parent_span)
132-
133- # print(f"Before module execution - Current span: {parent_span}")
134- # print(f"Current span attributes: {getattr(parent_span, 'attributes', {})}")
135-
136105 spec = importlib .util .spec_from_file_location ("dynamic_module" , script_path )
137106 if not spec or not spec .loader :
138107 raise UiPathRuntimeError (
@@ -144,16 +113,9 @@ async def _execute_python_script(self, script_path: str, input_data: Any) -> Any
144113
145114 module = importlib .util .module_from_spec (spec )
146115
147- # Attach the context BEFORE any module operations
148- # token = context_api.attach(ctx)
149-
150116 try :
151- # print("Executing module with context attached")
152117 spec .loader .exec_module (module )
153118
154- # active_span = trace.get_current_span()
155- # print(f"After module execution - Active span: {active_span}")
156-
157119 # Execute the function while context is still attached
158120 for func_name in ["main" , "run" , "execute" ]:
159121 if hasattr (module , func_name ):
@@ -209,26 +171,26 @@ async def _execute_python_script(self, script_path: str, input_data: Any) -> Any
209171 UiPathErrorCategory .USER ,
210172 ) from e
211173
212- # Case 3: Dict parameter
213- else :
214- try :
215- result = (
216- await main_func (input_data )
217- if is_async
218- else main_func (input_data )
219- )
220- return (
221- self ._convert_from_class (result )
222- if result is not None
223- else {}
224- )
225- except Exception as e :
226- raise UiPathRuntimeError (
227- "FUNCTION_EXECUTION_ERROR" ,
228- f"Error executing { func_name } function with dictionary input" ,
229- f"Error: { str (e )} " ,
230- UiPathErrorCategory .USER ,
231- ) from e
174+ # Case 3: Dict parameter
175+ else :
176+ try :
177+ result = (
178+ await main_func (input_data )
179+ if is_async
180+ else main_func (input_data )
181+ )
182+ return (
183+ self ._convert_from_class (result )
184+ if result is not None
185+ else {}
186+ )
187+ except Exception as e :
188+ raise UiPathRuntimeError (
189+ "FUNCTION_EXECUTION_ERROR" ,
190+ f"Error executing { func_name } function with dictionary input" ,
191+ f"Error: { str (e )} " ,
192+ UiPathErrorCategory .USER ,
193+ ) from e
232194
233195 # If we get here, no main function was found
234196 raise UiPathRuntimeError (
@@ -249,10 +211,6 @@ async def _execute_python_script(self, script_path: str, input_data: Any) -> Any
249211 UiPathErrorCategory .USER ,
250212 ) from e
251213
252- # finally:
253- # Only detach the context at the very end, after all operations
254- # context_api.detach(token)
255-
256214 def _convert_to_class (self , data : Dict [str , Any ], cls : Type [T ]) -> T :
257215 """Convert a dictionary to either a dataclass, Pydantic model, or regular class instance."""
258216 # Handle Pydantic models
0 commit comments