otel-utils 0.1.19__py3-none-any.whl → 0.1.21__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 otel-utils might be problematic. Click here for more details.
otel_utils/logging.py
CHANGED
|
@@ -8,25 +8,32 @@ from opentelemetry import trace
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class JsonFormatter(logging.Formatter):
|
|
11
|
-
|
|
12
11
|
def format(self, record):
|
|
13
|
-
log_record = {"timestamp": datetime.utcnow().isoformat(), "level": record.levelname, "
|
|
12
|
+
log_record = {"timestamp": datetime.utcnow().isoformat(), "level": record.levelname, "service": record.name,
|
|
14
13
|
"message": record.getMessage()}
|
|
15
14
|
|
|
15
|
+
ignored_attrs = {
|
|
16
|
+
'args', 'exc_info', 'exc_text', 'msg', 'message', 'levelname',
|
|
17
|
+
'levelno', 'pathname', 'filename', 'module', 'stack_info',
|
|
18
|
+
'lineno', 'funcName', 'created', 'msecs', 'relativeCreated',
|
|
19
|
+
'name', 'thread', 'threadName', 'processName', 'process',
|
|
20
|
+
'levelname', 'getMessage',
|
|
21
|
+
'otelTraceID', 'otelSpanID', 'otelTraceSampled', 'otelServiceName'
|
|
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
|
-
|
|
28
|
-
|
|
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 key == 'service_name' and 'service' in log_record and log_record['service'] == value:
|
|
34
|
+
pass
|
|
35
|
+
elif value is not None and value != '':
|
|
36
|
+
log_record[key] = value
|
|
30
37
|
|
|
31
38
|
return json.dumps(log_record)
|
|
32
39
|
|
|
@@ -89,9 +96,9 @@ class StructuredLogger:
|
|
|
89
96
|
extra_data["context"] = context
|
|
90
97
|
|
|
91
98
|
trace_ctx = self._get_trace_context()
|
|
92
|
-
if trace_ctx:
|
|
93
|
-
extra_data["
|
|
94
|
-
extra_data["
|
|
99
|
+
if trace_ctx and not hasattr(logging.getLogRecordFactory(), "otelTraceID"):
|
|
100
|
+
extra_data["trace_id"] = trace_ctx.get("trace_id")
|
|
101
|
+
extra_data["span_id"] = trace_ctx.get("span_id")
|
|
95
102
|
|
|
96
103
|
self.logger.log(level, message, extra=extra_data)
|
|
97
104
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
otel_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
otel_utils/configurator.py,sha256=zfvP2jpIA-CiyxIasvInxhVmrljTgLme6kG_HhKGwgI,7114
|
|
3
|
-
otel_utils/logging.py,sha256=
|
|
3
|
+
otel_utils/logging.py,sha256=4zOjlJg8RMR83TWcnGPmuZl4EIEO2JvQKdWXySXQvPo,4769
|
|
4
4
|
otel_utils/metrics.py,sha256=XD-t9V3peZJs97hN2hR2rwJKrcCJHqx2cldNOTCpzoA,3664
|
|
5
5
|
otel_utils/tracing.py,sha256=PtowQ7MvYld_xJlVAV4pBQuDBQIqPeP1FQPrzgZx9_Q,2625
|
|
6
|
-
otel_utils-0.1.
|
|
7
|
-
otel_utils-0.1.
|
|
8
|
-
otel_utils-0.1.
|
|
6
|
+
otel_utils-0.1.21.dist-info/METADATA,sha256=bVhDfJaxc9KYyeSE7qRkPXO1QNUOw9drCoKJ5kIU41w,5279
|
|
7
|
+
otel_utils-0.1.21.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
8
|
+
otel_utils-0.1.21.dist-info/RECORD,,
|
|
File without changes
|