diff options
author | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
---|---|---|
committer | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
commit | 4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch) | |
tree | ee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_diagnostics/status_logger.py | |
parent | cc961e04ba734dd72309fb548a2f97d67d578813 (diff) | |
download | gn-ai-master.tar.gz |
Diffstat (limited to '.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_diagnostics/status_logger.py')
-rw-r--r-- | .venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_diagnostics/status_logger.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_diagnostics/status_logger.py b/.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_diagnostics/status_logger.py new file mode 100644 index 00000000..3f1ca29e --- /dev/null +++ b/.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_diagnostics/status_logger.py @@ -0,0 +1,58 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License in the project root for +# license information. +# -------------------------------------------------------------------------- + +from json import dumps +from os import getpid, makedirs +from os.path import exists, join +from platform import node + +from azure.monitor.opentelemetry._utils import ( + _EXTENSION_VERSION, + _IS_DIAGNOSTICS_ENABLED, + _get_customer_ikey_from_env_var, + _get_log_path, +) +from azure.monitor.opentelemetry._version import VERSION + +_MACHINE_NAME = node() +_STATUS_LOG_PATH = _get_log_path(status_log_path=True) + + +def _get_status_logger_file_name(pid): + return f"status_{_MACHINE_NAME}_{pid}.json" + + +class AzureStatusLogger: + @classmethod + def _get_status_json(cls, agent_initialized_successfully, pid, reason=None, sdk_present=None): + status_json = { + "AgentInitializedSuccessfully": agent_initialized_successfully, + "AppType": "python", + "MachineName": _MACHINE_NAME, + "PID": pid, + "SdkVersion": VERSION, + "Ikey": _get_customer_ikey_from_env_var(), + "ExtensionVersion": _EXTENSION_VERSION, + } + if reason: + status_json["Reason"] = reason + if sdk_present: + status_json["SDKPresent"] = sdk_present + return status_json + + @classmethod + def log_status(cls, agent_initialized_successfully, reason=None, sdk_present=None): + if _IS_DIAGNOSTICS_ENABLED and _STATUS_LOG_PATH: + pid = getpid() + status_json = AzureStatusLogger._get_status_json(agent_initialized_successfully, pid, reason, sdk_present) + if not exists(_STATUS_LOG_PATH): + makedirs(_STATUS_LOG_PATH) + # Change to be hostname and pid + status_logger_file_name = _get_status_logger_file_name(pid) + with open(join(_STATUS_LOG_PATH, status_logger_file_name), "w", encoding="utf8") as f: + f.seek(0) + f.write(dumps(status_json)) + f.truncate() |