agentscope-runtime 0.1.5b2__py3-none-any.whl → 0.2.0b2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. agentscope_runtime/common/__init__.py +0 -0
  2. agentscope_runtime/common/collections/in_memory_mapping.py +27 -0
  3. agentscope_runtime/common/collections/redis_mapping.py +42 -0
  4. agentscope_runtime/common/container_clients/__init__.py +0 -0
  5. agentscope_runtime/common/container_clients/agentrun_client.py +1098 -0
  6. agentscope_runtime/common/container_clients/docker_client.py +250 -0
  7. agentscope_runtime/{sandbox/manager → common}/container_clients/kubernetes_client.py +6 -13
  8. agentscope_runtime/engine/__init__.py +12 -0
  9. agentscope_runtime/engine/agents/agentscope_agent.py +488 -0
  10. agentscope_runtime/engine/agents/agno_agent.py +26 -27
  11. agentscope_runtime/engine/agents/autogen_agent.py +13 -8
  12. agentscope_runtime/engine/agents/utils.py +53 -0
  13. agentscope_runtime/engine/app/__init__.py +6 -0
  14. agentscope_runtime/engine/app/agent_app.py +239 -0
  15. agentscope_runtime/engine/app/base_app.py +181 -0
  16. agentscope_runtime/engine/app/celery_mixin.py +92 -0
  17. agentscope_runtime/engine/deployers/base.py +1 -0
  18. agentscope_runtime/engine/deployers/cli_fc_deploy.py +39 -20
  19. agentscope_runtime/engine/deployers/kubernetes_deployer.py +12 -5
  20. agentscope_runtime/engine/deployers/local_deployer.py +61 -3
  21. agentscope_runtime/engine/deployers/modelstudio_deployer.py +10 -11
  22. agentscope_runtime/engine/deployers/utils/docker_image_utils/runner_image_factory.py +9 -0
  23. agentscope_runtime/engine/deployers/utils/package_project_utils.py +234 -3
  24. agentscope_runtime/engine/deployers/utils/service_utils/fastapi_factory.py +567 -7
  25. agentscope_runtime/engine/deployers/utils/service_utils/standalone_main.py.j2 +211 -0
  26. agentscope_runtime/engine/deployers/utils/wheel_packager.py +1 -1
  27. agentscope_runtime/engine/helpers/helper.py +60 -41
  28. agentscope_runtime/engine/runner.py +35 -24
  29. agentscope_runtime/engine/schemas/agent_schemas.py +42 -0
  30. agentscope_runtime/engine/schemas/modelstudio_llm.py +14 -14
  31. agentscope_runtime/engine/services/sandbox_service.py +62 -70
  32. agentscope_runtime/engine/services/tablestore_memory_service.py +307 -0
  33. agentscope_runtime/engine/services/tablestore_rag_service.py +143 -0
  34. agentscope_runtime/engine/services/tablestore_session_history_service.py +293 -0
  35. agentscope_runtime/engine/services/utils/__init__.py +0 -0
  36. agentscope_runtime/engine/services/utils/tablestore_service_utils.py +352 -0
  37. agentscope_runtime/engine/tracing/__init__.py +9 -3
  38. agentscope_runtime/engine/tracing/asyncio_util.py +24 -0
  39. agentscope_runtime/engine/tracing/base.py +66 -34
  40. agentscope_runtime/engine/tracing/local_logging_handler.py +45 -31
  41. agentscope_runtime/engine/tracing/message_util.py +528 -0
  42. agentscope_runtime/engine/tracing/tracing_metric.py +20 -8
  43. agentscope_runtime/engine/tracing/tracing_util.py +130 -0
  44. agentscope_runtime/engine/tracing/wrapper.py +794 -169
  45. agentscope_runtime/sandbox/__init__.py +2 -0
  46. agentscope_runtime/sandbox/box/base/__init__.py +4 -0
  47. agentscope_runtime/sandbox/box/base/base_sandbox.py +6 -4
  48. agentscope_runtime/sandbox/box/browser/__init__.py +4 -0
  49. agentscope_runtime/sandbox/box/browser/browser_sandbox.py +10 -14
  50. agentscope_runtime/sandbox/box/dummy/__init__.py +4 -0
  51. agentscope_runtime/sandbox/box/dummy/dummy_sandbox.py +2 -1
  52. agentscope_runtime/sandbox/box/filesystem/__init__.py +4 -0
  53. agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +10 -7
  54. agentscope_runtime/sandbox/box/gui/__init__.py +4 -0
  55. agentscope_runtime/sandbox/box/gui/box/__init__.py +0 -0
  56. agentscope_runtime/sandbox/box/gui/gui_sandbox.py +81 -0
  57. agentscope_runtime/sandbox/box/sandbox.py +5 -2
  58. agentscope_runtime/sandbox/box/shared/routers/generic.py +20 -1
  59. agentscope_runtime/sandbox/box/training_box/__init__.py +4 -0
  60. agentscope_runtime/sandbox/box/training_box/training_box.py +7 -54
  61. agentscope_runtime/sandbox/build.py +143 -58
  62. agentscope_runtime/sandbox/client/http_client.py +87 -59
  63. agentscope_runtime/sandbox/client/training_client.py +0 -1
  64. agentscope_runtime/sandbox/constant.py +27 -1
  65. agentscope_runtime/sandbox/custom/custom_sandbox.py +7 -6
  66. agentscope_runtime/sandbox/custom/example.py +4 -3
  67. agentscope_runtime/sandbox/enums.py +1 -1
  68. agentscope_runtime/sandbox/manager/sandbox_manager.py +212 -106
  69. agentscope_runtime/sandbox/manager/server/app.py +82 -14
  70. agentscope_runtime/sandbox/manager/server/config.py +50 -3
  71. agentscope_runtime/sandbox/model/container.py +12 -23
  72. agentscope_runtime/sandbox/model/manager_config.py +93 -5
  73. agentscope_runtime/sandbox/registry.py +1 -1
  74. agentscope_runtime/sandbox/tools/gui/__init__.py +7 -0
  75. agentscope_runtime/sandbox/tools/gui/tool.py +77 -0
  76. agentscope_runtime/sandbox/tools/mcp_tool.py +6 -2
  77. agentscope_runtime/sandbox/tools/tool.py +4 -0
  78. agentscope_runtime/sandbox/utils.py +124 -0
  79. agentscope_runtime/version.py +1 -1
  80. {agentscope_runtime-0.1.5b2.dist-info → agentscope_runtime-0.2.0b2.dist-info}/METADATA +214 -102
  81. {agentscope_runtime-0.1.5b2.dist-info → agentscope_runtime-0.2.0b2.dist-info}/RECORD +94 -78
  82. agentscope_runtime/engine/agents/agentscope_agent/__init__.py +0 -6
  83. agentscope_runtime/engine/agents/agentscope_agent/agent.py +0 -401
  84. agentscope_runtime/engine/agents/agentscope_agent/hooks.py +0 -169
  85. agentscope_runtime/engine/agents/llm_agent.py +0 -51
  86. agentscope_runtime/engine/llms/__init__.py +0 -3
  87. agentscope_runtime/engine/llms/base_llm.py +0 -60
  88. agentscope_runtime/engine/llms/qwen_llm.py +0 -47
  89. agentscope_runtime/sandbox/manager/collections/in_memory_mapping.py +0 -22
  90. agentscope_runtime/sandbox/manager/collections/redis_mapping.py +0 -26
  91. agentscope_runtime/sandbox/manager/container_clients/__init__.py +0 -10
  92. agentscope_runtime/sandbox/manager/container_clients/docker_client.py +0 -422
  93. /agentscope_runtime/{sandbox/manager → common}/collections/__init__.py +0 -0
  94. /agentscope_runtime/{sandbox/manager → common}/collections/base_mapping.py +0 -0
  95. /agentscope_runtime/{sandbox/manager → common}/collections/base_queue.py +0 -0
  96. /agentscope_runtime/{sandbox/manager → common}/collections/base_set.py +0 -0
  97. /agentscope_runtime/{sandbox/manager → common}/collections/in_memory_queue.py +0 -0
  98. /agentscope_runtime/{sandbox/manager → common}/collections/in_memory_set.py +0 -0
  99. /agentscope_runtime/{sandbox/manager → common}/collections/redis_queue.py +0 -0
  100. /agentscope_runtime/{sandbox/manager → common}/collections/redis_set.py +0 -0
  101. /agentscope_runtime/{sandbox/manager → common}/container_clients/base_client.py +0 -0
  102. {agentscope_runtime-0.1.5b2.dist-info → agentscope_runtime-0.2.0b2.dist-info}/WHEEL +0 -0
  103. {agentscope_runtime-0.1.5b2.dist-info → agentscope_runtime-0.2.0b2.dist-info}/entry_points.txt +0 -0
  104. {agentscope_runtime-0.1.5b2.dist-info → agentscope_runtime-0.2.0b2.dist-info}/licenses/LICENSE +0 -0
  105. {agentscope_runtime-0.1.5b2.dist-info → agentscope_runtime-0.2.0b2.dist-info}/top_level.txt +0 -0
@@ -1,12 +1,12 @@
1
1
  # -*- coding: utf-8 -*-
2
- # pylint: disable=protected-access
3
2
  import time
4
3
  import traceback
5
4
  from abc import ABC, abstractmethod
6
5
  from contextlib import contextmanager
7
6
  from typing import Any, Dict, List
8
7
 
9
- from .tracing_metric import TraceType
8
+ from opentelemetry.propagate import inject, extract
9
+ from opentelemetry.context.context import Context
10
10
 
11
11
 
12
12
  # Handler Interface
@@ -16,22 +16,23 @@ class TracerHandler(ABC):
16
16
  @abstractmethod
17
17
  def on_start(
18
18
  self,
19
- event_type: TraceType,
19
+ event_name: str,
20
20
  payload: Dict[str, Any],
21
21
  **kwargs: Any,
22
22
  ) -> None:
23
23
  """Handle the start of a trace event.
24
24
 
25
25
  Args:
26
- event_type (TraceType): The type of event being traced.
26
+ event_name (str): The name of event being traced.
27
27
  payload (Dict[str, Any]): The payload data for the event.
28
28
  **kwargs (Any): Additional keyword arguments.
29
29
  """
30
+ raise NotImplementedError("Subclasses must implement on_start method")
30
31
 
31
32
  @abstractmethod
32
33
  def on_end(
33
34
  self,
34
- event_type: TraceType,
35
+ event_name: str,
35
36
  start_payload: Dict[str, Any],
36
37
  end_payload: Dict[str, Any],
37
38
  start_time: float,
@@ -40,12 +41,13 @@ class TracerHandler(ABC):
40
41
  """Handle the end of a trace event.
41
42
 
42
43
  Args:
43
- event_type (TraceType): The type of event being traced.
44
+ event_name (str): The name of event being traced.
44
45
  start_payload (Dict[str, Any]): The payload data from event start.
45
46
  end_payload (Dict[str, Any]): The payload data from event end.
46
47
  start_time (float): The timestamp when the event started.
47
48
  **kwargs (Any): Additional keyword arguments.
48
49
  """
50
+ raise NotImplementedError("Subclasses must implement on_end method")
49
51
 
50
52
  @abstractmethod
51
53
  def on_log(self, message: str, **kwargs: Any) -> None:
@@ -55,11 +57,12 @@ class TracerHandler(ABC):
55
57
  message (str): The log message.
56
58
  **kwargs (Any): Additional keyword arguments.
57
59
  """
60
+ raise NotImplementedError("Subclasses must implement on_log method")
58
61
 
59
62
  @abstractmethod
60
63
  def on_error(
61
64
  self,
62
- event_type: TraceType,
65
+ event_name: str,
63
66
  start_payload: Dict[str, Any],
64
67
  error: Exception,
65
68
  start_time: float,
@@ -69,15 +72,17 @@ class TracerHandler(ABC):
69
72
  """Handle an error during tracing.
70
73
 
71
74
  Args:
72
- event_type (TraceType): The type of event being traced.
75
+ event_name (str): The type of event being traced.
73
76
  start_payload (Dict[str, Any]): The payload data from event start.
74
77
  error (Exception): The exception that occurred.
75
78
  start_time (float): The timestamp when the event started.
76
79
  traceback_info (str): The traceback information.
77
80
  **kwargs (Any): Additional keyword arguments.
78
81
  """
82
+ raise NotImplementedError("Subclasses must implement on_error method")
79
83
 
80
84
 
85
+ # 新增基础的LogHandler类
81
86
  class BaseLogHandler(TracerHandler):
82
87
  """Basic log handler implementation using Python's logging module."""
83
88
 
@@ -87,22 +92,22 @@ class BaseLogHandler(TracerHandler):
87
92
 
88
93
  def on_start(
89
94
  self,
90
- event_type: TraceType,
95
+ event_name: str,
91
96
  payload: Dict[str, Any],
92
97
  **kwargs: Any,
93
98
  ) -> None:
94
99
  """Log the start of a trace event.
95
100
 
96
101
  Args:
97
- event_type (TraceType): The type of event being traced.
102
+ event_name (str): The name of event being traced.
98
103
  payload (Dict[str, Any]): The payload data for the event.
99
104
  **kwargs (Any): Additional keyword arguments.
100
105
  """
101
- self.logger.info(f"Event {event_type} started with payload: {payload}")
106
+ self.logger.info(f"Event {event_name} started with payload: {payload}")
102
107
 
103
108
  def on_end(
104
109
  self,
105
- event_type: TraceType,
110
+ event_name: str,
106
111
  start_payload: Dict[str, Any],
107
112
  end_payload: Dict[str, Any],
108
113
  start_time: float,
@@ -111,14 +116,14 @@ class BaseLogHandler(TracerHandler):
111
116
  """Log the end of a trace event.
112
117
 
113
118
  Args:
114
- event_type (TraceType): The type of event being traced.
119
+ event_name (str): The name of event being traced.
115
120
  start_payload (Dict[str, Any]): The payload data from event start.
116
121
  end_payload (Dict[str, Any]): The payload data from event end.
117
122
  start_time (float): The timestamp when the event started.
118
123
  **kwargs (Any): Additional keyword arguments.
119
124
  """
120
125
  self.logger.info(
121
- f"Event {event_type} ended with start payload: {start_payload}, "
126
+ f"Event {event_name} ended with start payload: {start_payload}, "
122
127
  f"end payload: {end_payload}, duration: "
123
128
  f"{time.time() - start_time} seconds, kwargs: {kwargs}",
124
129
  )
@@ -130,12 +135,11 @@ class BaseLogHandler(TracerHandler):
130
135
  message (str): The log message.
131
136
  **kwargs (Any): Additional keyword arguments.
132
137
  """
133
- if message:
134
- self.logger.info(f"Log: {message}")
138
+ self.logger.info(f"Log: {message}")
135
139
 
136
140
  def on_error(
137
141
  self,
138
- event_type: TraceType,
142
+ event_name: str,
139
143
  start_payload: Dict[str, Any],
140
144
  error: Exception,
141
145
  start_time: float,
@@ -145,7 +149,7 @@ class BaseLogHandler(TracerHandler):
145
149
  """Log an error during tracing.
146
150
 
147
151
  Args:
148
- event_type (TraceType): The type of event being traced.
152
+ event_name (str): The name of event being traced.
149
153
  start_payload (Dict[str, Any]): The payload data from event start.
150
154
  error (Exception): The exception that occurred.
151
155
  start_time (float): The timestamp when the event started.
@@ -153,7 +157,7 @@ class BaseLogHandler(TracerHandler):
153
157
  **kwargs (Any): Additional keyword arguments.
154
158
  """
155
159
  self.logger.error(
156
- f"Error in event {event_type} with payload: {start_payload}, "
160
+ f"Error in event {event_name} with payload: {start_payload}, "
157
161
  f"error: {error}, "
158
162
  f"traceback: {traceback_info}, duration: "
159
163
  f"{time.time() - start_time} seconds, kwargs: {kwargs}",
@@ -184,14 +188,16 @@ class Tracer:
184
188
  @contextmanager
185
189
  def event(
186
190
  self,
187
- event_type: TraceType,
191
+ span: Any,
192
+ event_name: str,
188
193
  payload: Dict[str, Any],
189
194
  **kwargs: Any,
190
195
  ) -> Any:
191
196
  """Create a context manager for tracing an event.
192
197
 
193
198
  Args:
194
- event_type (TraceType): The type of event being traced.
199
+ span(Any): span of event
200
+ event_name (str): The name of event being traced.
195
201
  payload (Dict[str, Any]): The payload data for the event.
196
202
  **kwargs (Any): Additional keyword arguments.
197
203
 
@@ -201,28 +207,35 @@ class Tracer:
201
207
  start_time = time.time()
202
208
 
203
209
  for handle in self.handlers:
204
- handle.on_start(event_type, payload, **kwargs)
210
+ handle.on_start(
211
+ event_name,
212
+ payload,
213
+ **kwargs,
214
+ )
205
215
 
206
216
  event_context = EventContext(
217
+ span,
207
218
  self.handlers,
208
- event_type,
219
+ event_name,
209
220
  start_time,
210
221
  payload,
211
222
  )
223
+
212
224
  try:
213
225
  yield event_context
214
226
  except Exception as e:
215
227
  traceback_info = traceback.format_exc()
216
228
  for handle in self.handlers:
217
229
  handle.on_error(
218
- event_type,
230
+ event_name,
219
231
  payload,
220
232
  e,
221
233
  start_time,
222
234
  traceback_info=traceback_info,
223
235
  )
224
236
  raise
225
- event_context._end(payload)
237
+
238
+ event_context.finalize(payload)
226
239
 
227
240
  def log(self, message: str, **kwargs: Any) -> None:
228
241
  """Log a message using all registered handlers.
@@ -240,8 +253,9 @@ class EventContext:
240
253
 
241
254
  def __init__(
242
255
  self,
256
+ span: Any,
243
257
  handlers: List[TracerHandler],
244
- event_type: TraceType,
258
+ event_name: str,
245
259
  start_time: float,
246
260
  start_payload: Dict[str, Any],
247
261
  ) -> None:
@@ -250,12 +264,13 @@ class EventContext:
250
264
  Args:
251
265
  handlers (List[TracerHandler]): List of handlers to process
252
266
  trace events.
253
- event_type (TraceType): The type of event being traced.
267
+ event_name (str): The name of event being traced.
254
268
  start_time (float): The timestamp when the event started.
255
269
  start_payload (Dict[str, Any]): The payload data from event start.
256
270
  """
271
+ self.span = span
257
272
  self.handlers = handlers
258
- self.event_type = event_type
273
+ self.event_name = event_name
259
274
  self.start_time = start_time
260
275
  self.start_payload = start_payload
261
276
  self.end_payload = {}
@@ -278,12 +293,21 @@ class EventContext:
278
293
  message (str): The log message.
279
294
  **kwargs (Any): Additional keyword arguments.
280
295
  """
281
- kwargs["event_type"] = self.event_type
296
+ kwargs["event_name"] = self.event_name
282
297
  kwargs["start_time"] = self.start_time
283
298
  kwargs["start_payload"] = self.start_payload
284
299
  for handle in self.handlers:
285
300
  handle.on_log(message, **kwargs)
286
301
 
302
+ def finalize(self, start_payload: Dict[str, Any] = None) -> None:
303
+ """Public method to finalize the event.
304
+
305
+ Args:
306
+ start_payload (Dict[str, Any], optional): The payload data from
307
+ event start.
308
+ """
309
+ self._end(start_payload)
310
+
287
311
  def _end(self, start_payload: Dict[str, Any] = None) -> None:
288
312
  """Finalize the event by calling on_end for all handlers.
289
313
 
@@ -293,17 +317,25 @@ class EventContext:
293
317
  """
294
318
  for handle in self.handlers:
295
319
  handle.on_end(
296
- self.event_type,
320
+ self.event_name,
297
321
  start_payload,
298
322
  self.end_payload,
299
323
  self.start_time,
300
324
  **self.kwargs,
301
325
  )
302
326
 
303
- def set_trace_header(self, trace_header: Dict[str, Any]) -> None:
304
- """Set trace header for compatible handlers.
327
+ def set_attribute(self, key: str, value: Any) -> None:
328
+ """Set attribute for the current span.
305
329
 
306
330
  Args:
307
- trace_header (Dict[str, Any]): The trace header information.
331
+ key (str): key of attribute
332
+ value(str): value of attribute
308
333
  """
309
- # TODO: Implement this
334
+
335
+ self.span.set_attribute(key, value)
336
+
337
+ def get_trace_context(self) -> Context:
338
+ carrier = {}
339
+ inject(carrier)
340
+ context = extract(carrier)
341
+ return context
@@ -9,7 +9,8 @@ from typing import Any, Dict, Optional
9
9
 
10
10
  from pydantic import BaseModel
11
11
 
12
- from .base import TracerHandler, TraceType
12
+ from . import TracingUtil
13
+ from .base import TracerHandler
13
14
 
14
15
  DEFAULT_LOG_NAME = "agentscope-runtime"
15
16
 
@@ -64,7 +65,11 @@ class JsonFormatter(logging.Formatter):
64
65
  "code": getattr(record, "code", None),
65
66
  "message": record.getMessage(),
66
67
  "task_id": getattr(record, "task_id", None),
67
- "request_id": getattr(record, "request_id", None),
68
+ "request_id": getattr(
69
+ record,
70
+ "request_id",
71
+ TracingUtil.get_request_id(),
72
+ ),
68
73
  "context": getattr(record, "context", None),
69
74
  "interval": getattr(record, "interval", None),
70
75
  "ds_service_id": DS_SVC_ID,
@@ -88,7 +93,6 @@ class LocalLogHandler(TracerHandler):
88
93
  max_bytes: int = 1024 * 1024 * 1024,
89
94
  backup_count: int = 7,
90
95
  enable_console: bool = False,
91
- propagate: bool = False,
92
96
  **kwargs: Any,
93
97
  ) -> None:
94
98
  """Initialize the llm chat log handler.
@@ -103,17 +107,12 @@ class LocalLogHandler(TracerHandler):
103
107
  backup_count (int): Number of log files to keep. Defaults to 7.
104
108
  enable_console (bool): Whether to enable console logging.
105
109
  Defaults to False.
106
- propagate (bool): Whether to propagate log messages to parent
107
- loggers.
108
- Defaults to False.
109
- **kwargs (Any): Additional keyword arguments.
110
+ **kwargs (Any): Additional keyword arguments (unused but kept for
111
+ compatibility).
110
112
  """
113
+ # Store kwargs for potential future use
114
+ self._extra_kwargs = kwargs
111
115
  self.logger = logging.getLogger(DEFAULT_LOG_NAME)
112
- # Set propagate attribute to control log message propagation
113
- # Note: Python logging propagate defaults to True, we set it to
114
- # False by default
115
- self.logger.propagate = propagate
116
-
117
116
  if enable_console:
118
117
  handler = logging.StreamHandler()
119
118
  handler.setFormatter(JsonFormatter())
@@ -127,7 +126,6 @@ class LocalLogHandler(TracerHandler):
127
126
  )
128
127
 
129
128
  self.logger.setLevel(log_level)
130
- self.kwargs = kwargs
131
129
 
132
130
  def _set_file_handle(
133
131
  self,
@@ -188,6 +186,9 @@ class LocalLogHandler(TracerHandler):
188
186
  original (Dict[str, Any]): The original dictionary to update.
189
187
  update (Dict[str, Any]): The dictionary containing updates.
190
188
  """
189
+ if not isinstance(original, dict):
190
+ return
191
+
191
192
  for key, value in update.items():
192
193
  if (
193
194
  isinstance(value, dict)
@@ -200,19 +201,19 @@ class LocalLogHandler(TracerHandler):
200
201
 
201
202
  def on_start(
202
203
  self,
203
- event_type: TraceType,
204
+ event_name: str,
204
205
  payload: Dict[str, Any],
205
206
  **kwargs: Any,
206
207
  ) -> None:
207
208
  """Handle the start of a trace event.
208
209
 
209
210
  Args:
210
- event_type (TraceType): The type of event being traced.
211
+ event_name (str): The name of event being traced.
211
212
  payload (Dict[str, Any]): The payload data for the event.
212
213
  **kwargs (Any): Additional keyword arguments.
213
214
  """
214
- step = f"{event_type}_start"
215
- request_id = payload.get("request_id", "")
215
+ step = f"{event_name}_start"
216
+ request_id = TracingUtil.get_request_id()
216
217
  context = payload.get("context", payload)
217
218
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
218
219
  interval = {"type": step, "cost": 0}
@@ -236,27 +237,32 @@ class LocalLogHandler(TracerHandler):
236
237
 
237
238
  def on_end(
238
239
  self,
239
- event_type: TraceType,
240
+ event_name: str,
240
241
  start_payload: Dict[str, Any],
241
- end_payload: Dict[str, Any],
242
+ end_payload: Any,
242
243
  start_time: float,
243
244
  **kwargs: Any,
244
245
  ) -> None:
245
246
  """Handle the end of a trace event.
246
247
 
247
248
  Args:
248
- event_type (TraceType): The type of event being traced.
249
+ event_name (str): The name of event being traced.
249
250
  start_payload (Dict[str, Any]): The payload data from event start.
250
- end_payload (Dict[str, Any]): The payload data from event end.
251
+ end_payload (Any): The payload data from event end.
251
252
  start_time (float): The timestamp when the event started.
252
253
  **kwargs (Any): Additional keyword arguments.
253
254
  """
254
255
 
255
- LocalLogHandler._deep_update(end_payload, start_payload)
256
+ request_id = TracingUtil.get_request_id()
257
+
258
+ if isinstance(end_payload, dict):
259
+ context = end_payload
260
+ else:
261
+ context = {}
262
+ if end_payload is not None:
263
+ context["output"] = end_payload
256
264
 
257
- step = f"{event_type}_end"
258
- request_id = end_payload.get("request_id", "")
259
- context = end_payload.get("context", end_payload)
265
+ step = f"{event_name}_end"
260
266
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
261
267
  duration = time.time() - start_time
262
268
  interval = {"type": step, "cost": f"{duration:.3f}"}
@@ -287,14 +293,14 @@ class LocalLogHandler(TracerHandler):
287
293
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
288
294
  if "step_suffix" in kwargs:
289
295
  step_suffix = kwargs["step_suffix"]
290
- event_type = kwargs["event_type"]
296
+ event_name = kwargs["event_name"]
291
297
  payload = kwargs["payload"]
292
298
  start_time = kwargs["start_time"]
293
299
  start_payload = kwargs["start_payload"]
294
300
 
295
301
  LocalLogHandler._deep_update(payload, start_payload)
296
302
 
297
- step = f"{event_type}_{step_suffix}"
303
+ step = f"{event_name}_{step_suffix}"
298
304
  duration = time.time() - start_time
299
305
  interval = {"type": step, "cost": f"{duration:.3f}"}
300
306
  else:
@@ -302,12 +308,20 @@ class LocalLogHandler(TracerHandler):
302
308
  interval = {"type": step, "cost": "0"}
303
309
  payload = {}
304
310
 
311
+ request_id = TracingUtil.get_request_id()
312
+
313
+ if isinstance(payload, dict):
314
+ context = payload
315
+ else:
316
+ context = {"payload": str(payload)}
317
+
305
318
  runtime_context = LogContext(
306
319
  time=timestamp,
307
320
  step=step,
308
321
  interval=interval,
309
- context=payload,
322
+ context=context,
310
323
  message=message,
324
+ request_id=request_id,
311
325
  )
312
326
  self.logger.info(
313
327
  runtime_context.message,
@@ -316,7 +330,7 @@ class LocalLogHandler(TracerHandler):
316
330
 
317
331
  def on_error(
318
332
  self,
319
- event_type: TraceType,
333
+ event_name: str,
320
334
  start_payload: Dict[str, Any],
321
335
  error: Exception,
322
336
  start_time: float,
@@ -326,14 +340,14 @@ class LocalLogHandler(TracerHandler):
326
340
  """Handle an error during tracing.
327
341
 
328
342
  Args:
329
- event_type (TraceType): The type of event being traced.
343
+ event_name (str): The name of event being traced.
330
344
  start_payload (Dict[str, Any]): The payload data from event start.
331
345
  error (Exception): The exception that occurred.
332
346
  start_time (float): The timestamp when the event started.
333
347
  traceback_info (str): The traceback information.
334
348
  **kwargs (Any): Additional keyword arguments.
335
349
  """
336
- step = f"{event_type}_error"
350
+ step = f"{event_name}_error"
337
351
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
338
352
  duration = time.time() - start_time
339
353
  interval = {"type": step, "cost": f"{duration:.3f}"}