|
16 | 16 | from ._dbos_config import ConfigFile |
17 | 17 |
|
18 | 18 | dbos_logger = logging.getLogger("dbos") |
19 | | -_otlp_handler, _otlp_transformer = None, None |
| 19 | +_otlp_handler, _dbos_log_transformer = None, None |
20 | 20 |
|
21 | 21 |
|
22 | 22 | class DBOSLogTransformer(logging.Filter): |
@@ -93,25 +93,31 @@ def config_logger(config: "ConfigFile") -> None: |
93 | 93 | global _otlp_handler |
94 | 94 | _otlp_handler = LoggingHandler(logger_provider=log_provider) |
95 | 95 |
|
96 | | - # Attach DBOS-specific attributes to all log entries. |
97 | | - global _otlp_transformer |
98 | | - _otlp_transformer = DBOSLogTransformer() |
99 | | - |
100 | 96 | # Direct DBOS logs to OTLP |
101 | 97 | dbos_logger.addHandler(_otlp_handler) |
102 | | - dbos_logger.addFilter(_otlp_transformer) |
| 98 | + |
| 99 | + # Attach DBOS-specific attributes to all log entries. |
| 100 | + global _dbos_log_transformer |
| 101 | + _dbos_log_transformer = DBOSLogTransformer() |
| 102 | + dbos_logger.addFilter(_dbos_log_transformer) |
103 | 103 |
|
104 | 104 |
|
105 | 105 | def add_otlp_to_all_loggers() -> None: |
106 | | - if _otlp_handler is not None and _otlp_transformer is not None: |
| 106 | + if _otlp_handler is not None: |
107 | 107 | root = logging.root |
108 | | - |
109 | 108 | root.addHandler(_otlp_handler) |
110 | | - root.addFilter(_otlp_transformer) |
111 | | - |
112 | 109 | for logger_name in root.manager.loggerDict: |
113 | 110 | if logger_name != dbos_logger.name: |
114 | 111 | logger = logging.getLogger(logger_name) |
115 | 112 | if not logger.propagate: |
116 | 113 | logger.addHandler(_otlp_handler) |
117 | | - logger.addFilter(_otlp_transformer) |
| 114 | + |
| 115 | + |
| 116 | +def add_transformer_to_all_loggers() -> None: |
| 117 | + if _dbos_log_transformer is not None: |
| 118 | + root = logging.root |
| 119 | + root.addFilter(_dbos_log_transformer) |
| 120 | + for logger_name in root.manager.loggerDict: |
| 121 | + if logger_name != dbos_logger.name: |
| 122 | + logger = logging.getLogger(logger_name) |
| 123 | + logger.addFilter(_dbos_log_transformer) |
0 commit comments