otel-utils 0.7.0__py3-none-any.whl → 0.8.0__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.
@@ -150,6 +150,11 @@ class OtelConfigurator:
150
150
 
151
151
  set_logger_provider(logger_provider)
152
152
 
153
+ self.logger = StructuredLogger(
154
+ self.config.service_name,
155
+ environment=self.config.environment
156
+ )
157
+
153
158
  if self.config.enable_console_logging:
154
159
  console_handler = logging.StreamHandler()
155
160
 
@@ -177,18 +182,10 @@ class OtelConfigurator:
177
182
  meter_provider=metrics.get_meter_provider(),
178
183
  )
179
184
 
180
- self.structured_logger = StructuredLogger(
181
- self.config.service_name,
182
- default_attributes={"env": self.config.environment}
183
- )
184
- self.logger = self.structured_logger.logger
185
-
186
- self.logger.propagate = False
187
-
188
185
 
189
186
  def get_logger(service_name: str = None, config: OtelConfig = None) -> StructuredLogger:
190
187
  if config:
191
188
  configurator = OtelConfigurator(config)
192
- return configurator.structured_logger
189
+ return configurator.logger
193
190
 
194
191
  return StructuredLogger(service_name or "default-service")
otel_utils/logging.py CHANGED
@@ -37,6 +37,9 @@ class JsonFormatter(logging.Formatter):
37
37
  elif value is not None and value != '':
38
38
  log_record[key] = value
39
39
 
40
+ if "environment" in log_record:
41
+ log_record["env"] = log_record.pop("environment")
42
+
40
43
  return json.dumps(log_record)
41
44
 
42
45
 
@@ -48,12 +51,14 @@ class StructuredLogger:
48
51
  def __init__(
49
52
  self,
50
53
  service_name: str,
51
- default_attributes: Optional[Dict[str, Any]] = None
54
+ default_attributes: Optional[Dict[str, Any]] = None,
55
+ environment: Optional[str] = None
52
56
  ):
53
57
  self.logger = logging.getLogger(service_name)
54
58
  self.service_name = service_name
55
59
  self.default_attributes = default_attributes or {}
56
-
60
+ if environment:
61
+ self.default_attributes['environment'] = environment
57
62
  self.logger.propagate = False
58
63
 
59
64
  if not self.logger.handlers:
@@ -86,11 +91,10 @@ class StructuredLogger:
86
91
 
87
92
  context = kwargs.copy() if kwargs else None
88
93
 
89
- extra_data = {
90
- "service_name": self.service_name
91
- }
92
-
93
- extra_data.update(self.default_attributes)
94
+ attributes = dict(self.default_attributes)
95
+ attributes.update(kwargs)
96
+ extra_data = attributes.copy()
97
+ extra_data['service_name'] = self.service_name
94
98
 
95
99
  if operation:
96
100
  extra_data["operation"] = operation
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: otel-utils
3
- Version: 0.7.0
3
+ Version: 0.8.0
4
4
  Summary: Utilidades simplificadas para instrumentación con OpenTelemetry
5
5
  License: Proprietary
6
6
  Author: Harold Portocarrero
@@ -0,0 +1,8 @@
1
+ otel_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ otel_utils/configurator.py,sha256=oq6OMt366xnWV5Qz-eu529MV4yks4Lclm_i2nzPGYR4,7483
3
+ otel_utils/logging.py,sha256=V-31IMbghZs6UgEsTMwy3tFrfrz8KQk5dD9C-lNP6zc,5831
4
+ otel_utils/metrics.py,sha256=XD-t9V3peZJs97hN2hR2rwJKrcCJHqx2cldNOTCpzoA,3664
5
+ otel_utils/tracing.py,sha256=PtowQ7MvYld_xJlVAV4pBQuDBQIqPeP1FQPrzgZx9_Q,2625
6
+ otel_utils-0.8.0.dist-info/METADATA,sha256=Gz_-whbRRB2rHcU31FBRtWqzIL-DMTNOW4pC26i6qFM,5278
7
+ otel_utils-0.8.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
8
+ otel_utils-0.8.0.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- otel_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- otel_utils/configurator.py,sha256=scrT4K0Y4o9DmYQs_xuToxnH1Q8fkSCQGk5jsSNQUXU,7612
3
- otel_utils/logging.py,sha256=rJFxWlJ6iP63x1QpIY1Uc_-cgOlhITNGIel41RcjL6Q,5545
4
- otel_utils/metrics.py,sha256=XD-t9V3peZJs97hN2hR2rwJKrcCJHqx2cldNOTCpzoA,3664
5
- otel_utils/tracing.py,sha256=PtowQ7MvYld_xJlVAV4pBQuDBQIqPeP1FQPrzgZx9_Q,2625
6
- otel_utils-0.7.0.dist-info/METADATA,sha256=IJV0G7TZCzOf-xJXFAOPfPi5r4TRhs7V1Bf7MkM_9Go,5278
7
- otel_utils-0.7.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
8
- otel_utils-0.7.0.dist-info/RECORD,,