From 1f8851ec0eba58a73e63287322f2c94b8182d4fc Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 7 Jun 2023 17:11:37 -0700 Subject: [PATCH 1/4] spelling --- CHANGELOG.md | 2 ++ .../azure/monitor/opentelemetry/_configure.py | 2 +- .../azure/monitor/opentelemetry/autoinstrumentation/_distro.py | 2 +- azure-monitor-opentelemetry/samples/tracing/manual.py | 2 +- .../tests/autoinstrumentation/test_distro.py | 2 +- azure-monitor-opentelemetry/tests/test_constants.py | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13ffca69..8455cc87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Update samples ([#281](https://github.com/microsoft/ApplicationInsights-Python/pull/281)) +- Fixed spelling + ([#291](https://github.com/microsoft/ApplicationInsights-Python/pull/291)) ## [1.0.0b12](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b12) - 2023-05-05 diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py index 47873cbc..0073b427 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py @@ -145,7 +145,7 @@ def _setup_instrumentations(): instrumentor().instrument(skip_dep_check=True) except Exception as ex: _logger.warning( - "Exception occured when instrumenting: %s.", + "Exception occurred when instrumenting: %s.", lib_name, exc_info=ex, ) diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_distro.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_distro.py index 1ca3adf5..d9341050 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_distro.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_distro.py @@ -34,7 +34,7 @@ def _configure(self, **kwargs) -> None: _configure_auto_instrumentation() except Exception as ex: _logger.exception( - ("Error occured auto-instrumenting AzureMonitorDistro") + ("Error occurred auto-instrumenting AzureMonitorDistro") ) raise ex diff --git a/azure-monitor-opentelemetry/samples/tracing/manual.py b/azure-monitor-opentelemetry/samples/tracing/manual.py index 7bbf1e50..feaa15f4 100644 --- a/azure-monitor-opentelemetry/samples/tracing/manual.py +++ b/azure-monitor-opentelemetry/samples/tracing/manual.py @@ -11,7 +11,7 @@ engine = create_engine("sqlite:///:memory:") # SQLAlchemy instrumentation is not officially supported by this package -# However, you can use the OpenTelemetry instument method manually in +# However, you can use the OpenTelemetry instrument method manually in # conjunction with configure_azure_monitor SQLAlchemyInstrumentor().instrument( engine=engine, diff --git a/azure-monitor-opentelemetry/tests/autoinstrumentation/test_distro.py b/azure-monitor-opentelemetry/tests/autoinstrumentation/test_distro.py index aae4653b..874ca922 100644 --- a/azure-monitor-opentelemetry/tests/autoinstrumentation/test_distro.py +++ b/azure-monitor-opentelemetry/tests/autoinstrumentation/test_distro.py @@ -10,7 +10,7 @@ class TestDistro(TestCase): @patch( "azure.monitor.opentelemetry.autoinstrumentation._distro.AzureDiagnosticLogging.enable" ) - # TODO: Enabled when duplciate logging issue is solved + # TODO: Enabled when duplicate logging issue is solved # @patch( # "azure.monitor.opentelemetry.autoinstrumentation._diagnostic_logging._EXPORTER_DIAGNOSTICS_ENABLED", # False, diff --git a/azure-monitor-opentelemetry/tests/test_constants.py b/azure-monitor-opentelemetry/tests/test_constants.py index c81aff52..54f17340 100644 --- a/azure-monitor-opentelemetry/tests/test_constants.py +++ b/azure-monitor-opentelemetry/tests/test_constants.py @@ -47,7 +47,7 @@ def test_ikey_defaults(self): reload(_constants) self.assertEqual(_constants._CUSTOMER_IKEY, "unknown") - # TODO: Enabled when duplciate logging issue is solved + # TODO: Enabled when duplicate logging issue is solved # @patch.dict( # "os.environ", # {"AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS": "True"}, From 7e7a97b0ffd77e6d39c4ef34a8525f91a99d4596 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 7 Jun 2023 17:11:37 -0700 Subject: [PATCH 2/4] spelling --- CHANGELOG.md | 2 ++ .../azure/monitor/opentelemetry/_configure.py | 2 +- .../azure/monitor/opentelemetry/_constants.py | 6 +++--- .../monitor/opentelemetry/autoinstrumentation/_distro.py | 2 +- azure-monitor-opentelemetry/samples/tracing/manual.py | 2 +- .../tests/autoinstrumentation/test_distro.py | 2 +- azure-monitor-opentelemetry/tests/test_constants.py | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13ffca69..8455cc87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Update samples ([#281](https://github.com/microsoft/ApplicationInsights-Python/pull/281)) +- Fixed spelling + ([#291](https://github.com/microsoft/ApplicationInsights-Python/pull/291)) ## [1.0.0b12](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b12) - 2023-05-05 diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py index 47873cbc..0073b427 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py @@ -145,7 +145,7 @@ def _setup_instrumentations(): instrumentor().instrument(skip_dep_check=True) except Exception as ex: _logger.warning( - "Exception occured when instrumenting: %s.", + "Exception occurred when instrumenting: %s.", lib_name, exc_info=ex, ) diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py index 7fe1b0dd..fd6518d4 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py @@ -30,7 +30,7 @@ _IS_ON_APP_SERVICE = "WEBSITE_SITE_NAME" in environ # TODO: Add environment variable to enabled diagnostics off of App Service _IS_DIAGNOSTICS_ENABLED = _IS_ON_APP_SERVICE -# TODO: Enabled when duplciate logging issue is solved +# TODO: Enabled when duplicate logging issue is solved # _EXPORTER_DIAGNOSTICS_ENABLED_ENV_VAR = ( # "AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS" # ) @@ -63,7 +63,7 @@ def _env_var_or_default(var_name, default_val=""): return default_val -# TODO: Enabled when duplciate logging issue is solved +# TODO: Enabled when duplicate logging issue is solved # def _is_exporter_diagnostics_enabled(): # return ( # _EXPORTER_DIAGNOSTICS_ENABLED_ENV_VAR in environ @@ -74,5 +74,5 @@ def _env_var_or_default(var_name, default_val=""): _EXTENSION_VERSION = _env_var_or_default( "ApplicationInsightsAgent_EXTENSION_VERSION", "disabled" ) -# TODO: Enabled when duplciate logging issue is solved +# TODO: Enabled when duplicate logging issue is solved # _EXPORTER_DIAGNOSTICS_ENABLED = _is_exporter_diagnostics_enabled() diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_distro.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_distro.py index 1ca3adf5..d9341050 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_distro.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_distro.py @@ -34,7 +34,7 @@ def _configure(self, **kwargs) -> None: _configure_auto_instrumentation() except Exception as ex: _logger.exception( - ("Error occured auto-instrumenting AzureMonitorDistro") + ("Error occurred auto-instrumenting AzureMonitorDistro") ) raise ex diff --git a/azure-monitor-opentelemetry/samples/tracing/manual.py b/azure-monitor-opentelemetry/samples/tracing/manual.py index 7bbf1e50..feaa15f4 100644 --- a/azure-monitor-opentelemetry/samples/tracing/manual.py +++ b/azure-monitor-opentelemetry/samples/tracing/manual.py @@ -11,7 +11,7 @@ engine = create_engine("sqlite:///:memory:") # SQLAlchemy instrumentation is not officially supported by this package -# However, you can use the OpenTelemetry instument method manually in +# However, you can use the OpenTelemetry instrument method manually in # conjunction with configure_azure_monitor SQLAlchemyInstrumentor().instrument( engine=engine, diff --git a/azure-monitor-opentelemetry/tests/autoinstrumentation/test_distro.py b/azure-monitor-opentelemetry/tests/autoinstrumentation/test_distro.py index aae4653b..874ca922 100644 --- a/azure-monitor-opentelemetry/tests/autoinstrumentation/test_distro.py +++ b/azure-monitor-opentelemetry/tests/autoinstrumentation/test_distro.py @@ -10,7 +10,7 @@ class TestDistro(TestCase): @patch( "azure.monitor.opentelemetry.autoinstrumentation._distro.AzureDiagnosticLogging.enable" ) - # TODO: Enabled when duplciate logging issue is solved + # TODO: Enabled when duplicate logging issue is solved # @patch( # "azure.monitor.opentelemetry.autoinstrumentation._diagnostic_logging._EXPORTER_DIAGNOSTICS_ENABLED", # False, diff --git a/azure-monitor-opentelemetry/tests/test_constants.py b/azure-monitor-opentelemetry/tests/test_constants.py index c81aff52..54f17340 100644 --- a/azure-monitor-opentelemetry/tests/test_constants.py +++ b/azure-monitor-opentelemetry/tests/test_constants.py @@ -47,7 +47,7 @@ def test_ikey_defaults(self): reload(_constants) self.assertEqual(_constants._CUSTOMER_IKEY, "unknown") - # TODO: Enabled when duplciate logging issue is solved + # TODO: Enabled when duplicate logging issue is solved # @patch.dict( # "os.environ", # {"AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS": "True"}, From 1d8d9f5cf3e92dd8ce4ec02232b48ae971a88ee1 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Thu, 8 Jun 2023 12:39:17 -0700 Subject: [PATCH 3/4] spelling --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8455cc87..e9b5616c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,11 +76,11 @@ ([#242](https://github.com/microsoft/ApplicationInsights-Python/pull/242)) - Update to azure-monitor-opentelemetry-exporter 1.0.0b12 ([#243](https://github.com/microsoft/ApplicationInsights-Python/pull/243)) -- Move symbols to protected, add docstring for api, pin opentelemtry-api/sdk versions +- Move symbols to protected, add docstring for api, pin opentelemetry-api/sdk versions ([#244](https://github.com/microsoft/ApplicationInsights-Python/pull/244)) - Replace service.X configurations with Resource ([#246](https://github.com/microsoft/ApplicationInsights-Python/pull/246)) -- Change namespace to `azure.monitor.opentelemtry` +- Change namespace to `azure.monitor.opentelemetry` ([#247](https://github.com/microsoft/ApplicationInsights-Python/pull/247)) - Updating documents for new namespace ([#249](https://github.com/microsoft/ApplicationInsights-Python/pull/249)) From a1a7f25e198ebe9b5f560f1a5091396e1f3a5e3e Mon Sep 17 00:00:00 2001 From: jerevoss Date: Fri, 9 Jun 2023 11:28:37 -0700 Subject: [PATCH 4/4] azure sdk lint --- CHANGELOG.md | 2 ++ .../azure/monitor/opentelemetry/_configure.py | 12 ++++++++---- .../azure/monitor/opentelemetry/_constants.py | 7 +++---- .../autoinstrumentation/_configurator.py | 5 +++-- .../opentelemetry/autoinstrumentation/_distro.py | 3 ++- .../diagnostics/_diagnostic_logging.py | 14 +++++++------- .../opentelemetry/diagnostics/_status_logger.py | 8 ++++++-- .../monitor/opentelemetry/util/configurations.py | 8 +++++--- 8 files changed, 36 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9b5616c..4279120c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py index 0073b427..e14629cf 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py @@ -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 `/Microsoft/AzureMonitor/opentelemetry-python-`. + :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 + `/Microsoft/AzureMonitor/opentelemetry-python-`. :rtype: None """ @@ -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, diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py index fd6518d4..77cc08e1 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py @@ -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=""): diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_configurator.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_configurator.py index d7da88d3..9440a21c 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_configurator.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_configurator.py @@ -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 diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_distro.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_distro.py index d9341050..7977e3d0 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_distro.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_distro.py @@ -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 diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/diagnostics/_diagnostic_logging.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/diagnostics/_diagnostic_logging.py index 6803c9c4..68d79f82 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/diagnostics/_diagnostic_logging.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/diagnostics/_diagnostic_logging.py @@ -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", ' @@ -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) diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/diagnostics/_status_logger.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/diagnostics/_status_logger.py index 7cc42d64..12da27af 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/diagnostics/_status_logger.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/diagnostics/_status_logger.py @@ -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", @@ -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( diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py index 270b633a..7da4e90b 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py @@ -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 @@ -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