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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: otel-utils
3
- Version: 0.1.19
3
+ Version: 0.1.20
4
4
  Summary: Utilidades simplificadas para instrumentación con OpenTelemetry
5
5
  License: Proprietary
6
6
  Author: Harold Portocarrero
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "otel-utils"
3
- version = "0.1.19"
3
+ version = "0.1.20"
4
4
  description = "Utilidades simplificadas para instrumentación con OpenTelemetry"
5
5
  authors = ["Harold Portocarrero <harold@getcometa.com>"]
6
6
  readme = "README.md"
@@ -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
- if hasattr(record, "context") and record.context:
22
- log_record["context"] = record.context
23
-
24
- if hasattr(record, "operation"):
25
- log_record["operation"] = record.operation
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["otelTraceID"] = trace_ctx.get("trace_id")
94
- extra_data["otelSpanID"] = trace_ctx.get("span_id")
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