otel-utils 0.1.19__tar.gz → 0.1.21__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.21
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.21"
4
4
  description = "Utilidades simplificadas para instrumentación con OpenTelemetry"
5
5
  authors = ["Harold Portocarrero <harold@getcometa.com>"]
6
6
  readme = "README.md"
@@ -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, "logger": record.name,
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
- 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 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["otelTraceID"] = trace_ctx.get("trace_id")
94
- extra_data["otelSpanID"] = trace_ctx.get("span_id")
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
 
File without changes