sycommon-python-lib 0.1.25__py3-none-any.whl → 0.1.27__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.

Potentially problematic release.


This version of sycommon-python-lib might be problematic. Click here for more details.

@@ -9,13 +9,13 @@ from decimal import Decimal
9
9
  class SQLTraceLogger:
10
10
  @staticmethod
11
11
  def setup_sql_logging(engine: Engine):
12
- """为 SQLAlchemy 引擎注册事件监听器,绑定 trace_id 到 SQL 日志"""
12
+ """为 SQLAlchemy 引擎注册事件监听器"""
13
13
  def serialize_params(params):
14
14
  """处理特殊类型参数的序列化"""
15
15
  if isinstance(params, (list, tuple)):
16
- return [SQLTraceLogger.serialize_params(p) for p in params]
16
+ return [serialize_params(p) for p in params]
17
17
  elif isinstance(params, dict):
18
- return {k: SQLTraceLogger.serialize_params(v) for k, v in params.items()}
18
+ return {k: serialize_params(v) for k, v in params.items()}
19
19
  elif isinstance(params, datetime):
20
20
  return params.isoformat()
21
21
  elif isinstance(params, Decimal):
@@ -29,12 +29,10 @@ class SQLTraceLogger:
29
29
  conn, cursor, statement, parameters, context, executemany
30
30
  ):
31
31
  try:
32
- # 从连接的 execution_options 中获取开始时间
33
32
  start_time = conn._execution_options.get(
34
33
  "_start_time", time.time())
35
34
  execution_time = (time.time() - start_time) * 1000
36
35
 
37
- # 构建 SQL 日志信息
38
36
  sql_log = {
39
37
  "type": "SQL",
40
38
  "statement": statement,
@@ -42,18 +40,16 @@ class SQLTraceLogger:
42
40
  "execution_time_ms": round(execution_time, 2),
43
41
  }
44
42
 
45
- SYLogger.info(f"SQL 执行: {sql_log}")
43
+ SYLogger.info(f"SQL执行: {sql_log}")
46
44
  except Exception as e:
47
- SYLogger.error(f"SQL 日志处理失败: {str(e)}")
45
+ SYLogger.error(f"SQL日志处理失败: {str(e)}")
48
46
 
49
- # 监听 SQL 执行开始事件(记录开始时间到连接的 execution_options)
47
+ # 监听 SQL 执行开始事件
50
48
  @event.listens_for(Engine, "before_cursor_execute")
51
49
  def before_cursor_execute(
52
50
  conn, cursor, statement, parameters, context, executemany
53
51
  ):
54
52
  try:
55
- # 通过连接对象的 execution_options 设置开始时间
56
- # 这里会创建一个新的执行选项副本,避免修改不可变对象
57
53
  conn = conn.execution_options(_start_time=time.time())
58
54
  except Exception as e:
59
- SYLogger.error(f"SQL 开始时间记录失败: {str(e)}")
55
+ SYLogger.error(f"SQL开始时间记录失败: {str(e)}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sycommon-python-lib
3
- Version: 0.1.25
3
+ Version: 0.1.27
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -17,7 +17,7 @@ sycommon/health/ping.py,sha256=FTlnIKk5y1mPfS1ZGOeT5IM_2udF5aqVLubEtuBp18M,250
17
17
  sycommon/logging/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  sycommon/logging/kafka_log.py,sha256=3HjBg3WoDd3DmjtAlpyLcAVTKI-AHKrKlKmmPerq9tU,20751
19
19
  sycommon/logging/logger_wrapper.py,sha256=TiHsrIIHiQMzXgXK12-0KIpU9GhwQJOoHslakzmq2zc,357
20
- sycommon/logging/sql_logger.py,sha256=sNfWnlqwKGDCSYNktBao03k_Z0o_D4xplMokBqXeh8E,2541
20
+ sycommon/logging/sql_logger.py,sha256=s6mqGg3X1Srul8FQB-TJYGESigCrtnniuRq__Y6cFcY,2137
21
21
  sycommon/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  sycommon/middleware/context.py,sha256=_5ghpv4u_yAvjkgM-XDx8OnO-YI1XtntHrXsHJHZkwo,88
23
23
  sycommon/middleware/cors.py,sha256=0B5d_ovD56wcH9TfktRs88Q09R9f8Xx5h5ALWYvE8Iw,600
@@ -48,8 +48,8 @@ sycommon/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
48
  sycommon/tools/docs.py,sha256=OPj2ETheuWjXLyaXtaZPbwmJKfJaYXV5s4XMVAUNrms,1607
49
49
  sycommon/tools/snowflake.py,sha256=DdEj3T5r5OEvikp3puxqmmmz6BrggxomoSlnsRFb5dM,1174
50
50
  sycommon/tools/timing.py,sha256=OiiE7P07lRoMzX9kzb8sZU9cDb0zNnqIlY5pWqHcnkY,2064
51
- sycommon_python_lib-0.1.25.dist-info/METADATA,sha256=xNQjkWiZ4PpKIk8UqDa09HVjYyX4W0oWg_4OcMcPD3A,7038
52
- sycommon_python_lib-0.1.25.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
53
- sycommon_python_lib-0.1.25.dist-info/entry_points.txt,sha256=q_h2nbvhhmdnsOUZEIwpuoDjaNfBF9XqppDEmQn9d_A,46
54
- sycommon_python_lib-0.1.25.dist-info/top_level.txt,sha256=98CJ-cyM2WIKxLz-Pf0AitWLhJyrfXvyY8slwjTXNuc,17
55
- sycommon_python_lib-0.1.25.dist-info/RECORD,,
51
+ sycommon_python_lib-0.1.27.dist-info/METADATA,sha256=tgr4tP4xxA0OPHY7cRQzcRjMSHLN3bDlKYq_dCuoLRY,7038
52
+ sycommon_python_lib-0.1.27.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
53
+ sycommon_python_lib-0.1.27.dist-info/entry_points.txt,sha256=q_h2nbvhhmdnsOUZEIwpuoDjaNfBF9XqppDEmQn9d_A,46
54
+ sycommon_python_lib-0.1.27.dist-info/top_level.txt,sha256=98CJ-cyM2WIKxLz-Pf0AitWLhJyrfXvyY8slwjTXNuc,17
55
+ sycommon_python_lib-0.1.27.dist-info/RECORD,,