Skip to content

Commit 7bca8a1

Browse files
authored
Merge pull request #292 from jeremydvoss/azure-sdk-lint
Azure sdk lint
2 parents d4454f1 + a1a7f25 commit 7bca8a1

File tree

8 files changed

+36
-23
lines changed

8 files changed

+36
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
([#281](https://github.com/microsoft/ApplicationInsights-Python/pull/281))
77
- Fixed spelling
88
([#291](https://github.com/microsoft/ApplicationInsights-Python/pull/291))
9+
- Fixing formatting issues for azure sdk
10+
([#292](https://github.com/microsoft/ApplicationInsights-Python/pull/292))
911

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

azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ def configure_azure_monitor(**kwargs) -> None:
5656
end user to configure OpenTelemetry and Azure monitor components. The
5757
configuration can be done via arguments passed to this function.
5858
:keyword str connection_string: Connection string for your Application Insights resource.
59-
:keyword ManagedIdentityCredential/ClientSecretCredential credential: Token credential, such as ManagedIdentityCredential or ClientSecretCredential, used for Azure Active Directory (AAD) authentication. Defaults to None.
60-
:keyword bool disable_offline_storage: Boolean value to determine whether to disable storing failed telemetry records for retry. Defaults to `False`.
61-
:keyword str storage_directory: Storage directory in which to store retry files. Defaults to `<tempfile.gettempdir()>/Microsoft/AzureMonitor/opentelemetry-python-<your-instrumentation-key>`.
59+
:keyword ManagedIdentityCredential/ClientSecretCredential credential: Token credential, such as
60+
ManagedIdentityCredential or ClientSecretCredential, used for Azure Active Directory (AAD) authentication. Defaults
61+
to None.
62+
:keyword bool disable_offline_storage: Boolean value to determine whether to disable storing failed telemetry
63+
records for retry. Defaults to `False`.
64+
:keyword str storage_directory: Storage directory in which to store retry files. Defaults to
65+
`<tempfile.gettempdir()>/Microsoft/AzureMonitor/opentelemetry-python-<your-instrumentation-key>`.
6266
:rtype: None
6367
"""
6468

@@ -143,7 +147,7 @@ def _setup_instrumentations():
143147
instrumentor: BaseInstrumentor = entry_point.load()
144148
# tell instrumentation to not run dep checks again as we already did it above
145149
instrumentor().instrument(skip_dep_check=True)
146-
except Exception as ex:
150+
except Exception as ex: # pylint: disable=broad-except
147151
_logger.warning(
148152
"Exception occurred when instrumenting: %s.",
149153
lib_name,

azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,20 @@
3939
try:
4040
_CUSTOMER_IKEY = ConnectionStringParser().instrumentation_key
4141
except ValueError as e:
42-
logger.error("Failed to parse Instrumentation Key: %s" % e)
42+
logger.error("Failed to parse Instrumentation Key: %s", e)
4343

4444

4545
def _get_log_path(status_log_path=False):
4646
system = platform.system()
4747
if system == "Linux":
4848
return _LOG_PATH_LINUX
49-
elif system == "Windows":
49+
if system == "Windows":
5050
log_path = str(Path.home()) + _LOG_PATH_WINDOWS
5151
if status_log_path:
5252
return log_path + "\\status"
5353
else:
5454
return log_path
55-
else:
56-
return None
55+
return None
5756

5857

5958
def _env_var_or_default(var_name, default_val=""):

azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_configurator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ def _configure(self, **kwargs):
2222
super()._configure(**kwargs)
2323
except ValueError as e:
2424
_logger.error(
25-
f"Azure Monitor Configurator failed during configuration due to a ValueError: {e}"
25+
"Azure Monitor Configurator failed during configuration due to a ValueError: %s",
26+
e,
2627
)
2728
raise e
2829
except Exception as e:
2930
_logger.error(
30-
f"Azure Monitor Configurator failed during configuration: {e}"
31+
"Azure Monitor Configurator failed during configuration: %s", e
3132
)
3233
raise e

azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_distro.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def _configure_auto_instrumentation() -> None:
7070
AzureStatusLogger.log_status(False, reason=exc)
7171
_logger.error(
7272
"Azure Monitor OpenTelemetry Distro failed during "
73-
+ f"configuration: {exc}"
73+
+ "configuration: %s",
74+
exc,
7475
)
7576
raise exc

azure-monitor-opentelemetry/azure/monitor/opentelemetry/diagnostics/_diagnostic_logging.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ class AzureDiagnosticLogging:
3535
_lock = threading.Lock()
3636
_f_handler = None
3737

38-
def _initialize():
38+
@classmethod
39+
def _initialize(cls):
3940
with AzureDiagnosticLogging._lock:
4041
if not AzureDiagnosticLogging._initialized:
4142
if _IS_DIAGNOSTICS_ENABLED and _DIAGNOSTIC_LOG_PATH:
42-
format = (
43+
log_format = (
4344
"{"
4445
+ '"time":"%(asctime)s.%(msecs)03d", '
4546
+ '"level":"%(levelname)s", '
@@ -64,16 +65,15 @@ def _initialize():
6465
)
6566
)
6667
formatter = logging.Formatter(
67-
fmt=format, datefmt="%Y-%m-%dT%H:%M:%S"
68+
fmt=log_format, datefmt="%Y-%m-%dT%H:%M:%S"
6869
)
6970
AzureDiagnosticLogging._f_handler.setFormatter(formatter)
7071
AzureDiagnosticLogging._initialized = True
7172
_logger.info("Initialized Azure Diagnostic Logger.")
7273

73-
def enable(logger: logging.Logger):
74+
@classmethod
75+
def enable(cls, logger: logging.Logger):
7476
AzureDiagnosticLogging._initialize()
7577
if AzureDiagnosticLogging._initialized:
7678
logger.addHandler(AzureDiagnosticLogging._f_handler)
77-
_logger.info(
78-
"Added Azure diagnostics logging to %s." % logger.name
79-
)
79+
_logger.info("Added Azure diagnostics logging to %s.", logger.name)

azure-monitor-opentelemetry/azure/monitor/opentelemetry/diagnostics/_status_logger.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222

2323

2424
class AzureStatusLogger:
25-
def _get_status_json(agent_initialized_successfully, pid, reason=None):
25+
@classmethod
26+
def _get_status_json(
27+
cls, agent_initialized_successfully, pid, reason=None
28+
):
2629
status_json = {
2730
"AgentInitializedSuccessfully": agent_initialized_successfully,
2831
"AppType": "python",
@@ -36,7 +39,8 @@ def _get_status_json(agent_initialized_successfully, pid, reason=None):
3639
status_json["Reason"] = reason
3740
return status_json
3841

39-
def log_status(agent_initialized_successfully, reason=None):
42+
@classmethod
43+
def log_status(cls, agent_initialized_successfully, reason=None):
4044
if _IS_DIAGNOSTICS_ENABLED and _STATUS_LOG_PATH:
4145
pid = getpid()
4246
status_json = AzureStatusLogger._get_status_json(

azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ def _default_logging_export_interval_ms(configurations):
8888
default = int(environ[LOGGING_EXPORT_INTERVAL_MS_ENV_VAR])
8989
except ValueError as e:
9090
_logger.error(
91-
_INVALID_INT_MESSAGE
92-
% (LOGGING_EXPORT_INTERVAL_MS_ENV_VAR, default, e)
91+
_INVALID_INT_MESSAGE,
92+
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR,
93+
default,
94+
e,
9395
)
9496
configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] = default
9597

@@ -102,6 +104,6 @@ def _default_sampling_ratio(configurations):
102104
default = float(environ[SAMPLING_RATIO_ENV_VAR])
103105
except ValueError as e:
104106
_logger.error(
105-
_INVALID_FLOAT_MESSAGE % (SAMPLING_RATIO_ENV_VAR, default, e)
107+
_INVALID_FLOAT_MESSAGE, SAMPLING_RATIO_ENV_VAR, default, e
106108
)
107109
configurations[SAMPLING_RATIO_ARG] = default

0 commit comments

Comments
 (0)