Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
"urllib",
"urllib3",
_AZURE_SDK_OPENTELEMETRY_NAME,
"cassandra",
Comment thread
jeremydvoss marked this conversation as resolved.
"tortoiseorm",
]

_INSTRUMENTATIONS_BIT_MAP = {_INSTRUMENTATIONS_LIST[i]: _BASE**i for i in range(len(_INSTRUMENTATIONS_LIST))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __init__(self, **kwargs: Any) -> None:
self._storage_directory = kwargs.get('storage_directory', default_storage_directory) # Storage path in which to store retry files.
self._storage_retention_period = kwargs.get('storage_retention_period', 48 * 60 * 60) # Retention period in seconds (default 48 hrs)
self._timeout = kwargs.get('timeout', 10.0) # networking timeout in seconds
self._distro_version = kwargs.get('distro_version', '') # If set, indicates the exporter is instantiated via Azure monitor OpenTelemetry distro. Versions corresponds to distro version.
Comment thread
lzchen marked this conversation as resolved.
Outdated

config = AzureMonitorClientConfiguration(self._endpoint, **kwargs)
policies = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def collect_statsbeat_metrics(exporter) -> None:
exporter._disable_offline_storage,
long_interval_threshold,
exporter._credential is not None,
exporter._distro_version,
)
# Export some initial stats on program start
mp.force_flush()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class _StatsbeatFeature:
DISK_RETRY = 1
AAD = 2
CUSTOM_EVENTS_EXTENSION = 4
DISTRO = 8


class _AttachTypes:
Expand Down Expand Up @@ -97,13 +98,16 @@ def __init__(
disable_offline_storage: bool,
long_interval_threshold: int,
has_credential: bool,
distro_version: str = "",
) -> None:
self._ikey = instrumentation_key
self._feature = _StatsbeatFeature.NONE
if not disable_offline_storage:
self._feature |= _StatsbeatFeature.DISK_RETRY
if has_credential:
self._feature |= _StatsbeatFeature.AAD
if distro_version:
self._feature |= _StatsbeatFeature.DISTRO
Comment thread
lzchen marked this conversation as resolved.
if get_statsbeat_custom_events_feature_set():
self._feature |= _StatsbeatFeature.CUSTOM_EVENTS_EXTENSION
self._ikey = instrumentation_key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def test_collect_statsbeat_metrics_aad(
exporter._instrumentation_key = TEST_IKEY
exporter._disable_offline_storage = False
exporter._credential = TEST_CREDENTIAL
exporter._distro_version = ""
_statsbeat.collect_statsbeat_metrics(exporter)
mock_statsbeat_metrics.assert_called_once_with(
mock.ANY,
Expand All @@ -184,6 +185,7 @@ def test_collect_statsbeat_metrics_aad(
False,
_DEFAULT_STATS_LONG_EXPORT_INTERVAL / _DEFAULT_STATS_SHORT_EXPORT_INTERVAL,
True,
"",
)


Expand All @@ -207,6 +209,7 @@ def test_collect_statsbeat_metrics_no_aad(
exporter._instrumentation_key = TEST_IKEY
exporter._disable_offline_storage = False
exporter._credential = TEST_CREDENTIAL
exporter._distro_version = ""
_statsbeat.collect_statsbeat_metrics(exporter)
mock_statsbeat_metrics.assert_called_once_with(
mock.ANY,
Expand All @@ -215,6 +218,39 @@ def test_collect_statsbeat_metrics_no_aad(
False,
_DEFAULT_STATS_LONG_EXPORT_INTERVAL / _DEFAULT_STATS_SHORT_EXPORT_INTERVAL,
False,
"",
)

@mock.patch('azure.monitor.opentelemetry.exporter.statsbeat._statsbeat._StatsbeatMetrics')
@mock.patch.dict(
"os.environ",
{
"APPLICATION_INSIGHTS_STATS_SHORT_EXPORT_INTERVAL": "",
"APPLICATION_INSIGHTS_STATS_LONG_EXPORT_INTERVAL": "",
},
)
def test_collect_statsbeat_metrics_distro_version(
self,
mock_statsbeat_metrics,
):
exporter = mock.Mock()
TEST_ENDPOINT = "test endpoint"
TEST_IKEY = "test ikey"
TEST_CREDENTIAL = None
exporter._endpoint = TEST_ENDPOINT
exporter._instrumentation_key = TEST_IKEY
exporter._disable_offline_storage = False
exporter._credential = TEST_CREDENTIAL
exporter._distro_version = "1.0.0"
_statsbeat.collect_statsbeat_metrics(exporter)
mock_statsbeat_metrics.assert_called_once_with(
mock.ANY,
TEST_IKEY,
TEST_ENDPOINT,
False,
_DEFAULT_STATS_LONG_EXPORT_INTERVAL / _DEFAULT_STATS_SHORT_EXPORT_INTERVAL,
False,
"1.0.0",
)

def test_shutdown_statsbeat_metrics(self):
Expand Down Expand Up @@ -634,7 +670,7 @@ def test_get_feature_metric_does_not_meet_threshold(self):
self.assertEqual(metric._long_interval_count_map[_FEATURE_METRIC_NAME[0]], 1)

# pylint: disable=protected-access
def test_get_feature_metric(self):
def test_get_feature_metric_storage(self):
mp = MeterProvider()
ikey = "1aa11111-bbbb-1ccc-8ddd-eeeeffff3334"
endpoint = "https://westus-1.in.applicationinsights.azure.com/"
Expand All @@ -648,7 +684,7 @@ def test_get_feature_metric(self):
)
attributes = dict(_StatsbeatMetrics._COMMON_ATTRIBUTES)
attributes.update(_StatsbeatMetrics._FEATURE_ATTRIBUTES)
self.assertEqual(attributes["feature"], 1)
self.assertEqual(attributes["feature"], _StatsbeatFeature.DISK_RETRY)
self.assertEqual(attributes["type"], _FEATURE_TYPES.FEATURE)
observations = metric._get_feature_metric(options=None)
for obs in observations:
Expand Down Expand Up @@ -740,6 +776,25 @@ def test_get_feature_metric_custom_events_runtime(self):
self.assertEqual(obs.value, 1)
self.assertEqual(obs.attributes, attributes)

# pylint: disable=protected-access
def test_get_feature_metric_distro(self):
mp = MeterProvider()
ikey = "1aa11111-bbbb-1ccc-8ddd-eeeeffff3334"
endpoint = "https://westus-1.in.applicationinsights.azure.com/"
metric = _StatsbeatMetrics(
mp,
ikey,
endpoint,
True,
0,
False,
"1.0.0"
)
self.assertEqual(_StatsbeatMetrics._FEATURE_ATTRIBUTES["feature"], _StatsbeatFeature.DISTRO)
observations = metric._get_feature_metric(options=None)
self.assertEqual(len(observations), 1)
self.assertEqual(_StatsbeatMetrics._FEATURE_ATTRIBUTES["feature"], _StatsbeatFeature.DISTRO)

# pylint: disable=protected-access
def test_get_feature_metric_instrumentation(self):
mp = MeterProvider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_constructor(self):
api_version="2021-02-10_Preview",
connection_string="InstrumentationKey=4321abcd-5678-4efa-8abc-1234567890ab;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com/",
disable_offline_storage=False,
distro_version="1.0.0",
storage_maintenance_period=30,
storage_max_size=1000,
storage_min_retry_interval=100,
Expand All @@ -115,6 +116,7 @@ def test_constructor(self):
base._endpoint,
"https://westus-0.in.applicationinsights.azure.com/",
)
self.assertEqual(base._distro_version, "1.0.0")
self.assertIsNotNone(base.storage)
self.assertEqual(base.storage._max_size, 1000)
self.assertEqual(base.storage._retention_period, 2000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DISABLE_LOGGING_ARG = "disable_logging"
DISABLE_METRICS_ARG = "disable_metrics"
DISABLE_TRACING_ARG = "disable_tracing"
DISTRO_VERSION = "distro_version"
Comment thread
lzchen marked this conversation as resolved.
Outdated
LOGGER_NAME_ARG = "logger_name"
INSTRUMENTATION_OPTIONS_ARG = "instrumentation_options"
RESOURCE_ARG = "resource"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
DISABLE_LOGGING_ARG,
DISABLE_METRICS_ARG,
DISABLE_TRACING_ARG,
DISTRO_VERSION,
INSTRUMENTATION_OPTIONS_ARG,
LOGGER_NAME_ARG,
RESOURCE_ARG,
SAMPLING_RATIO_ARG,
)
from azure.monitor.opentelemetry._types import ConfigurationValue
from azure.monitor.opentelemetry._version import VERSION


_INVALID_FLOAT_MESSAGE = "Value of %s must be a float. Defaulting to %s: %s"
Expand All @@ -55,6 +57,7 @@ def _get_configurations(**kwargs) -> Dict[str, ConfigurationValue]:

for key, val in kwargs.items():
configurations[key] = val
configurations[DISTRO_VERSION] = VERSION

_default_disable_logging(configurations)
_default_disable_metrics(configurations)
Expand Down