QTZPOC-20

QTZPOC-20: Implement structured logging with metadata for repository, worker, and OPC activities.
This commit is contained in:
2026-09-10 14:15:42 -03:00
parent 4cccc45c34
commit 6c0d178f99
5 changed files with 60 additions and 41 deletions

View File

@@ -136,7 +136,7 @@ async def main():
metadata_runtime = {**metadata, 'runtime': runtime}
logger.custom_info('Starting prometheus client...', metadata_runtime)
start_prometheus_server()
start_prometheus_server(logger, metadata_runtime)
logger.custom_info('Starting Notification Handler...', metadata_runtime)
@@ -313,7 +313,7 @@ async def main():
exit_code = e.code if isinstance(e, SystemExit) and isinstance(e.code, int) else 0
raise
except Exception as e:
logger.custom_error(f'An unhandled exception occurred: {e}', metadata)
logger.custom_error(f'An unhandled exception occurred: {e}', metadata_runtime)
exit_code = 1
finally:
if notification_handler:
@@ -324,7 +324,7 @@ async def main():
sys.exit(exit_code)
def start_prometheus_server():
def start_prometheus_server(logger, metadata: dict):
"""
Starts the Prometheus metrics server for monitoring and observability.
@@ -344,10 +344,10 @@ def start_prometheus_server():
try:
port = int(os.getenv('HTTP_METRICS_PORT', 9090))
start_http_server(port)
print(f'Prometheus server started on port {port}.')
logger.custom_info(f'Prometheus server started on port {port}.', metadata)
metrics.APP_UP.labels(pod_id=POD_ID).set(1) # Mark app as UP
except Exception as e:
print(f'Failed to start Prometheus server: {e}')
logger.custom_critical(f'Failed to start Prometheus server: {e}', metadata)
os._exit(1)