otel-utils 0.7.1__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.
otel_utils/configurator.py
CHANGED
|
@@ -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.
|
|
189
|
+
return configurator.logger
|
|
193
190
|
|
|
194
191
|
return StructuredLogger(service_name or "default-service")
|
otel_utils/logging.py
CHANGED
|
@@ -9,10 +9,8 @@ from opentelemetry import trace
|
|
|
9
9
|
|
|
10
10
|
class JsonFormatter(logging.Formatter):
|
|
11
11
|
def format(self, record):
|
|
12
|
-
print('record', record)
|
|
13
12
|
log_record = {"timestamp": datetime.utcnow().isoformat(), "level": record.levelname, "service": record.name,
|
|
14
13
|
"message": record.getMessage()}
|
|
15
|
-
print('log_record', log_record)
|
|
16
14
|
|
|
17
15
|
ignored_attrs = {
|
|
18
16
|
'args', 'exc_info', 'exc_text', 'msg', 'message', 'levelname',
|
|
@@ -39,7 +37,8 @@ class JsonFormatter(logging.Formatter):
|
|
|
39
37
|
elif value is not None and value != '':
|
|
40
38
|
log_record[key] = value
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
if "environment" in log_record:
|
|
41
|
+
log_record["env"] = log_record.pop("environment")
|
|
43
42
|
|
|
44
43
|
return json.dumps(log_record)
|
|
45
44
|
|
|
@@ -52,12 +51,14 @@ class StructuredLogger:
|
|
|
52
51
|
def __init__(
|
|
53
52
|
self,
|
|
54
53
|
service_name: str,
|
|
55
|
-
default_attributes: Optional[Dict[str, Any]] = None
|
|
54
|
+
default_attributes: Optional[Dict[str, Any]] = None,
|
|
55
|
+
environment: Optional[str] = None
|
|
56
56
|
):
|
|
57
57
|
self.logger = logging.getLogger(service_name)
|
|
58
58
|
self.service_name = service_name
|
|
59
59
|
self.default_attributes = default_attributes or {}
|
|
60
|
-
|
|
60
|
+
if environment:
|
|
61
|
+
self.default_attributes['environment'] = environment
|
|
61
62
|
self.logger.propagate = False
|
|
62
63
|
|
|
63
64
|
if not self.logger.handlers:
|
|
@@ -90,11 +91,10 @@ class StructuredLogger:
|
|
|
90
91
|
|
|
91
92
|
context = kwargs.copy() if kwargs else None
|
|
92
93
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
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
|
|
98
98
|
|
|
99
99
|
if operation:
|
|
100
100
|
extra_data["operation"] = operation
|
|
@@ -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=MHviLFGk3ZFJ-k0exs_4974eGKIL-qckTskGeNsujMk,5664
|
|
4
|
-
otel_utils/metrics.py,sha256=XD-t9V3peZJs97hN2hR2rwJKrcCJHqx2cldNOTCpzoA,3664
|
|
5
|
-
otel_utils/tracing.py,sha256=PtowQ7MvYld_xJlVAV4pBQuDBQIqPeP1FQPrzgZx9_Q,2625
|
|
6
|
-
otel_utils-0.7.1.dist-info/METADATA,sha256=9vqwxz5GVkGivtUdRL4RRyKYuCRh4yJ9a9-WWJ0hCGc,5278
|
|
7
|
-
otel_utils-0.7.1.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
8
|
-
otel_utils-0.7.1.dist-info/RECORD,,
|
|
File without changes
|