blaxel 0.1.14.dev1__py3-none-any.whl → 0.1.14.dev3__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.
- blaxel/common/logger.py +54 -2
- blaxel/instrumentation/manager.py +10 -8
- {blaxel-0.1.14.dev1.dist-info → blaxel-0.1.14.dev3.dist-info}/METADATA +1 -1
- {blaxel-0.1.14.dev1.dist-info → blaxel-0.1.14.dev3.dist-info}/RECORD +6 -6
- {blaxel-0.1.14.dev1.dist-info → blaxel-0.1.14.dev3.dist-info}/WHEEL +0 -0
- {blaxel-0.1.14.dev1.dist-info → blaxel-0.1.14.dev3.dist-info}/licenses/LICENSE +0 -0
blaxel/common/logger.py
CHANGED
@@ -2,8 +2,55 @@
|
|
2
2
|
This module provides a custom colored formatter for logging and an initialization function
|
3
3
|
to set up logging configurations for Blaxel applications.
|
4
4
|
"""
|
5
|
-
|
5
|
+
import json
|
6
6
|
import logging
|
7
|
+
import os
|
8
|
+
from opentelemetry import trace
|
9
|
+
|
10
|
+
class JsonFormatter(logging.Formatter):
|
11
|
+
"""
|
12
|
+
A logger compatible with standard json logging.
|
13
|
+
"""
|
14
|
+
def __init__(self):
|
15
|
+
super().__init__()
|
16
|
+
self.trace_id_name = os.environ.get('BL_LOGGER_TRACE_ID', 'trace_id')
|
17
|
+
self.span_id_name = os.environ.get('BL_LOGGER_SPAN_ID', 'span_id')
|
18
|
+
self.labels_name = os.environ.get('BL_LOGGER_LABELS', 'labels')
|
19
|
+
self.trace_id_prefix = os.environ.get('BL_LOGGER_TRACE_ID_PREFIX', '')
|
20
|
+
self.span_id_prefix = os.environ.get('BL_LOGGER_SPAN_ID_PREFIX', '')
|
21
|
+
self.task_index = os.environ.get('BL_TASK_KEY', 'TASK_INDEX')
|
22
|
+
self.task_prefix = os.environ.get('BL_TASK_PREFIX', '')
|
23
|
+
self.execution_key = os.environ.get('BL_EXECUTION_KEY', 'BL_EXECUTION_ID')
|
24
|
+
self.execution_prefix = os.environ.get('BL_EXECUTION_PREFIX', '')
|
25
|
+
|
26
|
+
def format(self, record):
|
27
|
+
"""
|
28
|
+
Formats the log record by converting it to a JSON object with trace context and environment variables.
|
29
|
+
"""
|
30
|
+
log_entry = {
|
31
|
+
'message': record.getMessage(),
|
32
|
+
'severity': record.levelname,
|
33
|
+
self.labels_name: {}
|
34
|
+
}
|
35
|
+
|
36
|
+
# Add trace context if available
|
37
|
+
current_span = trace.get_current_span()
|
38
|
+
if current_span.is_recording():
|
39
|
+
span_context = current_span.get_span_context()
|
40
|
+
log_entry[self.trace_id_name] = f"{self.trace_id_prefix}{span_context.trace_id}"
|
41
|
+
log_entry[self.span_id_name] = f"{self.span_id_prefix}{span_context.span_id}"
|
42
|
+
|
43
|
+
# Add task ID if available
|
44
|
+
task_id = os.environ.get(self.task_index)
|
45
|
+
if task_id:
|
46
|
+
log_entry[self.labels_name]['blaxel-task'] = f"{self.task_prefix}{task_id}"
|
47
|
+
|
48
|
+
# Add execution ID if available
|
49
|
+
execution_id = os.environ.get(self.execution_key)
|
50
|
+
if execution_id:
|
51
|
+
log_entry[self.labels_name]['blaxel-execution'] = f"{self.execution_prefix}{execution_id.split('-')[-1]}"
|
52
|
+
|
53
|
+
return json.dumps(log_entry)
|
7
54
|
|
8
55
|
|
9
56
|
class ColoredFormatter(logging.Formatter):
|
@@ -51,5 +98,10 @@ def init_logger(log_level: str):
|
|
51
98
|
logging.getLogger('urllib3').setLevel(logging.CRITICAL)
|
52
99
|
logging.getLogger("httpx").setLevel(logging.CRITICAL)
|
53
100
|
handler = logging.StreamHandler()
|
54
|
-
|
101
|
+
|
102
|
+
logger_type = os.environ.get("BL_LOGGER", "http")
|
103
|
+
if logger_type == "json":
|
104
|
+
handler.setFormatter(JsonFormatter())
|
105
|
+
else:
|
106
|
+
handler.setFormatter(ColoredFormatter("%(levelname)s %(name)s - %(message)s"))
|
55
107
|
logging.basicConfig(level=log_level, handlers=[handler])
|
@@ -7,6 +7,7 @@ import importlib
|
|
7
7
|
import logging
|
8
8
|
import signal
|
9
9
|
import time
|
10
|
+
import os
|
10
11
|
from typing import Any, Dict, List, Optional, Type
|
11
12
|
|
12
13
|
from opentelemetry import metrics, trace
|
@@ -164,14 +165,15 @@ class TelemetryManager:
|
|
164
165
|
metrics.set_meter_provider(meter_provider)
|
165
166
|
self.meter = meter_provider.get_meter(__name__)
|
166
167
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
168
|
+
logger_type = os.environ.get("BL_LOGGER", "http")
|
169
|
+
if logger_type == "http":
|
170
|
+
self.logger_provider = LoggerProvider(resource=resource)
|
171
|
+
set_logger_provider(self.logger_provider)
|
172
|
+
self.logger_provider.add_log_record_processor(
|
173
|
+
AsyncLogRecordProcessor(self.get_log_exporter())
|
174
|
+
)
|
175
|
+
handler = LoggingHandler(level=logging.NOTSET, logger_provider=self.logger_provider)
|
176
|
+
logging.getLogger().addHandler(handler)
|
175
177
|
|
176
178
|
# Load and enable instrumentations
|
177
179
|
for name, mapping in MAPPINGS.items():
|
@@ -263,11 +263,11 @@ blaxel/client/models/workspace_user.py,sha256=70CcifQWYbeWG7TDui4pblTzUe5sVK0AS1
|
|
263
263
|
blaxel/common/autoload.py,sha256=NFuK71-IHOY2JQyEBSjDCVfUaQ8D8PJsEUEryIdG4AU,263
|
264
264
|
blaxel/common/env.py,sha256=wTbzPDdNgz4HMJiS2NCZmQlN0qpxy1PQEYBaZgtvhoc,1247
|
265
265
|
blaxel/common/internal.py,sha256=PExgeKfJEmjINKreNb3r2nB5GAfG7uJhbfqHxuxBED8,2395
|
266
|
-
blaxel/common/logger.py,sha256=
|
266
|
+
blaxel/common/logger.py,sha256=7oWvrZ4fg7qUfrXe7oFAeH-1pTxadrvWQmPDn7bvbmQ,4111
|
267
267
|
blaxel/common/settings.py,sha256=7KTryuBdud0IfHqykX7xEEtpgq5M5h1Z8YEzYKsHB-Q,2327
|
268
268
|
blaxel/instrumentation/exporters.py,sha256=EoX3uaBVku1Rg49pSNXKFyHhgY5OV3Ih6UlqgjF5epw,1670
|
269
269
|
blaxel/instrumentation/log.py,sha256=4tGyvLg6r4DbjqJfajYbbZ1toUzF4Q4H7kHVqYWFAEA,2537
|
270
|
-
blaxel/instrumentation/manager.py,sha256=
|
270
|
+
blaxel/instrumentation/manager.py,sha256=vX8RT84upjzgCUeiULp9QpDSSNVnPNFxLq0sMVz4Pjs,8974
|
271
271
|
blaxel/instrumentation/map.py,sha256=zZoiUiQHmik5WQZ4VCWNARSa6ppMi0r7D6hlb41N-Mg,1589
|
272
272
|
blaxel/instrumentation/span.py,sha256=X2lwfu_dyxwQTMQJT2vbXOrbVSChEhjRLc413QOxQJM,3244
|
273
273
|
blaxel/jobs/__init__.py,sha256=4Mk-S_eT-bV-bI9Y_TOfisv_rxme9O1Z69AgmDoAKTY,6510
|
@@ -341,7 +341,7 @@ blaxel/tools/llamaindex.py,sha256=-gQ-C9V_h9a11J4ItsbWjXrCJOg0lRKsb98v9rVsNak,71
|
|
341
341
|
blaxel/tools/openai.py,sha256=GuFXkj6bXEwldyVr89jEsRAi5ihZUVEVe327QuWiGNs,653
|
342
342
|
blaxel/tools/pydantic.py,sha256=CvnNbAG_J4yBtA-XFI4lQrq3FYKjNd39hu841vZT004,1801
|
343
343
|
blaxel/tools/types.py,sha256=YPCGJ4vZDhqR0X2H_TWtc5chQScsC32nGTQdRKJlO8Y,707
|
344
|
-
blaxel-0.1.14.
|
345
|
-
blaxel-0.1.14.
|
346
|
-
blaxel-0.1.14.
|
347
|
-
blaxel-0.1.14.
|
344
|
+
blaxel-0.1.14.dev3.dist-info/METADATA,sha256=wwb37Z03Dg-wMo0jN0MhdZUf-uA5lLlKrdbywdH8hMM,11777
|
345
|
+
blaxel-0.1.14.dev3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
346
|
+
blaxel-0.1.14.dev3.dist-info/licenses/LICENSE,sha256=p5PNQvpvyDT_0aYBDgmV1fFI_vAD2aSV0wWG7VTgRis,1069
|
347
|
+
blaxel-0.1.14.dev3.dist-info/RECORD,,
|
File without changes
|
File without changes
|