Skip to content

Commit e0b5b2f

Browse files
committed
changelog
1 parent d7d29d0 commit e0b5b2f

File tree

6 files changed

+54
-24
lines changed

6 files changed

+54
-24
lines changed

azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/__init__.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
# --------------------------------------------------------------------------
66
from logging import NOTSET, getLogger
77

8+
from azure.monitor.opentelemetry.distro._constants import (
9+
ConnectionStringConstants,
10+
)
811
from azure.monitor.opentelemetry.distro.util import get_configurations
9-
from azure.monitor.opentelemetry.distro._constants import ConnectionStringConstants
1012
from azure.monitor.opentelemetry.exporter import (
1113
ApplicationInsightsSampler,
1214
AzureMonitorLogExporter,
@@ -37,7 +39,9 @@ def configure_azure_monitor(**kwargs):
3739
conn_str = configurations.get("connection_string", "")
3840
if conn_str is None:
3941
# TODO: JEREVOSS: We could levae this for the exporter to determine.
40-
configurations["connection_string"] = ConnectionStringConstants.get_conn_str()
42+
configurations[
43+
"connection_string"
44+
] = ConnectionStringConstants.get_conn_str()
4145
else:
4246
ConnectionStringConstants.set_conn_str(conn_str)
4347
service_name = configurations.get("service_name", "")

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,19 @@ def _env_var_or_default(var_name, default_val=""):
6363
class ConnectionStringConstants:
6464
_conn_str_parser = None
6565

66-
6766
def set_conn_str_from_env_var():
6867
ConnectionStringConstants._conn_str_parser = ConnectionStringParser()
6968

70-
7169
def set_conn_str(conn_str):
72-
ConnectionStringConstants._conn_str_parser = ConnectionStringParser(conn_str)
73-
70+
ConnectionStringConstants._conn_str_parser = ConnectionStringParser(
71+
conn_str
72+
)
7473

7574
def get_conn_str():
7675
if ConnectionStringConstants._conn_str_parser is None:
7776
return None
7877
return ConnectionStringConstants._conn_str_parser._conn_str
7978

80-
8179
def get_customer_ikey():
8280
if ConnectionStringConstants._conn_str_parser is None:
8381
return None

azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_diagnostics/_diagnostic_logging.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from os.path import exists, join
1111

1212
from azure.monitor.opentelemetry.distro._constants import (
13-
ConnectionStringConstants,
1413
_EXTENSION_VERSION,
1514
_IS_DIAGNOSTICS_ENABLED,
15+
ConnectionStringConstants,
1616
_env_var_or_default,
1717
_get_log_path,
1818
)
@@ -39,13 +39,19 @@ def _initialize():
3939
with AzureDiagnosticLogging._lock:
4040
if not AzureDiagnosticLogging._initialized:
4141
if _IS_DIAGNOSTICS_ENABLED and _DIAGNOSTIC_LOG_PATH:
42-
customer_ikey = ConnectionStringConstants.get_customer_ikey()
42+
customer_ikey = (
43+
ConnectionStringConstants.get_customer_ikey()
44+
)
4345
if customer_ikey is None:
4446
try:
4547
ConnectionStringConstants.set_conn_str_from_env_var()
46-
customer_ikey = ConnectionStringConstants.get_customer_ikey()
48+
customer_ikey = (
49+
ConnectionStringConstants.get_customer_ikey()
50+
)
4751
except ValueError as e:
48-
_logger.error("Failed to parse Instrumentation Key: %s" % e)
52+
_logger.error(
53+
"Failed to parse Instrumentation Key: %s" % e
54+
)
4955
customer_ikey = "unknown"
5056
format = (
5157
"{"

azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_diagnostics/_status_logger.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
# license information.
55
# --------------------------------------------------------------------------
66

7+
import logging
78
from json import dumps
89
from os import getpid, makedirs
910
from os.path import exists, join
1011
from platform import node
1112

1213
from azure.monitor.opentelemetry.distro._constants import (
13-
ConnectionStringConstants,
1414
_EXTENSION_VERSION,
1515
_IS_DIAGNOSTICS_ENABLED,
16+
ConnectionStringConstants,
1617
_get_log_path,
1718
)
1819
from azure.monitor.opentelemetry.distro._version import VERSION
19-
import logging
2020

2121
_MACHINE_NAME = node()
2222
_STATUS_LOG_PATH = _get_log_path(status_log_path=True)

azure-monitor-opentelemetry-distro/tests/diagnostics/test_status_logger.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ def test_log_status_success(self, mock_get_customer_ikey, mock_getpid):
129129
"azure.monitor.opentelemetry.distro._diagnostics._status_logger.getpid",
130130
return_value=TEST_PID,
131131
)
132-
def test_log_status_failed_initialization(self, mock_get_customer_ikey, mock_getpid):
132+
def test_log_status_failed_initialization(
133+
self, mock_get_customer_ikey, mock_getpid
134+
):
133135
AzureStatusLogger.log_status(True, MESSAGE1)
134136
AzureStatusLogger.log_status(False, MESSAGE2)
135137
check_file_for_messages(False, MESSAGE2)
@@ -195,7 +197,9 @@ def test_log_status_no_reason(self, mock_get_customer_ikey, mock_getpid):
195197
"azure.monitor.opentelemetry.distro._diagnostics._status_logger.getpid",
196198
return_value=TEST_PID,
197199
)
198-
def test_disabled_log_status_success(self, mock_get_customer_ikey, mock_getpid):
200+
def test_disabled_log_status_success(
201+
self, mock_get_customer_ikey, mock_getpid
202+
):
199203
AzureStatusLogger.log_status(False, MESSAGE1)
200204
AzureStatusLogger.log_status(True, MESSAGE2)
201205
check_file_is_empty()
@@ -228,7 +232,9 @@ def test_disabled_log_status_success(self, mock_get_customer_ikey, mock_getpid):
228232
"azure.monitor.opentelemetry.distro._diagnostics._status_logger.getpid",
229233
return_value=TEST_PID,
230234
)
231-
def test_disabled_log_status_failed_initialization(self, mock_get_customer_ikey, mock_getpid):
235+
def test_disabled_log_status_failed_initialization(
236+
self, mock_get_customer_ikey, mock_getpid
237+
):
232238
AzureStatusLogger.log_status(True, MESSAGE1)
233239
AzureStatusLogger.log_status(False, MESSAGE2)
234240
check_file_is_empty()
@@ -261,7 +267,9 @@ def test_disabled_log_status_failed_initialization(self, mock_get_customer_ikey,
261267
"azure.monitor.opentelemetry.distro._diagnostics._status_logger.getpid",
262268
return_value=TEST_PID,
263269
)
264-
def test_disabled_log_status_no_reason(self, mock_get_customer_ikey, mock_getpid):
270+
def test_disabled_log_status_no_reason(
271+
self, mock_get_customer_ikey, mock_getpid
272+
):
265273
AzureStatusLogger.log_status(False, MESSAGE1)
266274
AzureStatusLogger.log_status(True)
267275
check_file_is_empty()

azure-monitor-opentelemetry-distro/tests/test_constants.py

+21-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from importlib import reload
88
from os import environ
99
from unittest import TestCase
10-
from unittest.mock import patch, Mock
10+
from unittest.mock import Mock, patch
1111

1212
from azure.monitor.opentelemetry.distro import _constants
1313

@@ -46,11 +46,18 @@ def test_set_conn_str_from_env_var(self, mock_csp):
4646
mock_csp_init = Mock()
4747
mock_csp.return_value = mock_csp_init
4848
mock_csp_init.instrumentation_key = TEST_IKEY
49-
self.assertIsNone(_constants.ConnectionStringConstants._conn_str_parser)
49+
self.assertIsNone(
50+
_constants.ConnectionStringConstants._conn_str_parser
51+
)
5052
_constants.ConnectionStringConstants.set_conn_str_from_env_var()
5153
mock_csp.assert_called_once()
52-
self.assertEqual(_constants.ConnectionStringConstants._conn_str_parser, mock_csp_init)
53-
self.assertEqual(_constants.ConnectionStringConstants.get_customer_ikey(), TEST_IKEY)
54+
self.assertEqual(
55+
_constants.ConnectionStringConstants._conn_str_parser,
56+
mock_csp_init,
57+
)
58+
self.assertEqual(
59+
_constants.ConnectionStringConstants.get_customer_ikey(), TEST_IKEY
60+
)
5461

5562
@patch(
5663
"azure.monitor.opentelemetry.exporter._connection_string_parser.ConnectionStringParser"
@@ -61,16 +68,23 @@ def test_set_conn_str(self, mock_csp):
6168
mock_csp.return_value = mock_csp_init
6269
mock_csp_init.instrumentation_key = TEST_IKEY
6370
_constants.ConnectionStringConstants.set_conn_str(TEST_CONN_STR)
64-
self.assertEqual(_constants.ConnectionStringConstants._conn_str_parser, mock_csp_init)
65-
self.assertEqual(_constants.ConnectionStringConstants.get_customer_ikey(), TEST_IKEY)
71+
self.assertEqual(
72+
_constants.ConnectionStringConstants._conn_str_parser,
73+
mock_csp_init,
74+
)
75+
self.assertEqual(
76+
_constants.ConnectionStringConstants.get_customer_ikey(), TEST_IKEY
77+
)
6678

6779
@patch(
6880
"azure.monitor.opentelemetry.exporter._connection_string_parser.ConnectionStringParser"
6981
)
7082
def test_ikey_defaults(self, mock_csp):
7183
clear_env_var("APPLICATIONINSIGHTS_CONNECTION_STRING")
7284
reload(_constants)
73-
self.assertIsNone(_constants.ConnectionStringConstants.get_customer_ikey())
85+
self.assertIsNone(
86+
_constants.ConnectionStringConstants.get_customer_ikey()
87+
)
7488

7589
# TODO: Enabled when duplciate logging issue is solved
7690
# @patch.dict(

0 commit comments

Comments
 (0)