Skip to content

Commit 1e84508

Browse files
authored
Merge branch 'main' into vendor-instrumentations
2 parents d7ceb65 + 7bca8a1 commit 1e84508

File tree

11 files changed

+48
-33
lines changed

11 files changed

+48
-33
lines changed

CHANGELOG.md

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

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

@@ -76,11 +80,11 @@
7680
([#242](https://github.com/microsoft/ApplicationInsights-Python/pull/242))
7781
- Update to azure-monitor-opentelemetry-exporter 1.0.0b12
7882
([#243](https://github.com/microsoft/ApplicationInsights-Python/pull/243))
79-
- Move symbols to protected, add docstring for api, pin opentelemtry-api/sdk versions
83+
- Move symbols to protected, add docstring for api, pin opentelemetry-api/sdk versions
8084
([#244](https://github.com/microsoft/ApplicationInsights-Python/pull/244))
8185
- Replace service.X configurations with Resource
8286
([#246](https://github.com/microsoft/ApplicationInsights-Python/pull/246))
83-
- Change namespace to `azure.monitor.opentelemtry`
87+
- Change namespace to `azure.monitor.opentelemetry`
8488
([#247](https://github.com/microsoft/ApplicationInsights-Python/pull/247))
8589
- Updating documents for new namespace
8690
([#249](https://github.com/microsoft/ApplicationInsights-Python/pull/249))

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

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

@@ -150,9 +154,9 @@ def _setup_instrumentations():
150154
instrumentor: BaseInstrumentor = entry_point.load()
151155
# tell instrumentation to not run dep checks again as we already did it above
152156
instrumentor().instrument(skip_dep_check=True)
153-
except Exception as ex:
157+
except Exception as ex: # pylint: disable=broad-except
154158
_logger.warning(
155-
"Exception occured when instrumenting: %s.",
159+
"Exception occurred when instrumenting: %s.",
156160
lib_name,
157161
exc_info=ex,
158162
)

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
_IS_ON_APP_SERVICE = "WEBSITE_SITE_NAME" in environ
3131
# TODO: Add environment variable to enabled diagnostics off of App Service
3232
_IS_DIAGNOSTICS_ENABLED = _IS_ON_APP_SERVICE
33-
# TODO: Enabled when duplciate logging issue is solved
33+
# TODO: Enabled when duplicate logging issue is solved
3434
# _EXPORTER_DIAGNOSTICS_ENABLED_ENV_VAR = (
3535
# "AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS"
3636
# )
@@ -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=""):
@@ -63,7 +62,7 @@ def _env_var_or_default(var_name, default_val=""):
6362
return default_val
6463

6564

66-
# TODO: Enabled when duplciate logging issue is solved
65+
# TODO: Enabled when duplicate logging issue is solved
6766
# def _is_exporter_diagnostics_enabled():
6867
# return (
6968
# _EXPORTER_DIAGNOSTICS_ENABLED_ENV_VAR in environ
@@ -74,5 +73,5 @@ def _env_var_or_default(var_name, default_val=""):
7473
_EXTENSION_VERSION = _env_var_or_default(
7574
"ApplicationInsightsAgent_EXTENSION_VERSION", "disabled"
7675
)
77-
# TODO: Enabled when duplciate logging issue is solved
76+
# TODO: Enabled when duplicate logging issue is solved
7877
# _EXPORTER_DIAGNOSTICS_ENABLED = _is_exporter_diagnostics_enabled()

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _configure(self, **kwargs) -> None:
3636
_configure_auto_instrumentation()
3737
except Exception as ex:
3838
_logger.exception(
39-
("Error occured auto-instrumenting AzureMonitorDistro")
39+
("Error occurred auto-instrumenting AzureMonitorDistro")
4040
)
4141
raise ex
4242

@@ -72,6 +72,7 @@ def _configure_auto_instrumentation() -> None:
7272
AzureStatusLogger.log_status(False, reason=exc)
7373
_logger.error(
7474
"Azure Monitor OpenTelemetry Distro failed during "
75-
+ f"configuration: {exc}"
75+
+ "configuration: %s",
76+
exc,
7677
)
7778
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

azure-monitor-opentelemetry/samples/tracing/manual.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
engine = create_engine("sqlite:///:memory:")
1313
# SQLAlchemy instrumentation is not officially supported by this package
14-
# However, you can use the OpenTelemetry instument method manually in
14+
# However, you can use the OpenTelemetry instrument method manually in
1515
# conjunction with configure_azure_monitor
1616
SQLAlchemyInstrumentor().instrument(
1717
engine=engine,

azure-monitor-opentelemetry/tests/autoinstrumentation/test_distro.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class TestDistro(TestCase):
1010
@patch(
1111
"azure.monitor.opentelemetry.autoinstrumentation._distro.AzureDiagnosticLogging.enable"
1212
)
13-
# TODO: Enabled when duplciate logging issue is solved
13+
# TODO: Enabled when duplicate logging issue is solved
1414
# @patch(
1515
# "azure.monitor.opentelemetry.autoinstrumentation._diagnostic_logging._EXPORTER_DIAGNOSTICS_ENABLED",
1616
# False,

0 commit comments

Comments
 (0)