Skip to content

Commit 49f0279

Browse files
committed
update log attribute handler
1 parent bb1d89e commit 49f0279

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

middleware/log.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,29 @@ def create_logger_handler(options: MWOptions, resource: Resource) -> LoggingHand
6060

6161
return handler
6262

63+
# class MWLoggingHandler(LoggingHandler):
64+
# @staticmethod
65+
# def _get_attributes(record: LogRecord):
66+
# attributes = LoggingHandler._get_attributes(record)
67+
# if "request" in attributes:
68+
# attributes["request"] = f'{attributes["request"].method} {attributes["request"].path}'
69+
# return attributes
70+
6371
class MWLoggingHandler(LoggingHandler):
6472
@staticmethod
6573
def _get_attributes(record: LogRecord):
6674
attributes = LoggingHandler._get_attributes(record)
67-
if "request" in attributes:
68-
attributes["request"] = f'{attributes["request"].method} {attributes["request"].path}'
75+
76+
for key, value in attributes.items():
77+
if key == "request":
78+
if hasattr(value, "method") and hasattr(value, "path"):
79+
if len(vars(value)) == 2:
80+
attributes[key] = f'{value.method} {value.path}'
81+
else:
82+
attributes[key] = str(value)
83+
else:
84+
attributes[key] = str(value)
85+
elif not isinstance(value, (bool, str, bytes, int, float)):
86+
attributes[key] = str(value)
87+
6988
return attributes

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "middleware-io"
7-
version = "2.0.0"
7+
version = "2.0.1rc0"
88
requires-python = ">=3.8"
99
description = "Middleware's APM tool enables Python developers to effortlessly monitor their applications, gathering distributed tracing, metrics, logs, and profiling data for valuable insights and performance optimization."
1010
authors = [{ name = "middleware-dev" }]

0 commit comments

Comments
 (0)