Skip to content

Commit 03f8571

Browse files
authored
Merge pull request #3 from UiPath/fix/add_custom_log_handler
fix: add custom log handler
2 parents 61bf96c + 8c7ccdb commit 03f8571

File tree

5 files changed

+23
-29
lines changed

5 files changed

+23
-29
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[project]
22
name = "uipath-dev"
3-
version = "0.0.1"
3+
version = "0.0.2"
44
description = "UiPath Developer Console"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"
77
dependencies = [
8-
"uipath-runtime>=0.0.4",
8+
"uipath-runtime>=0.0.5, <0.1.0",
99
"textual>=6.5.0",
1010
"pyperclip>=1.11.0",
1111
]

src/uipath/dev/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from uipath.dev.models.messages import LogMessage, TraceMessage
3232

3333
from ._utils._exporter import RunContextExporter
34-
from ._utils._logger import patch_textual_stderr
34+
from ._utils._logger import RunContextLogHandler, patch_textual_stderr
3535

3636

3737
class UiPathDeveloperConsole(App[Any]):
@@ -203,10 +203,16 @@ async def _execute_runtime(self, run: ExecutionRun):
203203

204204
run.status = "running"
205205
run.start_time = datetime.now()
206-
206+
log_handler = RunContextLogHandler(
207+
run_id=run.id,
208+
callback=self._handle_log_message,
209+
)
207210
runtime = self.runtime_factory.new_runtime(entrypoint=run.entrypoint)
208211
execution_runtime = UiPathExecutionRuntime(
209-
delegate=runtime, trace_manager=self.trace_manager, execution_id=run.id
212+
delegate=runtime,
213+
trace_manager=self.trace_manager,
214+
log_handler=log_handler,
215+
execution_id=run.id,
210216
)
211217
result = await execution_runtime.execute(execution_input, execution_options)
212218

src/uipath/dev/_demo/mock_runtime.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ async def execute(
4646

4747
tracer = trace.get_tracer("uipath.dev.mock-runtime")
4848

49-
execution_id = getattr(self.context, "job_id", None) or "mock-execution"
50-
entrypoint = getattr(self.context, "entrypoint", None) or "mock-entrypoint"
49+
entrypoint = "mock-entrypoint"
5150
message = str(payload.get("message", ""))
5251
message_length = len(message)
5352

@@ -56,7 +55,6 @@ async def execute(
5655
attributes={
5756
"uipath.runtime.name": "MockRuntime",
5857
"uipath.runtime.type": "agent",
59-
"uipath.execution.id": execution_id,
6058
"uipath.runtime.entrypoint": entrypoint,
6159
"uipath.input.message.length": message_length,
6260
"uipath.input.has_message": "message" in payload,
@@ -65,19 +63,17 @@ async def execute(
6563
logger.info(
6664
"MockRuntime: starting execution",
6765
extra={
68-
"uipath.execution.id": execution_id,
6966
"uipath.runtime.entrypoint": entrypoint,
7067
},
7168
)
72-
print(f"[MockRuntime] Starting execution (execution_id={execution_id})")
69+
print(f"[MockRuntime] Starting execution with payload={payload!r}")
7370

7471
# Stage 1: Initialization
7572
with tracer.start_as_current_span(
7673
"initialize.environment",
7774
attributes={
7875
"uipath.step.name": "initialize-environment",
7976
"uipath.step.kind": "init",
80-
"uipath.execution.id": execution_id,
8177
},
8278
):
8379
logger.info("MockRuntime: initializing environment")
@@ -90,7 +86,6 @@ async def execute(
9086
attributes={
9187
"uipath.step.name": "validate-input",
9288
"uipath.step.kind": "validation",
93-
"uipath.execution.id": execution_id,
9489
"uipath.input.has_message": "message" in payload,
9590
},
9691
) as validate_span:
@@ -110,7 +105,6 @@ async def execute(
110105
attributes={
111106
"uipath.step.name": "preprocess-data",
112107
"uipath.step.kind": "preprocess",
113-
"uipath.execution.id": execution_id,
114108
"uipath.input.size.bytes": len(str(payload).encode("utf-8")),
115109
},
116110
):
@@ -124,7 +118,6 @@ async def execute(
124118
attributes={
125119
"uipath.step.name": "compute-result",
126120
"uipath.step.kind": "compute",
127-
"uipath.execution.id": execution_id,
128121
},
129122
):
130123
logger.info("MockRuntime: compute phase started")
@@ -136,7 +129,6 @@ async def execute(
136129
attributes={
137130
"uipath.step.name": "compute-embeddings",
138131
"uipath.step.kind": "compute-subtask",
139-
"uipath.execution.id": execution_id,
140132
},
141133
):
142134
logger.info("MockRuntime: computing embeddings")
@@ -149,7 +141,6 @@ async def execute(
149141
attributes={
150142
"uipath.step.name": "query-knowledgebase",
151143
"uipath.step.kind": "io",
152-
"uipath.execution.id": execution_id,
153144
"uipath.kb.query.length": message_length,
154145
},
155146
):
@@ -163,7 +154,6 @@ async def execute(
163154
attributes={
164155
"uipath.step.name": "postprocess-results",
165156
"uipath.step.kind": "postprocess",
166-
"uipath.execution.id": execution_id,
167157
},
168158
):
169159
logger.info("MockRuntime: post-processing results")
@@ -175,7 +165,6 @@ async def execute(
175165
attributes={
176166
"uipath.step.name": "generate-output",
177167
"uipath.step.kind": "postprocess-subtask",
178-
"uipath.execution.id": execution_id,
179168
},
180169
):
181170
logger.info("MockRuntime: generating structured output")
@@ -188,7 +177,6 @@ async def execute(
188177
attributes={
189178
"uipath.step.name": "persist-artifacts",
190179
"uipath.step.kind": "io",
191-
"uipath.execution.id": execution_id,
192180
"uipath.persistence.enabled": False,
193181
},
194182
):
@@ -202,7 +190,6 @@ async def execute(
202190
attributes={
203191
"uipath.step.name": "cleanup-resources",
204192
"uipath.step.kind": "cleanup",
205-
"uipath.execution.id": execution_id,
206193
},
207194
):
208195
logger.info("MockRuntime: cleaning up resources")
@@ -212,7 +199,6 @@ async def execute(
212199
result_payload = {
213200
"result": f"Mock runtime processed: {payload.get('message', '<no message>')}",
214201
"metadata": {
215-
"execution_id": execution_id,
216202
"entrypoint": entrypoint,
217203
"message_length": message_length,
218204
},
@@ -228,7 +214,6 @@ async def execute(
228214
logger.info(
229215
"MockRuntime: execution completed successfully",
230216
extra={
231-
"uipath.execution.id": execution_id,
232217
"uipath.runtime.status": "success",
233218
},
234219
)

src/uipath/dev/_utils/_logger.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@
77
from datetime import datetime
88
from typing import Callable, Pattern
99

10+
from uipath.runtime.logging import UiPathRuntimeExecutionLogHandler
11+
1012
from uipath.dev.models.messages import LogMessage
1113

1214

13-
class RunContextLogHandler(logging.Handler):
15+
class RunContextLogHandler(UiPathRuntimeExecutionLogHandler):
1416
"""Custom log handler that sends logs to CLI UI."""
1517

1618
def __init__(
1719
self,
1820
run_id: str,
1921
callback: Callable[[LogMessage], None],
2022
):
21-
super().__init__()
23+
super().__init__(run_id)
2224
self.run_id = run_id
2325
self.callback = callback
26+
self.setFormatter(logging.Formatter("%(message)s"))
2427

2528
def emit(self, record: logging.LogRecord):
2629
"""Emit a log record to CLI UI."""

uv.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)