Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
([#281](https://github.com/microsoft/ApplicationInsights-Python/pull/281))
- Fixed spelling
([#291](https://github.com/microsoft/ApplicationInsights-Python/pull/291))
- Fixing formatting issues for azure sdk
([#292](https://github.com/microsoft/ApplicationInsights-Python/pull/292))

## [1.0.0b12](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b12) - 2023-05-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ def configure_azure_monitor(**kwargs) -> None:
end user to configure OpenTelemetry and Azure monitor components. The
configuration can be done via arguments passed to this function.
:keyword str connection_string: Connection string for your Application Insights resource.
:keyword ManagedIdentityCredential/ClientSecretCredential credential: Token credential, such as ManagedIdentityCredential or ClientSecretCredential, used for Azure Active Directory (AAD) authentication. Defaults to None.
:keyword bool disable_offline_storage: Boolean value to determine whether to disable storing failed telemetry records for retry. Defaults to `False`.
:keyword str storage_directory: Storage directory in which to store retry files. Defaults to `<tempfile.gettempdir()>/Microsoft/AzureMonitor/opentelemetry-python-<your-instrumentation-key>`.
:keyword ManagedIdentityCredential/ClientSecretCredential credential: Token credential, such as
ManagedIdentityCredential or ClientSecretCredential, used for Azure Active Directory (AAD) authentication. Defaults
to None.
:keyword bool disable_offline_storage: Boolean value to determine whether to disable storing failed telemetry
records for retry. Defaults to `False`.
:keyword str storage_directory: Storage directory in which to store retry files. Defaults to
`<tempfile.gettempdir()>/Microsoft/AzureMonitor/opentelemetry-python-<your-instrumentation-key>`.
:rtype: None
"""

Expand Down Expand Up @@ -143,7 +147,7 @@ def _setup_instrumentations():
instrumentor: BaseInstrumentor = entry_point.load()
# tell instrumentation to not run dep checks again as we already did it above
instrumentor().instrument(skip_dep_check=True)
except Exception as ex:
except Exception as ex: # pylint: disable=broad-except
_logger.warning(
"Exception occurred when instrumenting: %s.",
lib_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@
try:
_CUSTOMER_IKEY = ConnectionStringParser().instrumentation_key
except ValueError as e:
logger.error("Failed to parse Instrumentation Key: %s" % e)
logger.error("Failed to parse Instrumentation Key: %s", e)


def _get_log_path(status_log_path=False):
system = platform.system()
if system == "Linux":
return _LOG_PATH_LINUX
elif system == "Windows":
if system == "Windows":
log_path = str(Path.home()) + _LOG_PATH_WINDOWS
if status_log_path:
return log_path + "\\status"
else:
return log_path
else:
return None
return None


def _env_var_or_default(var_name, default_val=""):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ def _configure(self, **kwargs):
super()._configure(**kwargs)
except ValueError as e:
_logger.error(
f"Azure Monitor Configurator failed during configuration due to a ValueError: {e}"
"Azure Monitor Configurator failed during configuration due to a ValueError: %s",
e,
)
raise e
except Exception as e:
_logger.error(
f"Azure Monitor Configurator failed during configuration: {e}"
"Azure Monitor Configurator failed during configuration: %s", e
)
raise e
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def _configure_auto_instrumentation() -> None:
AzureStatusLogger.log_status(False, reason=exc)
_logger.error(
"Azure Monitor OpenTelemetry Distro failed during "
+ f"configuration: {exc}"
+ "configuration: %s",
exc,
)
raise exc
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ class AzureDiagnosticLogging:
_lock = threading.Lock()
_f_handler = None

def _initialize():
@classmethod
def _initialize(cls):
with AzureDiagnosticLogging._lock:
if not AzureDiagnosticLogging._initialized:
if _IS_DIAGNOSTICS_ENABLED and _DIAGNOSTIC_LOG_PATH:
format = (
log_format = (
"{"
+ '"time":"%(asctime)s.%(msecs)03d", '
+ '"level":"%(levelname)s", '
Expand All @@ -64,16 +65,15 @@ def _initialize():
)
)
formatter = logging.Formatter(
fmt=format, datefmt="%Y-%m-%dT%H:%M:%S"
fmt=log_format, datefmt="%Y-%m-%dT%H:%M:%S"
)
AzureDiagnosticLogging._f_handler.setFormatter(formatter)
AzureDiagnosticLogging._initialized = True
_logger.info("Initialized Azure Diagnostic Logger.")

def enable(logger: logging.Logger):
@classmethod
def enable(cls, logger: logging.Logger):
AzureDiagnosticLogging._initialize()
if AzureDiagnosticLogging._initialized:
logger.addHandler(AzureDiagnosticLogging._f_handler)
_logger.info(
"Added Azure diagnostics logging to %s." % logger.name
)
_logger.info("Added Azure diagnostics logging to %s.", logger.name)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@


class AzureStatusLogger:
def _get_status_json(agent_initialized_successfully, pid, reason=None):
@classmethod
def _get_status_json(
cls, agent_initialized_successfully, pid, reason=None
):
status_json = {
"AgentInitializedSuccessfully": agent_initialized_successfully,
"AppType": "python",
Expand All @@ -36,7 +39,8 @@ def _get_status_json(agent_initialized_successfully, pid, reason=None):
status_json["Reason"] = reason
return status_json

def log_status(agent_initialized_successfully, reason=None):
@classmethod
def log_status(cls, agent_initialized_successfully, reason=None):
if _IS_DIAGNOSTICS_ENABLED and _STATUS_LOG_PATH:
pid = getpid()
status_json = AzureStatusLogger._get_status_json(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ def _default_logging_export_interval_ms(configurations):
default = int(environ[LOGGING_EXPORT_INTERVAL_MS_ENV_VAR])
except ValueError as e:
_logger.error(
_INVALID_INT_MESSAGE
% (LOGGING_EXPORT_INTERVAL_MS_ENV_VAR, default, e)
_INVALID_INT_MESSAGE,
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR,
default,
e,
)
configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] = default

Expand All @@ -102,6 +104,6 @@ def _default_sampling_ratio(configurations):
default = float(environ[SAMPLING_RATIO_ENV_VAR])
except ValueError as e:
_logger.error(
_INVALID_FLOAT_MESSAGE % (SAMPLING_RATIO_ENV_VAR, default, e)
_INVALID_FLOAT_MESSAGE, SAMPLING_RATIO_ENV_VAR, default, e
)
configurations[SAMPLING_RATIO_ARG] = default