otel-utils 0.1.19__tar.gz → 0.1.20__tar.gz
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 otel-utils might be problematic. Click here for more details.
- {otel_utils-0.1.19 → otel_utils-0.1.20}/PKG-INFO +1 -1
- {otel_utils-0.1.19 → otel_utils-0.1.20}/pyproject.toml +1 -1
- {otel_utils-0.1.19 → otel_utils-0.1.20}/src/otel_utils/logging.py +17 -12
- {otel_utils-0.1.19 → otel_utils-0.1.20}/README.md +0 -0
- {otel_utils-0.1.19 → otel_utils-0.1.20}/src/otel_utils/__init__.py +0 -0
- {otel_utils-0.1.19 → otel_utils-0.1.20}/src/otel_utils/configurator.py +0 -0
- {otel_utils-0.1.19 → otel_utils-0.1.20}/src/otel_utils/metrics.py +0 -0
- {otel_utils-0.1.19 → otel_utils-0.1.20}/src/otel_utils/tracing.py +0 -0
|
@@ -13,20 +13,25 @@ class JsonFormatter(logging.Formatter):
|
|
|
13
13
|
log_record = {"timestamp": datetime.utcnow().isoformat(), "level": record.levelname, "logger": record.name,
|
|
14
14
|
"message": record.getMessage()}
|
|
15
15
|
|
|
16
|
+
ignored_attrs = {
|
|
17
|
+
'args', 'exc_info', 'exc_text', 'msg', 'message', 'levelname',
|
|
18
|
+
'levelno', 'pathname', 'filename', 'module', 'stack_info',
|
|
19
|
+
'lineno', 'funcName', 'created', 'msecs', 'relativeCreated',
|
|
20
|
+
'name', 'thread', 'threadName', 'processName', 'process',
|
|
21
|
+
'levelname', 'getMessage'
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
if hasattr(record, "otelTraceID"):
|
|
17
25
|
log_record["trace_id"] = getattr(record, "otelTraceID")
|
|
18
26
|
if hasattr(record, "otelSpanID"):
|
|
19
27
|
log_record["span_id"] = getattr(record, "otelSpanID")
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
for attr in ["service_name", "status", "error_type", "error_message"]:
|
|
28
|
-
if hasattr(record, attr):
|
|
29
|
-
log_record[attr] = getattr(record, attr)
|
|
29
|
+
for key, value in record.__dict__.items():
|
|
30
|
+
if key not in ignored_attrs and not key.startswith('_'):
|
|
31
|
+
if key == 'context' and value:
|
|
32
|
+
log_record[key] = value
|
|
33
|
+
elif value is not None and value != '':
|
|
34
|
+
log_record[key] = value
|
|
30
35
|
|
|
31
36
|
return json.dumps(log_record)
|
|
32
37
|
|
|
@@ -89,9 +94,9 @@ class StructuredLogger:
|
|
|
89
94
|
extra_data["context"] = context
|
|
90
95
|
|
|
91
96
|
trace_ctx = self._get_trace_context()
|
|
92
|
-
if trace_ctx:
|
|
93
|
-
extra_data["
|
|
94
|
-
extra_data["
|
|
97
|
+
if trace_ctx and not hasattr(logging.getLogRecordFactory(), "otelTraceID"):
|
|
98
|
+
extra_data["trace_id"] = trace_ctx.get("trace_id")
|
|
99
|
+
extra_data["span_id"] = trace_ctx.get("span_id")
|
|
95
100
|
|
|
96
101
|
self.logger.log(level, message, extra=extra_data)
|
|
97
102
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|