From 617c8450d21617dec8ef3ddcfac0fdb299353cdf Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 22 Mar 2023 14:42:29 -0700 Subject: [PATCH 01/19] Enable configuration via env vars, defaulting, and validation logic --- CHANGELOG.md | 2 + .../azure/monitor/opentelemetry/_configure.py | 47 +++-- .../azure/monitor/opentelemetry/_constants.py | 53 +++++ .../opentelemetry/util/configurations.py | 186 +++++++++++++++++- .../tests/configuration/test_configure.py | 18 +- .../tests/configuration/test_util.py | 127 ++++++++++-- 6 files changed, 396 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b40782b1..959aacab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,8 @@ ([#247](https://github.com/microsoft/ApplicationInsights-Python/pull/247)) - Updating documents for new namespace ([#249](https://github.com/microsoft/ApplicationInsights-Python/pull/249)) +- Configuration via env vars and argument validation. + ([#262](https://github.com/microsoft/ApplicationInsights-Python/pull/262)) ## [1.0.0b8](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b8) - 2022-09-26 diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py index dc4c92ec..211b4fca 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py @@ -3,9 +3,24 @@ # Licensed under the MIT License. See License in the project root for # license information. # -------------------------------------------------------------------------- -from logging import NOTSET, getLogger +from logging import getLogger from typing import Any, Dict +from azure.monitor.opentelemetry._constants import ( + DISABLE_LOGGING_ARG, + DISABLE_METRICS_ARG, + DISABLE_TRACING_ARG, + EXCLUDE_INSTRUMENTATIONS_ARG, + INSTRUMENTATION_CONFIG_ARG, + LOGGER_NAME_ARG, + LOGGING_EXPORT_INTERVAL_MS_ARG, + LOGGING_LEVEL_ARG, + METRIC_READERS_ARG, + RESOURCE_ARG, + SAMPLING_RATIO_ARG, + TRACING_EXPORT_INTERVAL_MS_ARG, + VIEWS_ARG, +) from azure.monitor.opentelemetry._types import ConfigurationValue from azure.monitor.opentelemetry.exporter import ( ApplicationInsightsSampler, @@ -53,7 +68,7 @@ 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 Sequence[str] connection_string: Specifies the libraries with instrumentations to be enabled. + :keyword Sequence[str] exclude_instrumentations: Specifies instrumentations you do not want to enable. :keyword Resource resource: Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. :keyword bool disable_logging: If set to `True`, disables collection and export of logging telemetry. Defaults to `False`. :keyword bool disable_metrics: If set to `True`, disables collection and export of metric telemetry. Defaults to `False`. @@ -75,9 +90,9 @@ def configure_azure_monitor(**kwargs) -> None: configurations = _get_configurations(**kwargs) - disable_tracing = configurations.get("disable_tracing", False) - disable_logging = configurations.get("disable_logging", False) - disable_metrics = configurations.get("disable_metrics", False) + disable_tracing = configurations.get(DISABLE_TRACING_ARG) + disable_logging = configurations.get(DISABLE_LOGGING_ARG) + disable_metrics = configurations.get(DISABLE_METRICS_ARG) resource = None if not disable_logging or not disable_tracing or not disable_metrics: @@ -102,15 +117,15 @@ def configure_azure_monitor(**kwargs) -> None: def _get_resource(configurations: Dict[str, ConfigurationValue]) -> Resource: - return configurations.get("resource", Resource.create()) + return configurations.get(RESOURCE_ARG, Resource.create()) def _setup_tracing( resource: Resource, configurations: Dict[str, ConfigurationValue] ): - sampling_ratio = configurations.get("sampling_ratio", 1.0) + sampling_ratio = configurations.get(SAMPLING_RATIO_ARG) tracing_export_interval_ms = configurations.get( - "tracing_export_interval_ms", 5000 + TRACING_EXPORT_INTERVAL_MS_ARG ) tracer_provider = TracerProvider( sampler=ApplicationInsightsSampler(sampling_ratio=sampling_ratio), @@ -128,10 +143,10 @@ def _setup_tracing( def _setup_logging( resource: Resource, configurations: Dict[str, ConfigurationValue] ): - logger_name = configurations.get("logger_name", "") - logging_level = configurations.get("logging_level", NOTSET) + logger_name = configurations.get(LOGGER_NAME_ARG) + logging_level = configurations.get(LOGGING_LEVEL_ARG) logging_export_interval_ms = configurations.get( - "logging_export_interval_ms", 5000 + LOGGING_EXPORT_INTERVAL_MS_ARG ) logger_provider = LoggerProvider(resource=resource) set_logger_provider(logger_provider) @@ -150,8 +165,8 @@ def _setup_logging( def _setup_metrics( resource: Resource, configurations: Dict[str, ConfigurationValue] ): - views = configurations.get("views", ()) - metric_readers = configurations.get("metric_readers", []) + views = configurations.get(VIEWS_ARG) + metric_readers = configurations.get(METRIC_READERS_ARG) metric_exporter = AzureMonitorMetricExporter(**configurations) reader = PeriodicExportingMetricReader(metric_exporter) meter_provider = MeterProvider( @@ -164,9 +179,11 @@ def _setup_metrics( def _setup_instrumentations(configurations: Dict[str, ConfigurationValue]): exclude_instrumentations = configurations.get( - "exclude_instrumentations", [] + EXCLUDE_INSTRUMENTATIONS_ARG, [] + ) + instrumentation_configs = configurations.get( + INSTRUMENTATION_CONFIG_ARG, {} ) - instrumentation_configs = configurations.get("instrumentation_config", {}) # use pkg_resources for now until https://github.com/open-telemetry/opentelemetry-python/pull/3168 is merged for entry_point in iter_entry_points("opentelemetry_instrumentor"): diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py index 51c4f558..a0c20c2d 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py @@ -13,6 +13,59 @@ ConnectionStringParser, ) +# --------------------Configuration------------------------------ + +CONNECTION_STRING_ARG = "connection_string" +EXCLUDE_INSTRUMENTATIONS_ARG = "exclude_instrumentations" +RESOURCE_ARG = "resource" +DISABLE_LOGGING_ARG = "disable_logging" +DISABLE_METRICS_ARG = "disable_metrics" +DISABLE_TRACING_ARG = "disable_tracing" +# TODO: Consider Log Level to match +LOGGING_LEVEL_ARG = "logging_level" +LOGGER_NAME_ARG = "logger_name" +LOGGING_EXPORT_INTERVAL_MS_ARG = "logging_export_interval_ms" +METRIC_READERS_ARG = "metric_readers" +VIEWS_ARG = "views" +SAMPLING_RATIO_ARG = "sampling_ratio" +TRACING_EXPORT_INTERVAL_MS_ARG = "tracing_export_interval_ms" +INSTRUMENTATION_CONFIG_ARG = "instrumentation_config" + + +CONFIGURATION_ARGUMENTS = ( + CONNECTION_STRING_ARG, + EXCLUDE_INSTRUMENTATIONS_ARG, + RESOURCE_ARG, + DISABLE_LOGGING_ARG, + DISABLE_METRICS_ARG, + DISABLE_TRACING_ARG, + LOGGING_LEVEL_ARG, + LOGGER_NAME_ARG, + LOGGING_EXPORT_INTERVAL_MS_ARG, + METRIC_READERS_ARG, + VIEWS_ARG, + SAMPLING_RATIO_ARG, + TRACING_EXPORT_INTERVAL_MS_ARG, + INSTRUMENTATION_CONFIG_ARG, +) + + +# # "connection_string", +# "exclude_instrumentations", +# # "resource", +# "disable_logging", +# "disable_metrics", +# "disable_tracing", +# "logging_level", +# "logger_name", +# "logging_export_interval_ms", +# "metric_readers", +# "views", +# "sampling_ratio", +# "tracing_export_interval_ms", +# "instrumentation_config", + + # --------------------Diagnostic/status logging------------------------------ _LOG_PATH_LINUX = "/var/log/applicationinsights" diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py index 44d2c5d0..bf66a1f5 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py @@ -4,9 +4,82 @@ # license information. # -------------------------------------------------------------------------- +from json import loads +from logging import NOTSET +from os import environ, getenv from typing import Dict +from azure.monitor.opentelemetry._constants import ( + CONNECTION_STRING_ARG, + DISABLE_LOGGING_ARG, + DISABLE_METRICS_ARG, + DISABLE_TRACING_ARG, + EXCLUDE_INSTRUMENTATIONS_ARG, + INSTRUMENTATION_CONFIG_ARG, + LOGGER_NAME_ARG, + LOGGING_EXPORT_INTERVAL_MS_ARG, + LOGGING_LEVEL_ARG, + METRIC_READERS_ARG, + RESOURCE_ARG, + SAMPLING_RATIO_ARG, + TRACING_EXPORT_INTERVAL_MS_ARG, + VIEWS_ARG, +) from azure.monitor.opentelemetry._types import ConfigurationValue +from opentelemetry.sdk.environment_variables import ( + OTEL_BSP_SCHEDULE_DELAY, + OTEL_LOG_LEVEL, + OTEL_TRACES_SAMPLER_ARG, +) +from opentelemetry.sdk.resources import OTELResourceDetector + +""" + This function works as a configuration layer that allows the + 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 Sequence[str] connection_string: Specifies the libraries with instrumentations to be enabled. + :keyword Resource resource: Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. + :keyword bool disable_logging: If set to `True`, disables collection and export of logging telemetry. Defaults to `False`. + :keyword bool disable_metrics: If set to `True`, disables collection and export of metric telemetry. Defaults to `False`. + :keyword bool disable_tracing: If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`. + :keyword int logging_level: Specifies the logging of the logs you would like to collect for your logging pipeline. + :keyword str logger_name: Specifies the logger name under which logging will be instrumented. Defaults to "" which corresponds to the root logger. + :keyword int logging_export_interval_ms: Specifies the logging export interval in milliseconds. Defaults to 5000. + :keyword Sequence[MetricReader] metric_readers: Specifies the metric readers that you would like to use for your metric pipeline. + :keyword Sequence[View] views: Specifies the list of views to configure for the metric pipeline. + :keyword float sampling_ratio: Specifies the ratio of distributed tracing telemetry to be sampled. Accepted values are in the range [0,1]. Defaults to 1.0, meaning no telemetry is sampled out. + :keyword int tracing_export_interval_ms: Specifies the distributed tracing export interval in milliseconds. Defaults to 5000. + :keyword Dict[str, Any] _config: Specifies a dictionary of kwargs that will be applied to configuration for instrumentation . + :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 + """ + +_CONFIGURATION_ENV_VAR_PREFIX = "APPLICATIONINSIGHTS_" +_OTEL_BLRP_SCHEDULE_DELAY = "OTEL_BLRP_SCHEDULE_DELAY" + + +def _get_env_var_name(arg): + return _CONFIGURATION_ENV_VAR_PREFIX + arg.upper() + + +EXCLUDE_INSTRUMENTATIONS_ENV_VAR = _get_env_var_name( + EXCLUDE_INSTRUMENTATIONS_ARG +) +DISABLE_LOGGING_ENV_VAR = _get_env_var_name(DISABLE_LOGGING_ARG) +DISABLE_METRICS_ENV_VAR = _get_env_var_name(DISABLE_METRICS_ARG) +DISABLE_TRACING_ENV_VAR = _get_env_var_name(DISABLE_TRACING_ARG) +# Speced out but unused by OTel SDK as of 1.15.0 +LOGGING_LEVEL_ENV_VAR = OTEL_LOG_LEVEL +LOGGER_NAME_ENV_VAR = _get_env_var_name(LOGGER_NAME_ARG) +# Speced out but unused by OTel SDK as of 1.15.0 +LOGGING_EXPORT_INTERVAL_MS_ENV_VAR = _OTEL_BLRP_SCHEDULE_DELAY +METRIC_READERS_ENV_VAR = _get_env_var_name(METRIC_READERS_ARG) +VIEWS_ENV_VAR = _get_env_var_name(VIEWS_ARG) +# TODO: remove when sampler uses env var instead +SAMPLING_RATIO_ENV_VAR = OTEL_TRACES_SAMPLER_ARG +INSTRUMENTATION_CONFIG_ENV_VAR = _get_env_var_name(INSTRUMENTATION_CONFIG_ARG) def _get_configurations(**kwargs) -> Dict[str, ConfigurationValue]: @@ -15,7 +88,118 @@ def _get_configurations(**kwargs) -> Dict[str, ConfigurationValue]: for key, val in kwargs.items(): configurations[key] = val + _default_exclude_instrumentations(configurations) + _default_disable_logging(configurations) + _default_disable_metrics(configurations) + _default_disable_tracing(configurations) + _default_logging_level(configurations) + _default_logger_name(configurations) + _default_logging_export_interval_ms(configurations) + _default_metric_readers(configurations) + _default_views(configurations) + _default_sampling_ratio(configurations) + _default_tracing_export_interval_ms(configurations) + _default_instrumentation_config(configurations) + + # TODO: remove when validation added to BLRP + if configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] <= 0: + raise ValueError("%s must be positive." % LOGGING_EXPORT_INTERVAL_MS_ARG) + return configurations -# TODO: Add env var configuration +def _default_exclude_instrumentations(configurations): + if EXCLUDE_INSTRUMENTATIONS_ARG not in configurations: + default = [] + if EXCLUDE_INSTRUMENTATIONS_ENV_VAR in environ: + default = loads(environ[EXCLUDE_INSTRUMENTATIONS_ENV_VAR]) + configurations[EXCLUDE_INSTRUMENTATIONS_ARG] = default + + +def _default_disable_logging(configurations): + if DISABLE_LOGGING_ARG not in configurations: + default = False + if DISABLE_LOGGING_ENV_VAR in environ: + default = bool(environ[DISABLE_LOGGING_ENV_VAR]) + configurations[DISABLE_LOGGING_ARG] = default + + +def _default_disable_metrics(configurations): + if DISABLE_METRICS_ARG not in configurations: + default = False + if DISABLE_METRICS_ENV_VAR in environ: + default = bool(environ[DISABLE_METRICS_ENV_VAR]) + configurations[DISABLE_METRICS_ARG] = default + + +def _default_disable_tracing(configurations): + if DISABLE_TRACING_ARG not in configurations: + default = False + if DISABLE_TRACING_ENV_VAR in environ: + default = bool(environ[DISABLE_TRACING_ENV_VAR]) + configurations[DISABLE_TRACING_ARG] = default + + +def _default_logging_level(configurations): + if LOGGING_LEVEL_ARG not in configurations: + default = NOTSET + if LOGGING_LEVEL_ENV_VAR in environ: + default = int(environ[LOGGING_LEVEL_ENV_VAR]) + # TODO: Match OTel env var usage when it is determined. + configurations[LOGGING_LEVEL_ARG] = default + + +def _default_logger_name(configurations): + if LOGGER_NAME_ARG not in configurations: + default = "" + if LOGGER_NAME_ENV_VAR in environ: + default = environ[LOGGER_NAME_ENV_VAR] + configurations[LOGGER_NAME_ARG] = default + + +def _default_logging_export_interval_ms(configurations): + if LOGGING_EXPORT_INTERVAL_MS_ARG not in configurations: + default = 5000 + if LOGGING_EXPORT_INTERVAL_MS_ENV_VAR in environ: + default = int(environ[LOGGING_EXPORT_INTERVAL_MS_ENV_VAR]) + configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] = default + + +def _default_metric_readers(configurations): + if METRIC_READERS_ARG not in configurations: + default = [] + if METRIC_READERS_ENV_VAR in environ: + default = loads(environ[METRIC_READERS_ENV_VAR]) + configurations[METRIC_READERS_ARG] = default + + +def _default_views(configurations): + if VIEWS_ARG not in configurations: + #TODO tuple or list + default = [] + if VIEWS_ENV_VAR in environ: + default = loads(environ[VIEWS_ENV_VAR]) + configurations[VIEWS_ARG] = default + + +# TODO: remove when sampler uses env var instead +def _default_sampling_ratio(configurations): + if SAMPLING_RATIO_ARG not in configurations: + default = 1.0 + if SAMPLING_RATIO_ENV_VAR in environ: + default = float(environ[SAMPLING_RATIO_ENV_VAR]) + configurations[SAMPLING_RATIO_ARG] = default + + +def _default_tracing_export_interval_ms(configurations): + if TRACING_EXPORT_INTERVAL_MS_ARG not in configurations: + configurations[TRACING_EXPORT_INTERVAL_MS_ARG] = None + + +def _default_instrumentation_config(configurations): + if INSTRUMENTATION_CONFIG_ARG not in configurations: + # TODO: list or dict + default = {} + if INSTRUMENTATION_CONFIG_ENV_VAR in environ: + default = loads(environ[INSTRUMENTATION_CONFIG_ENV_VAR]) + configurations[INSTRUMENTATION_CONFIG_ARG] = default diff --git a/azure-monitor-opentelemetry/tests/configuration/test_configure.py b/azure-monitor-opentelemetry/tests/configuration/test_configure.py index be264574..06173925 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_configure.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_configure.py @@ -52,19 +52,22 @@ def test_configure_azure_monitor( ): kwargs = { "connection_string": "test_cs", + "exclude_instrumentations": [], "disable_tracing": False, "disable_logging": False, "disable_metrics": False, "logging_export_interval_ms": 10000, "logging_level": "test_logging_level", "logger_name": "test_logger_name", - "metric_readers": "test_metric_readers", + # TODO Replace with resource "service_name": "test_service_name", "service_namespace": "test_namespace", "service_instance_id": "test_id", "sampling_ratio": 0.5, "tracing_export_interval_ms": 15000, + "metric_readers": "test_metric_readers", "views": "test_views", + "instrumentation_config": [], } resource_init_mock = Mock() resource_mock.return_value = resource_init_mock @@ -100,18 +103,22 @@ def test_configure_azure_monitor_disable_tracing( ): kwargs = { "connection_string": "test_cs", + "exclude_instrumentations": [], "disable_tracing": True, "disable_logging": False, "disable_metrics": False, "logging_export_interval_ms": 10000, "logging_level": "test_logging_level", "logger_name": "test_logger_name", + # TODO Replace with resource "service_name": "test_service_name", "service_namespace": "test_namespace", "service_instance_id": "test_id", "sampling_ratio": 0.5, "tracing_export_interval_ms": 15000, + "metric_readers": [], "views": "test_views", + "instrumentation_config": [], } resource_init_mock = Mock() resource_mock.return_value = resource_init_mock @@ -147,18 +154,22 @@ def test_configure_azure_monitor_disable_logging( ): kwargs = { "connection_string": "test_cs", + "exclude_instrumentations": [], "disable_tracing": False, "disable_logging": True, "disable_metrics": False, "logging_export_interval_ms": 10000, "logging_level": "test_logging_level", "logger_name": "test_logger_name", + # TODO Replace with resource "service_name": "test_service_name", "service_namespace": "test_namespace", "service_instance_id": "test_id", "sampling_ratio": 0.5, "tracing_export_interval_ms": 15000, + "metric_readers": [], "views": "test_views", + "instrumentation_config": [], } resource_init_mock = Mock() resource_mock.return_value = resource_init_mock @@ -194,17 +205,22 @@ def test_configure_azure_monitor_disable_metrics( ): kwargs = { "connection_string": "test_cs", + "exclude_instrumentations": [], "disable_tracing": False, "disable_logging": False, "disable_metrics": True, "logging_export_interval_ms": 10000, "logging_level": "test_logging_level", + "logger_name": "test_logger_name", + # TODO Replace with resource "service_name": "test_service_name", "service_namespace": "test_namespace", "service_instance_id": "test_id", "sampling_ratio": 0.5, "tracing_export_interval_ms": 15000, + "metric_readers": [], "views": "test_views", + "instrumentation_config": [], } resource_init_mock = Mock() resource_mock.return_value = resource_init_mock diff --git a/azure-monitor-opentelemetry/tests/configuration/test_util.py b/azure-monitor-opentelemetry/tests/configuration/test_util.py index 111d5e6f..d68f6b27 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_util.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_util.py @@ -12,51 +12,138 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest +from unittest import TestCase +from unittest.mock import patch +from logging import NOTSET, WARN -from azure.monitor.opentelemetry.util.configurations import _get_configurations +from azure.monitor.opentelemetry.util.configurations import ( + _get_configurations, + EXCLUDE_INSTRUMENTATIONS_ENV_VAR, + DISABLE_LOGGING_ENV_VAR, + DISABLE_METRICS_ENV_VAR, + DISABLE_TRACING_ENV_VAR, + LOGGING_LEVEL_ENV_VAR, + LOGGER_NAME_ENV_VAR, + LOGGING_EXPORT_INTERVAL_MS_ENV_VAR, + METRIC_READERS_ENV_VAR, + VIEWS_ENV_VAR, + SAMPLING_RATIO_ENV_VAR, + INSTRUMENTATION_CONFIG_ENV_VAR, +) - -class TestUtil(unittest.TestCase): +class TestUtil(TestCase): def test_get_configurations(self): configurations = _get_configurations( connection_string="test_cs", + exclude_instrumentations="test_exclude_instrumentations", disable_logging="test_disable_logging", + disable_metrics="test_disable_metrics", disable_tracing="test_disable_tracing", instrumentations=["test_instrumentation"], logging_level="test_logging_level", logger_name="test_logger_name", - service_name="test_service_name", - service_namespace="test_namespace", - service_instance_id="test_id", + resource="test_resource", sampling_ratio="test_sample_ratio", - tracing_export_interval="test_tracing_interval", - logging_export_interval="test_logging_interval", + tracing_export_interval_ms=10000, + logging_export_interval_ms=10000, metric_readers=("test_readers"), views=("test_view"), + instrumentation_config="test_instrumentation_config", + credential="test_credential", ) self.assertEqual(configurations["connection_string"], "test_cs") + self.assertEqual( + configurations["exclude_instrumentations"], + "test_exclude_instrumentations", + ) self.assertEqual( configurations["disable_logging"], "test_disable_logging" ) self.assertEqual( - configurations["disable_tracing"], "test_disable_tracing" + configurations["disable_metrics"], "test_disable_metrics" ) self.assertEqual( - configurations["instrumentations"], ["test_instrumentation"] + configurations["disable_tracing"], "test_disable_tracing" ) self.assertEqual(configurations["logging_level"], "test_logging_level") self.assertEqual(configurations["logger_name"], "test_logger_name") - self.assertEqual(configurations["service_name"], "test_service_name") - self.assertEqual(configurations["service_namespace"], "test_namespace") - self.assertEqual(configurations["service_instance_id"], "test_id") + self.assertEqual(configurations["resource"], "test_resource") self.assertEqual(configurations["sampling_ratio"], "test_sample_ratio") - self.assertEqual( - configurations["tracing_export_interval"], "test_tracing_interval" - ) - self.assertEqual( - configurations["logging_export_interval"], "test_logging_interval" - ) + self.assertEqual(configurations["tracing_export_interval_ms"], 10000) + self.assertEqual(configurations["logging_export_interval_ms"], 10000) self.assertEqual(configurations["metric_readers"], ("test_readers")) self.assertEqual(configurations["views"], ("test_view")) + self.assertEqual( + configurations["instrumentation_config"], + ("test_instrumentation_config"), + ) + self.assertEqual(configurations["credential"], ("test_credential")) + + + @patch.dict("os.environ", {}, clear=True) + def test_get_configurations_defaults(self): + configurations = _get_configurations() + + self.assertTrue("connection_string" not in configurations) + self.assertEqual(configurations["exclude_instrumentations"], []) + self.assertEqual(configurations["disable_logging"], False) + self.assertEqual(configurations["disable_metrics"], False) + self.assertEqual(configurations["disable_tracing"], False) + self.assertEqual(configurations["logging_level"], NOTSET) + self.assertEqual(configurations["logger_name"], "") + self.assertTrue("resource" not in configurations) + self.assertEqual(configurations["sampling_ratio"], 1.0) + self.assertEqual(configurations["tracing_export_interval_ms"], None) + self.assertEqual(configurations["logging_export_interval_ms"], 5000) + self.assertEqual(configurations["metric_readers"], []) + self.assertEqual(configurations["views"], []) + self.assertEqual(configurations["instrumentation_config"], {}) + + + def test_get_configurations_validation(self): + self.assertRaises(ValueError, _get_configurations, logging_export_interval_ms=-0.5) + self.assertRaises(ValueError, _get_configurations, logging_export_interval_ms=-1) + + + @patch.dict("os.environ", { + EXCLUDE_INSTRUMENTATIONS_ENV_VAR: "[\"flask\"]", + DISABLE_LOGGING_ENV_VAR: "True", + DISABLE_METRICS_ENV_VAR: "True", + DISABLE_TRACING_ENV_VAR: "True", + # Speced out but unused by OTel SDK as of 1.15.0 + LOGGING_LEVEL_ENV_VAR: "30", + LOGGER_NAME_ENV_VAR: "opentelemetry", + # Speced out but unused by OTel SDK as of 1.15.0 + LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "10000", + METRIC_READERS_ENV_VAR: "[\"metricReader1\", \"metricReader2\"]", + VIEWS_ENV_VAR: "[\"view1\", \"view2\"]", + # TODO: remove when sampler uses env var instead + SAMPLING_RATIO_ENV_VAR: "0.5", + INSTRUMENTATION_CONFIG_ENV_VAR: """{ + "flask": { + "excluded_urls": "http://localhost:8080/ignore" + } + }""" + }, clear=True) + def test_get_configurations_env_vars(self): + configurations = _get_configurations() + + self.assertTrue("connection_string" not in configurations) + self.assertEqual(configurations["exclude_instrumentations"], ["flask"]) + self.assertEqual(configurations["disable_logging"], True) + self.assertEqual(configurations["disable_metrics"], True) + self.assertEqual(configurations["disable_tracing"], True) + self.assertEqual(configurations["logging_level"], WARN) + self.assertEqual(configurations["logger_name"], "opentelemetry") + self.assertTrue("resource" not in configurations) + self.assertEqual(configurations["sampling_ratio"], 0.5) + self.assertEqual(configurations["tracing_export_interval_ms"], None) + self.assertEqual(configurations["logging_export_interval_ms"], 10000) + self.assertEqual(configurations["metric_readers"], ["metricReader1", "metricReader2"]) + self.assertEqual(configurations["views"], ["view1", "view2"]) + self.assertEqual(configurations["instrumentation_config"], { + "flask": { + "excluded_urls": "http://localhost:8080/ignore" + } + }) From bc44d188f68721f1c482777229dd27f3619f9677 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 22 Mar 2023 14:56:36 -0700 Subject: [PATCH 02/19] Updated out of date tests, lint --- .../opentelemetry/util/configurations.py | 7 +- .../tests/configuration/test_configure.py | 20 +---- .../tests/configuration/test_util.py | 76 ++++++++++--------- 3 files changed, 50 insertions(+), 53 deletions(-) diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py index bf66a1f5..ce7a474c 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py @@ -103,7 +103,9 @@ def _get_configurations(**kwargs) -> Dict[str, ConfigurationValue]: # TODO: remove when validation added to BLRP if configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] <= 0: - raise ValueError("%s must be positive." % LOGGING_EXPORT_INTERVAL_MS_ARG) + raise ValueError( + "%s must be positive." % LOGGING_EXPORT_INTERVAL_MS_ARG + ) return configurations @@ -175,7 +177,7 @@ def _default_metric_readers(configurations): def _default_views(configurations): if VIEWS_ARG not in configurations: - #TODO tuple or list + # TODO tuple or list default = [] if VIEWS_ENV_VAR in environ: default = loads(environ[VIEWS_ENV_VAR]) @@ -198,7 +200,6 @@ def _default_tracing_export_interval_ms(configurations): def _default_instrumentation_config(configurations): if INSTRUMENTATION_CONFIG_ARG not in configurations: - # TODO: list or dict default = {} if INSTRUMENTATION_CONFIG_ENV_VAR in environ: default = loads(environ[INSTRUMENTATION_CONFIG_ENV_VAR]) diff --git a/azure-monitor-opentelemetry/tests/configuration/test_configure.py b/azure-monitor-opentelemetry/tests/configuration/test_configure.py index 06173925..75996d0d 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_configure.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_configure.py @@ -59,10 +59,7 @@ def test_configure_azure_monitor( "logging_export_interval_ms": 10000, "logging_level": "test_logging_level", "logger_name": "test_logger_name", - # TODO Replace with resource - "service_name": "test_service_name", - "service_namespace": "test_namespace", - "service_instance_id": "test_id", + "resource": "test_resource", "sampling_ratio": 0.5, "tracing_export_interval_ms": 15000, "metric_readers": "test_metric_readers", @@ -110,10 +107,7 @@ def test_configure_azure_monitor_disable_tracing( "logging_export_interval_ms": 10000, "logging_level": "test_logging_level", "logger_name": "test_logger_name", - # TODO Replace with resource - "service_name": "test_service_name", - "service_namespace": "test_namespace", - "service_instance_id": "test_id", + "resource": "test_resource", "sampling_ratio": 0.5, "tracing_export_interval_ms": 15000, "metric_readers": [], @@ -161,10 +155,7 @@ def test_configure_azure_monitor_disable_logging( "logging_export_interval_ms": 10000, "logging_level": "test_logging_level", "logger_name": "test_logger_name", - # TODO Replace with resource - "service_name": "test_service_name", - "service_namespace": "test_namespace", - "service_instance_id": "test_id", + "resource": "test_resource", "sampling_ratio": 0.5, "tracing_export_interval_ms": 15000, "metric_readers": [], @@ -212,10 +203,7 @@ def test_configure_azure_monitor_disable_metrics( "logging_export_interval_ms": 10000, "logging_level": "test_logging_level", "logger_name": "test_logger_name", - # TODO Replace with resource - "service_name": "test_service_name", - "service_namespace": "test_namespace", - "service_instance_id": "test_id", + "resource": "test_resource", "sampling_ratio": 0.5, "tracing_export_interval_ms": 15000, "metric_readers": [], diff --git a/azure-monitor-opentelemetry/tests/configuration/test_util.py b/azure-monitor-opentelemetry/tests/configuration/test_util.py index d68f6b27..7afaa24e 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_util.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_util.py @@ -12,25 +12,26 @@ # See the License for the specific language governing permissions and # limitations under the License. +from logging import NOTSET, WARN from unittest import TestCase from unittest.mock import patch -from logging import NOTSET, WARN from azure.monitor.opentelemetry.util.configurations import ( - _get_configurations, - EXCLUDE_INSTRUMENTATIONS_ENV_VAR, DISABLE_LOGGING_ENV_VAR, DISABLE_METRICS_ENV_VAR, DISABLE_TRACING_ENV_VAR, - LOGGING_LEVEL_ENV_VAR, + EXCLUDE_INSTRUMENTATIONS_ENV_VAR, + INSTRUMENTATION_CONFIG_ENV_VAR, LOGGER_NAME_ENV_VAR, LOGGING_EXPORT_INTERVAL_MS_ENV_VAR, + LOGGING_LEVEL_ENV_VAR, METRIC_READERS_ENV_VAR, - VIEWS_ENV_VAR, SAMPLING_RATIO_ENV_VAR, - INSTRUMENTATION_CONFIG_ENV_VAR, + VIEWS_ENV_VAR, + _get_configurations, ) + class TestUtil(TestCase): def test_get_configurations(self): configurations = _get_configurations( @@ -80,7 +81,6 @@ def test_get_configurations(self): ) self.assertEqual(configurations["credential"], ("test_credential")) - @patch.dict("os.environ", {}, clear=True) def test_get_configurations_defaults(self): configurations = _get_configurations() @@ -100,32 +100,38 @@ def test_get_configurations_defaults(self): self.assertEqual(configurations["views"], []) self.assertEqual(configurations["instrumentation_config"], {}) - def test_get_configurations_validation(self): - self.assertRaises(ValueError, _get_configurations, logging_export_interval_ms=-0.5) - self.assertRaises(ValueError, _get_configurations, logging_export_interval_ms=-1) - + self.assertRaises( + ValueError, _get_configurations, logging_export_interval_ms=-0.5 + ) + self.assertRaises( + ValueError, _get_configurations, logging_export_interval_ms=-1 + ) - @patch.dict("os.environ", { - EXCLUDE_INSTRUMENTATIONS_ENV_VAR: "[\"flask\"]", - DISABLE_LOGGING_ENV_VAR: "True", - DISABLE_METRICS_ENV_VAR: "True", - DISABLE_TRACING_ENV_VAR: "True", - # Speced out but unused by OTel SDK as of 1.15.0 - LOGGING_LEVEL_ENV_VAR: "30", - LOGGER_NAME_ENV_VAR: "opentelemetry", - # Speced out but unused by OTel SDK as of 1.15.0 - LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "10000", - METRIC_READERS_ENV_VAR: "[\"metricReader1\", \"metricReader2\"]", - VIEWS_ENV_VAR: "[\"view1\", \"view2\"]", - # TODO: remove when sampler uses env var instead - SAMPLING_RATIO_ENV_VAR: "0.5", - INSTRUMENTATION_CONFIG_ENV_VAR: """{ + @patch.dict( + "os.environ", + { + EXCLUDE_INSTRUMENTATIONS_ENV_VAR: '["flask"]', + DISABLE_LOGGING_ENV_VAR: "True", + DISABLE_METRICS_ENV_VAR: "True", + DISABLE_TRACING_ENV_VAR: "True", + # Speced out but unused by OTel SDK as of 1.15.0 + LOGGING_LEVEL_ENV_VAR: "30", + LOGGER_NAME_ENV_VAR: "opentelemetry", + # Speced out but unused by OTel SDK as of 1.15.0 + LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "10000", + METRIC_READERS_ENV_VAR: '["metricReader1", "metricReader2"]', + VIEWS_ENV_VAR: '["view1", "view2"]', + # TODO: remove when sampler uses env var instead + SAMPLING_RATIO_ENV_VAR: "0.5", + INSTRUMENTATION_CONFIG_ENV_VAR: """{ "flask": { "excluded_urls": "http://localhost:8080/ignore" } - }""" - }, clear=True) + }""", + }, + clear=True, + ) def test_get_configurations_env_vars(self): configurations = _get_configurations() @@ -140,10 +146,12 @@ def test_get_configurations_env_vars(self): self.assertEqual(configurations["sampling_ratio"], 0.5) self.assertEqual(configurations["tracing_export_interval_ms"], None) self.assertEqual(configurations["logging_export_interval_ms"], 10000) - self.assertEqual(configurations["metric_readers"], ["metricReader1", "metricReader2"]) + self.assertEqual( + configurations["metric_readers"], + ["metricReader1", "metricReader2"], + ) self.assertEqual(configurations["views"], ["view1", "view2"]) - self.assertEqual(configurations["instrumentation_config"], { - "flask": { - "excluded_urls": "http://localhost:8080/ignore" - } - }) + self.assertEqual( + configurations["instrumentation_config"], + {"flask": {"excluded_urls": "http://localhost:8080/ignore"}}, + ) From e8af2b4dff46384ed4f45102a566f9f6f740b566 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 22 Mar 2023 15:01:58 -0700 Subject: [PATCH 03/19] lint --- .../azure/monitor/opentelemetry/util/configurations.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py index ce7a474c..4b61028f 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py @@ -6,11 +6,10 @@ from json import loads from logging import NOTSET -from os import environ, getenv +from os import environ from typing import Dict from azure.monitor.opentelemetry._constants import ( - CONNECTION_STRING_ARG, DISABLE_LOGGING_ARG, DISABLE_METRICS_ARG, DISABLE_TRACING_ARG, @@ -20,18 +19,15 @@ LOGGING_EXPORT_INTERVAL_MS_ARG, LOGGING_LEVEL_ARG, METRIC_READERS_ARG, - RESOURCE_ARG, SAMPLING_RATIO_ARG, TRACING_EXPORT_INTERVAL_MS_ARG, VIEWS_ARG, ) from azure.monitor.opentelemetry._types import ConfigurationValue from opentelemetry.sdk.environment_variables import ( - OTEL_BSP_SCHEDULE_DELAY, OTEL_LOG_LEVEL, OTEL_TRACES_SAMPLER_ARG, ) -from opentelemetry.sdk.resources import OTELResourceDetector """ This function works as a configuration layer that allows the From ce5ce9bb3b73f38843a16ca03a36e1597a14a305 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 22 Mar 2023 15:14:10 -0700 Subject: [PATCH 04/19] Rearranged arguments according to code usage and easier reading --- azure-monitor-opentelemetry/README.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/azure-monitor-opentelemetry/README.md b/azure-monitor-opentelemetry/README.md index 3e1e3d4d..a354fb67 100644 --- a/azure-monitor-opentelemetry/README.md +++ b/azure-monitor-opentelemetry/README.md @@ -53,10 +53,18 @@ pip install azure-monitor-opentelemetry --pre You can use `configure_azure_monitor` to set up instrumentation for your app to Azure Monitor. `configure_azure_monitor` supports the following optional arguments: * connection_string - The [connection string][connection_string_doc] for your Application Insights resource. The connection string will be automatically populated from the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable if not explicitly passed in. +* exclude_instrumentations - By default, all supported [instrumentations](#officially-supported-instrumentations) are enabled to collect telemetry. Specify instrumentations you do not want to enable to collect telemetry by passing in a comma separated list of instrumented library names. e.g. `["requests", "flask"]` +* resource - Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior. * disable_logging - If set to `True`, disables collection and export of logging telemetry. Defaults to `False`. * disable_metrics - If set to `True`, disables collection and export of metric telemetry. Defaults to `False`. * disable_tracing - If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`. -* exclude_instrumentations - By default, all supported [instrumentations](#officially-supported-instrumentations) are enabled to collect telemetry. Specify instrumentations you do not want to enable to collect telemetry by passing in a comma separated list of instrumented library names. e.g. `["requests", "flask"]` +* logging_level - Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. Defaults to logging.NOTSET. +* logger_name = Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Defaults to "" which corresponds to the root logger. +* logging_export_interval_ms - Specifies the logging export interval in milliseconds. Defaults to 5000. +* metric_readers - Specifies the [metric readers][ot_metric_reader] that you would like to use for your metric pipeline. Accepts a list of [metric readers][ot_sdk_python_metric_reader]. +* views - Specifies the list of [views][opentelemetry_spec_view] to configure for the metric pipeline. See [here][ot_sdk_python_view_examples] for example usage. +* sampling_ratio - Specifies the ratio of distributed tracing telemetry to be [sampled][application_insights_sampling]. Accepted values are in the range [0,1]. Defaults to 1.0, meaning no telemetry is sampled out. +* tracing_export_interval_ms - Specifies the distributed tracing export interval in milliseconds. Defaults to 5000. * instrumentation_config - Specifies a dictionary of kwargs that will be applied to instrumentation configuration. You can specify which instrumentation you want to configure by name in the key field and value as a dictionary representing `kwargs` for the corresponding instrumentation. Refer to the `Supported Library` section [above](#officially-supported-instrumentations) for the list of suppoprted library names. @@ -78,15 +86,6 @@ configure_azure_monitor( Take a look at the specific [instrumenation][ot_instrumentations] documentation for available configurations. -* resource - Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior. -* logging_level - Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. Defaults to logging.NOTSET. -* logger_name = Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Defaults to "" which corresponds to the root logger. -* logging_export_interval_ms - Specifies the logging export interval in milliseconds. Defaults to 5000. -* metric_readers - Specifies the [metric readers][ot_metric_reader] that you would like to use for your metric pipeline. Accepts a list of [metric readers][ot_sdk_python_metric_reader]. -* views - Specifies the list of [views][opentelemetry_spec_view] to configure for the metric pipeline. See [here][ot_sdk_python_view_examples] for example usage. -* sampling_ratio - Specifies the ratio of distributed tracing telemetry to be [sampled][application_insights_sampling]. Accepted values are in the range [0,1]. Defaults to 1.0, meaning no telemetry is sampled out. -* tracing_export_interval_ms - Specifies the distributed tracing export interval in milliseconds. Defaults to 5000. - #### Azure monitor OpenTelemetry Exporter configurations You can pass Azure monitor OpenTelemetry exporter configuration parameters directly into `configure_azure_monitor`. See additional [configuration related to exporting here][exporter_configuration_docs]. From db73ac03f46038d78707c7faf115daa7bbe670d5 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 22 Mar 2023 15:26:19 -0700 Subject: [PATCH 05/19] Documentation --- azure-monitor-opentelemetry/README.md | 22 ++++++++++--------- .../opentelemetry/util/configurations.py | 2 ++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/azure-monitor-opentelemetry/README.md b/azure-monitor-opentelemetry/README.md index a354fb67..cb5b3a44 100644 --- a/azure-monitor-opentelemetry/README.md +++ b/azure-monitor-opentelemetry/README.md @@ -53,19 +53,19 @@ pip install azure-monitor-opentelemetry --pre You can use `configure_azure_monitor` to set up instrumentation for your app to Azure Monitor. `configure_azure_monitor` supports the following optional arguments: * connection_string - The [connection string][connection_string_doc] for your Application Insights resource. The connection string will be automatically populated from the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable if not explicitly passed in. -* exclude_instrumentations - By default, all supported [instrumentations](#officially-supported-instrumentations) are enabled to collect telemetry. Specify instrumentations you do not want to enable to collect telemetry by passing in a comma separated list of instrumented library names. e.g. `["requests", "flask"]` +* exclude_instrumentations - By default, all supported [instrumentations](#officially-supported-instrumentations) are enabled to collect telemetry. Specify instrumentations you do not want to enable to collect telemetry by passing in a comma separated list of instrumented library names. Can also be set via the `APPLICATIONINSIGHTS_EXCLUDE_INSTRUMENTATIONS` environment vairable. e.g. `["requests", "flask"]` * resource - Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior. -* disable_logging - If set to `True`, disables collection and export of logging telemetry. Defaults to `False`. -* disable_metrics - If set to `True`, disables collection and export of metric telemetry. Defaults to `False`. -* disable_tracing - If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`. -* logging_level - Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. Defaults to logging.NOTSET. -* logger_name = Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Defaults to "" which corresponds to the root logger. -* logging_export_interval_ms - Specifies the logging export interval in milliseconds. Defaults to 5000. +* disable_logging - If set to `True`, disables collection and export of logging telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_LOGGING` environment vairable. Defaults to `False`. +* disable_metrics - If set to `True`, disables collection and export of metric telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_METRICS` environment vairable. Defaults to `False`. +* disable_tracing - If set to `True`, disables collection and export of distributed tracing telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_TRACING` environment vairable. Defaults to `False`. +* logging_level - Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. Can also be set via the `OTEL_LOG_LEVEL` environment vairable. Defaults to logging.NOTSET. +* logger_name = Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Can also be set via the `APPLICATIONINSIGHTS_LOGGER_NAME` environment vairable. Defaults to "" which corresponds to the root logger. +* logging_export_interval_ms - Specifies the logging export interval in milliseconds. Can also be set via the `OTEL_BLRP_SCHEDULE_DELAY` environment vairable. Defaults to 5000. * metric_readers - Specifies the [metric readers][ot_metric_reader] that you would like to use for your metric pipeline. Accepts a list of [metric readers][ot_sdk_python_metric_reader]. * views - Specifies the list of [views][opentelemetry_spec_view] to configure for the metric pipeline. See [here][ot_sdk_python_view_examples] for example usage. -* sampling_ratio - Specifies the ratio of distributed tracing telemetry to be [sampled][application_insights_sampling]. Accepted values are in the range [0,1]. Defaults to 1.0, meaning no telemetry is sampled out. -* tracing_export_interval_ms - Specifies the distributed tracing export interval in milliseconds. Defaults to 5000. -* instrumentation_config - Specifies a dictionary of kwargs that will be applied to instrumentation configuration. You can specify which instrumentation you want to configure by name in the key field and value as a dictionary representing `kwargs` for the corresponding instrumentation. +* sampling_ratio - Specifies the ratio of distributed tracing telemetry to be [sampled][application_insights_sampling]. Accepted values are in the range [0,1]. Can also be set with the `OTEL_TRACES_SAMPLER_ARG` environment variable. Defaults to 1.0, meaning no telemetry is sampled out. +* tracing_export_interval_ms - Specifies the distributed tracing export interval in milliseconds. Can also be set via the `APPLICATIONINSIGHTS_TRACING_EXPORT_INTERVAL_MS` environment vairable. Defaults to 5000. +* instrumentation_config - Specifies a dictionary of kwargs that will be applied to instrumentation configuration. You can specify which instrumentation you want to configure by name in the key field and value as a dictionary representing `kwargs` for the corresponding instrumentation. Can also be set via the `APPLICATIONINSIGHTS_INSTRUMENTATION_CONFIG` environment vairable. Refer to the `Supported Library` section [above](#officially-supported-instrumentations) for the list of suppoprted library names. ```python @@ -86,6 +86,8 @@ configure_azure_monitor( Take a look at the specific [instrumenation][ot_instrumentations] documentation for available configurations. +When configuring list or dictionary arguments via their respective environment variables, the environment variable values with be interpretted as JSON objects. + #### Azure monitor OpenTelemetry Exporter configurations You can pass Azure monitor OpenTelemetry exporter configuration parameters directly into `configure_azure_monitor`. See additional [configuration related to exporting here][exporter_configuration_docs]. diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py index 4b61028f..d1f4972a 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py @@ -163,6 +163,7 @@ def _default_logging_export_interval_ms(configurations): configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] = default +# TODO: Design metric readers env var usage def _default_metric_readers(configurations): if METRIC_READERS_ARG not in configurations: default = [] @@ -171,6 +172,7 @@ def _default_metric_readers(configurations): configurations[METRIC_READERS_ARG] = default +# TODO: Design views env var usage def _default_views(configurations): if VIEWS_ARG not in configurations: # TODO tuple or list From fd97ef09d74864397abd741c4b66d1f76a6bf3ba Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 22 Mar 2023 15:27:34 -0700 Subject: [PATCH 06/19] clean up --- .../opentelemetry/util/configurations.py | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py index d1f4972a..706fb1be 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py @@ -29,28 +29,6 @@ OTEL_TRACES_SAMPLER_ARG, ) -""" - This function works as a configuration layer that allows the - 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 Sequence[str] connection_string: Specifies the libraries with instrumentations to be enabled. - :keyword Resource resource: Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. - :keyword bool disable_logging: If set to `True`, disables collection and export of logging telemetry. Defaults to `False`. - :keyword bool disable_metrics: If set to `True`, disables collection and export of metric telemetry. Defaults to `False`. - :keyword bool disable_tracing: If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`. - :keyword int logging_level: Specifies the logging of the logs you would like to collect for your logging pipeline. - :keyword str logger_name: Specifies the logger name under which logging will be instrumented. Defaults to "" which corresponds to the root logger. - :keyword int logging_export_interval_ms: Specifies the logging export interval in milliseconds. Defaults to 5000. - :keyword Sequence[MetricReader] metric_readers: Specifies the metric readers that you would like to use for your metric pipeline. - :keyword Sequence[View] views: Specifies the list of views to configure for the metric pipeline. - :keyword float sampling_ratio: Specifies the ratio of distributed tracing telemetry to be sampled. Accepted values are in the range [0,1]. Defaults to 1.0, meaning no telemetry is sampled out. - :keyword int tracing_export_interval_ms: Specifies the distributed tracing export interval in milliseconds. Defaults to 5000. - :keyword Dict[str, Any] _config: Specifies a dictionary of kwargs that will be applied to configuration for instrumentation . - :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 - """ _CONFIGURATION_ENV_VAR_PREFIX = "APPLICATIONINSIGHTS_" _OTEL_BLRP_SCHEDULE_DELAY = "OTEL_BLRP_SCHEDULE_DELAY" From c3f5812b3ab73222d41effce9113008d427d93db Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 22 Mar 2023 15:44:41 -0700 Subject: [PATCH 07/19] typos, documentation, remaining defaulting logic --- azure-monitor-opentelemetry/README.md | 20 ++++++------ .../azure/monitor/opentelemetry/_configure.py | 32 +++++++------------ .../opentelemetry/util/configurations.py | 1 - .../tests/configuration/test_configure.py | 26 ++++++++++++--- 4 files changed, 43 insertions(+), 36 deletions(-) diff --git a/azure-monitor-opentelemetry/README.md b/azure-monitor-opentelemetry/README.md index cb5b3a44..efa3d0ba 100644 --- a/azure-monitor-opentelemetry/README.md +++ b/azure-monitor-opentelemetry/README.md @@ -53,19 +53,19 @@ pip install azure-monitor-opentelemetry --pre You can use `configure_azure_monitor` to set up instrumentation for your app to Azure Monitor. `configure_azure_monitor` supports the following optional arguments: * connection_string - The [connection string][connection_string_doc] for your Application Insights resource. The connection string will be automatically populated from the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable if not explicitly passed in. -* exclude_instrumentations - By default, all supported [instrumentations](#officially-supported-instrumentations) are enabled to collect telemetry. Specify instrumentations you do not want to enable to collect telemetry by passing in a comma separated list of instrumented library names. Can also be set via the `APPLICATIONINSIGHTS_EXCLUDE_INSTRUMENTATIONS` environment vairable. e.g. `["requests", "flask"]` -* resource - Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior. -* disable_logging - If set to `True`, disables collection and export of logging telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_LOGGING` environment vairable. Defaults to `False`. -* disable_metrics - If set to `True`, disables collection and export of metric telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_METRICS` environment vairable. Defaults to `False`. -* disable_tracing - If set to `True`, disables collection and export of distributed tracing telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_TRACING` environment vairable. Defaults to `False`. -* logging_level - Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. Can also be set via the `OTEL_LOG_LEVEL` environment vairable. Defaults to logging.NOTSET. -* logger_name = Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Can also be set via the `APPLICATIONINSIGHTS_LOGGER_NAME` environment vairable. Defaults to "" which corresponds to the root logger. -* logging_export_interval_ms - Specifies the logging export interval in milliseconds. Can also be set via the `OTEL_BLRP_SCHEDULE_DELAY` environment vairable. Defaults to 5000. +* exclude_instrumentations - By default, all supported [instrumentations](#officially-supported-instrumentations) are enabled to collect telemetry. Specify instrumentations you do not want to enable to collect telemetry by passing in a comma separated list of instrumented library names. Can also be set via the `APPLICATIONINSIGHTS_EXCLUDE_INSTRUMENTATIONS` environment variable. e.g. `["requests", "flask"]` +* resource - Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior. This include configuration via environment variables. +* disable_logging - If set to `True`, disables collection and export of logging telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_LOGGING` environment variable. Defaults to `False`. +* disable_metrics - If set to `True`, disables collection and export of metric telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_METRICS` environment variable. Defaults to `False`. +* disable_tracing - If set to `True`, disables collection and export of distributed tracing telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_TRACING` environment variable. Defaults to `False`. +* logging_level - Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. Can also be set via the `OTEL_LOG_LEVEL` environment variable. This environment variable should be set to the number that represents the log leval, not a string representing that log level's name. Defaults to 0 which is logging.NOTSET. +* logger_name = Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Can also be set via the `APPLICATIONINSIGHTS_LOGGER_NAME` environment variable. Defaults to "" which corresponds to the root logger. +* logging_export_interval_ms - Specifies the logging export interval in milliseconds. Can also be set via the `OTEL_BLRP_SCHEDULE_DELAY` environment variable. Defaults to 5000. * metric_readers - Specifies the [metric readers][ot_metric_reader] that you would like to use for your metric pipeline. Accepts a list of [metric readers][ot_sdk_python_metric_reader]. * views - Specifies the list of [views][opentelemetry_spec_view] to configure for the metric pipeline. See [here][ot_sdk_python_view_examples] for example usage. * sampling_ratio - Specifies the ratio of distributed tracing telemetry to be [sampled][application_insights_sampling]. Accepted values are in the range [0,1]. Can also be set with the `OTEL_TRACES_SAMPLER_ARG` environment variable. Defaults to 1.0, meaning no telemetry is sampled out. -* tracing_export_interval_ms - Specifies the distributed tracing export interval in milliseconds. Can also be set via the `APPLICATIONINSIGHTS_TRACING_EXPORT_INTERVAL_MS` environment vairable. Defaults to 5000. -* instrumentation_config - Specifies a dictionary of kwargs that will be applied to instrumentation configuration. You can specify which instrumentation you want to configure by name in the key field and value as a dictionary representing `kwargs` for the corresponding instrumentation. Can also be set via the `APPLICATIONINSIGHTS_INSTRUMENTATION_CONFIG` environment vairable. +* tracing_export_interval_ms - Specifies the distributed tracing export interval in milliseconds. Can also be set via the `APPLICATIONINSIGHTS_TRACING_EXPORT_INTERVAL_MS` environment variable. Defaults to 5000. +* instrumentation_config - Specifies a dictionary of kwargs that will be applied to instrumentation configuration. You can specify which instrumentation you want to configure by name in the key field and value as a dictionary representing `kwargs` for the corresponding instrumentation. Can also be set via the `APPLICATIONINSIGHTS_INSTRUMENTATION_CONFIG` environment variable. Refer to the `Supported Library` section [above](#officially-supported-instrumentations) for the list of suppoprted library names. ```python diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py index 211b4fca..1eb32223 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py @@ -90,9 +90,9 @@ def configure_azure_monitor(**kwargs) -> None: configurations = _get_configurations(**kwargs) - disable_tracing = configurations.get(DISABLE_TRACING_ARG) - disable_logging = configurations.get(DISABLE_LOGGING_ARG) - disable_metrics = configurations.get(DISABLE_METRICS_ARG) + disable_tracing = configurations[DISABLE_TRACING_ARG] + disable_logging = configurations[DISABLE_LOGGING_ARG] + disable_metrics = configurations[DISABLE_METRICS_ARG] resource = None if not disable_logging or not disable_tracing or not disable_metrics: @@ -123,10 +123,8 @@ def _get_resource(configurations: Dict[str, ConfigurationValue]) -> Resource: def _setup_tracing( resource: Resource, configurations: Dict[str, ConfigurationValue] ): - sampling_ratio = configurations.get(SAMPLING_RATIO_ARG) - tracing_export_interval_ms = configurations.get( - TRACING_EXPORT_INTERVAL_MS_ARG - ) + sampling_ratio = configurations[SAMPLING_RATIO_ARG] + tracing_export_interval_ms = configurations[TRACING_EXPORT_INTERVAL_MS_ARG] tracer_provider = TracerProvider( sampler=ApplicationInsightsSampler(sampling_ratio=sampling_ratio), resource=resource, @@ -143,11 +141,9 @@ def _setup_tracing( def _setup_logging( resource: Resource, configurations: Dict[str, ConfigurationValue] ): - logger_name = configurations.get(LOGGER_NAME_ARG) - logging_level = configurations.get(LOGGING_LEVEL_ARG) - logging_export_interval_ms = configurations.get( - LOGGING_EXPORT_INTERVAL_MS_ARG - ) + logger_name = configurations[LOGGER_NAME_ARG] + logging_level = configurations[LOGGING_LEVEL_ARG] + logging_export_interval_ms = configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] logger_provider = LoggerProvider(resource=resource) set_logger_provider(logger_provider) log_exporter = AzureMonitorLogExporter(**configurations) @@ -165,8 +161,8 @@ def _setup_logging( def _setup_metrics( resource: Resource, configurations: Dict[str, ConfigurationValue] ): - views = configurations.get(VIEWS_ARG) - metric_readers = configurations.get(METRIC_READERS_ARG) + views = configurations[VIEWS_ARG] + metric_readers = configurations[METRIC_READERS_ARG] metric_exporter = AzureMonitorMetricExporter(**configurations) reader = PeriodicExportingMetricReader(metric_exporter) meter_provider = MeterProvider( @@ -178,12 +174,8 @@ def _setup_metrics( def _setup_instrumentations(configurations: Dict[str, ConfigurationValue]): - exclude_instrumentations = configurations.get( - EXCLUDE_INSTRUMENTATIONS_ARG, [] - ) - instrumentation_configs = configurations.get( - INSTRUMENTATION_CONFIG_ARG, {} - ) + exclude_instrumentations = configurations[EXCLUDE_INSTRUMENTATIONS_ARG] + instrumentation_configs = configurations[INSTRUMENTATION_CONFIG_ARG] # use pkg_resources for now until https://github.com/open-telemetry/opentelemetry-python/pull/3168 is merged for entry_point in iter_entry_points("opentelemetry_instrumentor"): diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py index 706fb1be..4124caa3 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py @@ -29,7 +29,6 @@ OTEL_TRACES_SAMPLER_ARG, ) - _CONFIGURATION_ENV_VAR_PREFIX = "APPLICATIONINSIGHTS_" _OTEL_BLRP_SCHEDULE_DELAY = "OTEL_BLRP_SCHEDULE_DELAY" diff --git a/azure-monitor-opentelemetry/tests/configuration/test_configure.py b/azure-monitor-opentelemetry/tests/configuration/test_configure.py index 75996d0d..667e89ad 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_configure.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_configure.py @@ -417,7 +417,10 @@ def test_setup_instrumentations( iter_mock, dep_mock, ): - configurations = {} + configurations = { + "exclude_instrumentations": [], + "instrumentation_config": {}, + } ep_mock = Mock() iter_mock.return_value = [ep_mock] instrumentor_mock = Mock() @@ -441,7 +444,10 @@ def test_setup_instrumentations_lib_not_supported( iter_mock, dep_mock, ): - configurations = {} + configurations = { + "exclude_instrumentations": [], + "instrumentation_config": {}, + } ep_mock = Mock() ep2_mock = Mock() iter_mock.return_value = (ep_mock, ep2_mock) @@ -468,7 +474,10 @@ def test_setup_instrumentations_lib_excluded( dep_mock, ): instr_exclude = _SUPPORTED_INSTRUMENTED_LIBRARIES[0] - configurations = {"exclude_instrumentations": [instr_exclude]} + configurations = { + "exclude_instrumentations": [instr_exclude], + "instrumentation_config": {}, + } ep_mock = Mock() ep2_mock = Mock() iter_mock.return_value = (ep_mock, ep2_mock) @@ -496,7 +505,10 @@ def test_setup_instrumentations_conflict( dep_mock, logger_mock, ): - configurations = {} + configurations = { + "exclude_instrumentations": [], + "instrumentation_config": {}, + } ep_mock = Mock() iter_mock.return_value = (ep_mock,) instrumentor_mock = Mock() @@ -522,7 +534,10 @@ def test_setup_instrumentations_exception( dep_mock, logger_mock, ): - configurations = {} + configurations = { + "exclude_instrumentations": [], + "instrumentation_config": {}, + } ep_mock = Mock() iter_mock.return_value = (ep_mock,) instrumentor_mock = Mock() @@ -548,6 +563,7 @@ def test_setup_instrumentations_custom_configuration( ): libr_name = _SUPPORTED_INSTRUMENTED_LIBRARIES[0] configurations = { + "exclude_instrumentations": [], "instrumentation_config": { libr_name: { "test_key": "test_value", From c26d363fe89d092d6801010e368807f7486e283b Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 22 Mar 2023 15:56:38 -0700 Subject: [PATCH 08/19] Lint, testing, private env vars --- .../azure/monitor/opentelemetry/_configure.py | 2 +- .../azure/monitor/opentelemetry/_constants.py | 38 +------------------ .../opentelemetry/util/configurations.py | 16 ++++---- .../tests/configuration/test_util.py | 19 ++++------ 4 files changed, 19 insertions(+), 56 deletions(-) diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py index 1eb32223..fed4b639 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py @@ -68,7 +68,7 @@ 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 Sequence[str] exclude_instrumentations: Specifies instrumentations you do not want to enable. + :keyword Sequence[str] exclude_instrumentations: Specifies instrumentations you want to disable. :keyword Resource resource: Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. :keyword bool disable_logging: If set to `True`, disables collection and export of logging telemetry. Defaults to `False`. :keyword bool disable_metrics: If set to `True`, disables collection and export of metric telemetry. Defaults to `False`. diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py index a0c20c2d..2489b772 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py @@ -13,7 +13,7 @@ ConnectionStringParser, ) -# --------------------Configuration------------------------------ +# --------------------Configuration------------------------------------------ CONNECTION_STRING_ARG = "connection_string" EXCLUDE_INSTRUMENTATIONS_ARG = "exclude_instrumentations" @@ -21,7 +21,7 @@ DISABLE_LOGGING_ARG = "disable_logging" DISABLE_METRICS_ARG = "disable_metrics" DISABLE_TRACING_ARG = "disable_tracing" -# TODO: Consider Log Level to match +# TODO: Consider Log Level to match env var LOGGING_LEVEL_ARG = "logging_level" LOGGER_NAME_ARG = "logger_name" LOGGING_EXPORT_INTERVAL_MS_ARG = "logging_export_interval_ms" @@ -32,40 +32,6 @@ INSTRUMENTATION_CONFIG_ARG = "instrumentation_config" -CONFIGURATION_ARGUMENTS = ( - CONNECTION_STRING_ARG, - EXCLUDE_INSTRUMENTATIONS_ARG, - RESOURCE_ARG, - DISABLE_LOGGING_ARG, - DISABLE_METRICS_ARG, - DISABLE_TRACING_ARG, - LOGGING_LEVEL_ARG, - LOGGER_NAME_ARG, - LOGGING_EXPORT_INTERVAL_MS_ARG, - METRIC_READERS_ARG, - VIEWS_ARG, - SAMPLING_RATIO_ARG, - TRACING_EXPORT_INTERVAL_MS_ARG, - INSTRUMENTATION_CONFIG_ARG, -) - - -# # "connection_string", -# "exclude_instrumentations", -# # "resource", -# "disable_logging", -# "disable_metrics", -# "disable_tracing", -# "logging_level", -# "logger_name", -# "logging_export_interval_ms", -# "metric_readers", -# "views", -# "sampling_ratio", -# "tracing_export_interval_ms", -# "instrumentation_config", - - # --------------------Diagnostic/status logging------------------------------ _LOG_PATH_LINUX = "/var/log/applicationinsights" diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py index 4124caa3..3f3b1ef6 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py @@ -30,7 +30,6 @@ ) _CONFIGURATION_ENV_VAR_PREFIX = "APPLICATIONINSIGHTS_" -_OTEL_BLRP_SCHEDULE_DELAY = "OTEL_BLRP_SCHEDULE_DELAY" def _get_env_var_name(arg): @@ -47,9 +46,10 @@ def _get_env_var_name(arg): LOGGING_LEVEL_ENV_VAR = OTEL_LOG_LEVEL LOGGER_NAME_ENV_VAR = _get_env_var_name(LOGGER_NAME_ARG) # Speced out but unused by OTel SDK as of 1.15.0 -LOGGING_EXPORT_INTERVAL_MS_ENV_VAR = _OTEL_BLRP_SCHEDULE_DELAY -METRIC_READERS_ENV_VAR = _get_env_var_name(METRIC_READERS_ARG) -VIEWS_ENV_VAR = _get_env_var_name(VIEWS_ARG) +LOGGING_EXPORT_INTERVAL_MS_ENV_VAR = "OTEL_BLRP_SCHEDULE_DELAY" +# TODO: leave as private until env var configuration logic is designed +_METRIC_READERS_ENV_VAR = _get_env_var_name(METRIC_READERS_ARG) +_VIEWS_ENV_VAR = _get_env_var_name(VIEWS_ARG) # TODO: remove when sampler uses env var instead SAMPLING_RATIO_ENV_VAR = OTEL_TRACES_SAMPLER_ARG INSTRUMENTATION_CONFIG_ENV_VAR = _get_env_var_name(INSTRUMENTATION_CONFIG_ARG) @@ -144,8 +144,8 @@ def _default_logging_export_interval_ms(configurations): def _default_metric_readers(configurations): if METRIC_READERS_ARG not in configurations: default = [] - if METRIC_READERS_ENV_VAR in environ: - default = loads(environ[METRIC_READERS_ENV_VAR]) + if _METRIC_READERS_ENV_VAR in environ: + default = loads(environ[_METRIC_READERS_ENV_VAR]) configurations[METRIC_READERS_ARG] = default @@ -154,8 +154,8 @@ def _default_views(configurations): if VIEWS_ARG not in configurations: # TODO tuple or list default = [] - if VIEWS_ENV_VAR in environ: - default = loads(environ[VIEWS_ENV_VAR]) + if _VIEWS_ENV_VAR in environ: + default = loads(environ[_VIEWS_ENV_VAR]) configurations[VIEWS_ARG] = default diff --git a/azure-monitor-opentelemetry/tests/configuration/test_util.py b/azure-monitor-opentelemetry/tests/configuration/test_util.py index 7afaa24e..b886d91a 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_util.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_util.py @@ -17,6 +17,8 @@ from unittest.mock import patch from azure.monitor.opentelemetry.util.configurations import ( + _METRIC_READERS_ENV_VAR, + _VIEWS_ENV_VAR, DISABLE_LOGGING_ENV_VAR, DISABLE_METRICS_ENV_VAR, DISABLE_TRACING_ENV_VAR, @@ -25,9 +27,7 @@ LOGGER_NAME_ENV_VAR, LOGGING_EXPORT_INTERVAL_MS_ENV_VAR, LOGGING_LEVEL_ENV_VAR, - METRIC_READERS_ENV_VAR, SAMPLING_RATIO_ENV_VAR, - VIEWS_ENV_VAR, _get_configurations, ) @@ -115,20 +115,17 @@ def test_get_configurations_validation(self): DISABLE_LOGGING_ENV_VAR: "True", DISABLE_METRICS_ENV_VAR: "True", DISABLE_TRACING_ENV_VAR: "True", - # Speced out but unused by OTel SDK as of 1.15.0 LOGGING_LEVEL_ENV_VAR: "30", LOGGER_NAME_ENV_VAR: "opentelemetry", - # Speced out but unused by OTel SDK as of 1.15.0 LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "10000", - METRIC_READERS_ENV_VAR: '["metricReader1", "metricReader2"]', - VIEWS_ENV_VAR: '["view1", "view2"]', - # TODO: remove when sampler uses env var instead + _METRIC_READERS_ENV_VAR: '["metricReader1", "metricReader2"]', + _VIEWS_ENV_VAR: '["view1", "view2"]', SAMPLING_RATIO_ENV_VAR: "0.5", INSTRUMENTATION_CONFIG_ENV_VAR: """{ - "flask": { - "excluded_urls": "http://localhost:8080/ignore" - } - }""", + "flask": { + "excluded_urls": "http://localhost:8080/ignore" + } + }""", }, clear=True, ) From 947ea4744a42768ffd13648d9ea11e59f1e91091 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 22 Mar 2023 16:15:31 -0700 Subject: [PATCH 09/19] Sample typo --- azure-monitor-opentelemetry/samples/metrics/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/azure-monitor-opentelemetry/samples/metrics/views.py b/azure-monitor-opentelemetry/samples/metrics/views.py index 2eb3925c..b81b1186 100644 --- a/azure-monitor-opentelemetry/samples/metrics/views.py +++ b/azure-monitor-opentelemetry/samples/metrics/views.py @@ -8,7 +8,6 @@ # Create a view matching the counter instrument `my.counter` # and configure the new name `my.counter.total` for the result metrics stream change_metric_name_view = View( - connection_string="", instrument_type=Counter, instrument_name="my.counter", name="my.counter.total", From bf54ff2d64f4c70490119742e83f85a47bdd5534 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Fri, 24 Mar 2023 15:21:10 -0700 Subject: [PATCH 10/19] Updated readme --- azure-monitor-opentelemetry/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-monitor-opentelemetry/README.md b/azure-monitor-opentelemetry/README.md index efa3d0ba..5d713158 100644 --- a/azure-monitor-opentelemetry/README.md +++ b/azure-monitor-opentelemetry/README.md @@ -54,7 +54,7 @@ You can use `configure_azure_monitor` to set up instrumentation for your app to * connection_string - The [connection string][connection_string_doc] for your Application Insights resource. The connection string will be automatically populated from the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable if not explicitly passed in. * exclude_instrumentations - By default, all supported [instrumentations](#officially-supported-instrumentations) are enabled to collect telemetry. Specify instrumentations you do not want to enable to collect telemetry by passing in a comma separated list of instrumented library names. Can also be set via the `APPLICATIONINSIGHTS_EXCLUDE_INSTRUMENTATIONS` environment variable. e.g. `["requests", "flask"]` -* resource - Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior. This include configuration via environment variables. +* resource - Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior. This include configuration via the `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_SERVICE_NAME` environment variables * disable_logging - If set to `True`, disables collection and export of logging telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_LOGGING` environment variable. Defaults to `False`. * disable_metrics - If set to `True`, disables collection and export of metric telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_METRICS` environment variable. Defaults to `False`. * disable_tracing - If set to `True`, disables collection and export of distributed tracing telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_TRACING` environment variable. Defaults to `False`. @@ -64,7 +64,7 @@ You can use `configure_azure_monitor` to set up instrumentation for your app to * metric_readers - Specifies the [metric readers][ot_metric_reader] that you would like to use for your metric pipeline. Accepts a list of [metric readers][ot_sdk_python_metric_reader]. * views - Specifies the list of [views][opentelemetry_spec_view] to configure for the metric pipeline. See [here][ot_sdk_python_view_examples] for example usage. * sampling_ratio - Specifies the ratio of distributed tracing telemetry to be [sampled][application_insights_sampling]. Accepted values are in the range [0,1]. Can also be set with the `OTEL_TRACES_SAMPLER_ARG` environment variable. Defaults to 1.0, meaning no telemetry is sampled out. -* tracing_export_interval_ms - Specifies the distributed tracing export interval in milliseconds. Can also be set via the `APPLICATIONINSIGHTS_TRACING_EXPORT_INTERVAL_MS` environment variable. Defaults to 5000. +* tracing_export_interval_ms - Specifies the distributed tracing export interval in milliseconds. Can also be set via the `OTEL_BSP_SCHEDULE_DELAY` environment variable. Defaults to 5000. * instrumentation_config - Specifies a dictionary of kwargs that will be applied to instrumentation configuration. You can specify which instrumentation you want to configure by name in the key field and value as a dictionary representing `kwargs` for the corresponding instrumentation. Can also be set via the `APPLICATIONINSIGHTS_INSTRUMENTATION_CONFIG` environment variable. Refer to the `Supported Library` section [above](#officially-supported-instrumentations) for the list of suppoprted library names. From 98afd5dc6adef171c0e9349156e20748e51e0d20 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Fri, 24 Mar 2023 15:33:08 -0700 Subject: [PATCH 11/19] table added --- azure-monitor-opentelemetry/README.md | 36 ++++++++++++++------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/azure-monitor-opentelemetry/README.md b/azure-monitor-opentelemetry/README.md index 5d713158..8a51f013 100644 --- a/azure-monitor-opentelemetry/README.md +++ b/azure-monitor-opentelemetry/README.md @@ -11,7 +11,7 @@ This distro automatically installs the following libraries: OpenTelemetry instrumentations allow automatic collection of requests sent from underlying instrumented libraries. The following is a list of OpenTelemetry instrumentations that come bundled in with the Azure monitor distro. If you would like to add support for another OpenTelemetry instrumentation, please submit a feature [request][distro_feature_request]. In the meantime, you can use the OpenTelemetry instrumentation manually via it's own APIs (i.e. `instrument()`) in your code. See [this][samples_manual] for an example. -| Instrumentation | Supported library | Supported versions | +| Instrumentation | Supported library | Supported versions | | ------------------------------------- | ----------------- | ------------------ | | [OpenTelemetry Django Instrumentation][ot_instrumentation_django] | [django][pypi_django] | [link][ot_instrumentation_django_version] | [OpenTelemetry FastApi Instrumentation][ot_instrumentation_fastapi] | [fastapi][pypi_fastapi] | [link][ot_instrumentation_fastapi_version] @@ -52,22 +52,24 @@ pip install azure-monitor-opentelemetry --pre You can use `configure_azure_monitor` to set up instrumentation for your app to Azure Monitor. `configure_azure_monitor` supports the following optional arguments: -* connection_string - The [connection string][connection_string_doc] for your Application Insights resource. The connection string will be automatically populated from the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable if not explicitly passed in. -* exclude_instrumentations - By default, all supported [instrumentations](#officially-supported-instrumentations) are enabled to collect telemetry. Specify instrumentations you do not want to enable to collect telemetry by passing in a comma separated list of instrumented library names. Can also be set via the `APPLICATIONINSIGHTS_EXCLUDE_INSTRUMENTATIONS` environment variable. e.g. `["requests", "flask"]` -* resource - Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior. This include configuration via the `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_SERVICE_NAME` environment variables -* disable_logging - If set to `True`, disables collection and export of logging telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_LOGGING` environment variable. Defaults to `False`. -* disable_metrics - If set to `True`, disables collection and export of metric telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_METRICS` environment variable. Defaults to `False`. -* disable_tracing - If set to `True`, disables collection and export of distributed tracing telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_TRACING` environment variable. Defaults to `False`. -* logging_level - Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. Can also be set via the `OTEL_LOG_LEVEL` environment variable. This environment variable should be set to the number that represents the log leval, not a string representing that log level's name. Defaults to 0 which is logging.NOTSET. -* logger_name = Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Can also be set via the `APPLICATIONINSIGHTS_LOGGER_NAME` environment variable. Defaults to "" which corresponds to the root logger. -* logging_export_interval_ms - Specifies the logging export interval in milliseconds. Can also be set via the `OTEL_BLRP_SCHEDULE_DELAY` environment variable. Defaults to 5000. -* metric_readers - Specifies the [metric readers][ot_metric_reader] that you would like to use for your metric pipeline. Accepts a list of [metric readers][ot_sdk_python_metric_reader]. -* views - Specifies the list of [views][opentelemetry_spec_view] to configure for the metric pipeline. See [here][ot_sdk_python_view_examples] for example usage. -* sampling_ratio - Specifies the ratio of distributed tracing telemetry to be [sampled][application_insights_sampling]. Accepted values are in the range [0,1]. Can also be set with the `OTEL_TRACES_SAMPLER_ARG` environment variable. Defaults to 1.0, meaning no telemetry is sampled out. -* tracing_export_interval_ms - Specifies the distributed tracing export interval in milliseconds. Can also be set via the `OTEL_BSP_SCHEDULE_DELAY` environment variable. Defaults to 5000. -* instrumentation_config - Specifies a dictionary of kwargs that will be applied to instrumentation configuration. You can specify which instrumentation you want to configure by name in the key field and value as a dictionary representing `kwargs` for the corresponding instrumentation. Can also be set via the `APPLICATIONINSIGHTS_INSTRUMENTATION_CONFIG` environment variable. - Refer to the `Supported Library` section [above](#officially-supported-instrumentations) for the list of suppoprted library names. - +| Parameter | Description | Environment Variable | +|-------------------|----------------------------------------------------|----------------------| +| `connection_string` | The [connection string][connection_string_doc] for your Application Insights resource. The connection string will be automatically populated from the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable if not explicitly passed in. | `APPLICATIONINSIGHTS_CONNECTION_STRING` | +| `exclude_instrumentations` | By default, all supported [instrumentations](#officially-supported-instrumentations) are enabled to collect telemetry. Specify instrumentations you do not want to enable to collect telemetry by passing in a comma separated list of instrumented library names. Can also be set via the `APPLICATIONINSIGHTS_EXCLUDE_INSTRUMENTATIONS` environment variable. e.g. `["requests", "flask"]` | `APPLICATIONINSIGHTS_EXCLUDE_INSTRUMENTATIONS` | +| `resource` | Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior. This include configuration via the `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_SERVICE_NAME` environment variables. | `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_SERVICE_NAME` | +| `disable_logging` | If set to `True`, disables collection and export of logging telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_LOGGING` environment variable. Defaults to `False`. | `APPLICATIONINSIGHTS_DISABLE_LOGGING` | +| `disable_metrics` | If set to `True`, disables collection and export of metric telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_METRICS` environment variable. Defaults to `False`. | `APPLICATIONINSIGHTS_DISABLE_METRICS` | +| `disable_tracing` | If set to `True`, disables collection and export of distributed tracing telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_TRACING` environment variable. Defaults to `False`. | `APPLICATIONINSIGHTS_DISABLE_TRACING` | +| `logging_level` | Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. Can also be set via the `OTEL_LOG_LEVEL` environment variable. This environment variable should be set to the number that represents the log leval, not a string representing that log level's name. Defaults to 0 which is logging.NOTSET. | `OTEL_LOG_LEVEL` | +| `logger_name` | Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Can also be set via the `APPLICATIONINSIGHTS_LOGGER_NAME` environment variable. Defaults to "" which corresponds to the root logger. | `APPLICATIONINSIGHTS_LOGGER_NAME` | +| `logging_export_interval_ms`| Specifies the logging export interval in milliseconds. Can also be set via the `OTEL_BLRP_SCHEDULE_DELAY` environment variable. Defaults to 5000. | `OTEL_BLRP_SCHEDULE_DELAY` | +| `metric_readers` | Specifies the [metric readers][ot_metric_reader] that you would like to use for your metric pipeline. Accepts a list of [metric readers][ot_sdk_python_metric_reader]. | | +| `views` | Specifies the list of [views][opentelemetry_spec_view] to configure for the metric pipeline. See [here][ot_sdk_python_view_examples] for example usage. | | +| `sampling_ratio` | Specifies the ratio of distributed tracing telemetry to be [sampled][application_insights_sampling]. Accepted values are in the range [0,1]. Can also be set with the `OTEL_TRACES_SAMPLER_ARG` environment variable. Defaults to 1.0, meaning no telemetry is sampled out. | `OTEL_TRACES_SAMPLER_ARG` | +| `tracing_export_interval_ms`| Specifies the distributed tracing export interval in milliseconds. Can also be set via the `OTEL_BSP_SCHEDULE_DELAY` environment variable. Defaults to 5000. | `OTEL_BSP_SCHEDULE_DELAY` | +| `instrumentation_config` | Specifies a dictionary of kwargs that will be applied to instrumentation configuration. You can specify which instrumentation you want to configure by name in the key field and value as a dictionary representing `kwargs` for the corresponding instrumentation. Can also be set via the `APPLICATIONINSIGHTS_INSTRUMENTATION_CONFIG` environment variable. Refer to the `Supported Library` section [above](#officially-supported-instrumentations) for the list of suppoprted library names. | `APPLICATIONINSIGHTS_INSTRUMENTATION_CONFIG` | + +Example for use of `instrumentation_config`: ```python ... configure_azure_monitor( From c05bc89eeb604ae3c7aa552c181361a98bb52676 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Mon, 27 Mar 2023 10:30:21 -0700 Subject: [PATCH 12/19] Add error handling to casts --- azure-monitor-opentelemetry/README.md | 20 +++--- .../opentelemetry/util/configurations.py | 65 ++++++++++++------- .../tests/configuration/test_util.py | 46 ++++++++++--- 3 files changed, 89 insertions(+), 42 deletions(-) diff --git a/azure-monitor-opentelemetry/README.md b/azure-monitor-opentelemetry/README.md index 8a51f013..109b6f8b 100644 --- a/azure-monitor-opentelemetry/README.md +++ b/azure-monitor-opentelemetry/README.md @@ -55,19 +55,19 @@ You can use `configure_azure_monitor` to set up instrumentation for your app to | Parameter | Description | Environment Variable | |-------------------|----------------------------------------------------|----------------------| | `connection_string` | The [connection string][connection_string_doc] for your Application Insights resource. The connection string will be automatically populated from the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable if not explicitly passed in. | `APPLICATIONINSIGHTS_CONNECTION_STRING` | -| `exclude_instrumentations` | By default, all supported [instrumentations](#officially-supported-instrumentations) are enabled to collect telemetry. Specify instrumentations you do not want to enable to collect telemetry by passing in a comma separated list of instrumented library names. Can also be set via the `APPLICATIONINSIGHTS_EXCLUDE_INSTRUMENTATIONS` environment variable. e.g. `["requests", "flask"]` | `APPLICATIONINSIGHTS_EXCLUDE_INSTRUMENTATIONS` | +| `exclude_instrumentations` | By default, all supported [instrumentations](#officially-supported-instrumentations) are enabled to collect telemetry. Specify instrumentations you do not want to enable to collect telemetry by passing in a comma separated list of instrumented library names. e.g. `["requests", "flask"]` | `APPLICATIONINSIGHTS_EXCLUDE_INSTRUMENTATIONS` | | `resource` | Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior. This include configuration via the `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_SERVICE_NAME` environment variables. | `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_SERVICE_NAME` | -| `disable_logging` | If set to `True`, disables collection and export of logging telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_LOGGING` environment variable. Defaults to `False`. | `APPLICATIONINSIGHTS_DISABLE_LOGGING` | -| `disable_metrics` | If set to `True`, disables collection and export of metric telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_METRICS` environment variable. Defaults to `False`. | `APPLICATIONINSIGHTS_DISABLE_METRICS` | -| `disable_tracing` | If set to `True`, disables collection and export of distributed tracing telemetry. Can also be set via the `APPLICATIONINSIGHTS_DISABLE_TRACING` environment variable. Defaults to `False`. | `APPLICATIONINSIGHTS_DISABLE_TRACING` | -| `logging_level` | Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. Can also be set via the `OTEL_LOG_LEVEL` environment variable. This environment variable should be set to the number that represents the log leval, not a string representing that log level's name. Defaults to 0 which is logging.NOTSET. | `OTEL_LOG_LEVEL` | -| `logger_name` | Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Can also be set via the `APPLICATIONINSIGHTS_LOGGER_NAME` environment variable. Defaults to "" which corresponds to the root logger. | `APPLICATIONINSIGHTS_LOGGER_NAME` | -| `logging_export_interval_ms`| Specifies the logging export interval in milliseconds. Can also be set via the `OTEL_BLRP_SCHEDULE_DELAY` environment variable. Defaults to 5000. | `OTEL_BLRP_SCHEDULE_DELAY` | +| `disable_logging` | If set to `True`, disables collection and export of logging telemetry. Defaults to `False`. | `APPLICATIONINSIGHTS_DISABLE_LOGGING` | +| `disable_metrics` | If set to `True`, disables collection and export of metric telemetry. Defaults to `False`. | `APPLICATIONINSIGHTS_DISABLE_METRICS` | +| `disable_tracing` | If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`. | `APPLICATIONINSIGHTS_DISABLE_TRACING` | +| `logging_level` | Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. In order to utilize the `OTEL_LOG_LEVEL` environment variable, set it to the number that represents the log leval, not a string representing that log level's name. For example, set to `30` for `logging.WARN`.Defaults to 0 which is `logging.NOTSET`. | `OTEL_LOG_LEVEL` | +| `logger_name` | Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Defaults to "" which corresponds to the root logger. | `APPLICATIONINSIGHTS_LOGGER_NAME` | +| `logging_export_interval_ms`| Specifies the logging export interval in milliseconds. Defaults to 5000. | `OTEL_BLRP_SCHEDULE_DELAY` | | `metric_readers` | Specifies the [metric readers][ot_metric_reader] that you would like to use for your metric pipeline. Accepts a list of [metric readers][ot_sdk_python_metric_reader]. | | | `views` | Specifies the list of [views][opentelemetry_spec_view] to configure for the metric pipeline. See [here][ot_sdk_python_view_examples] for example usage. | | -| `sampling_ratio` | Specifies the ratio of distributed tracing telemetry to be [sampled][application_insights_sampling]. Accepted values are in the range [0,1]. Can also be set with the `OTEL_TRACES_SAMPLER_ARG` environment variable. Defaults to 1.0, meaning no telemetry is sampled out. | `OTEL_TRACES_SAMPLER_ARG` | -| `tracing_export_interval_ms`| Specifies the distributed tracing export interval in milliseconds. Can also be set via the `OTEL_BSP_SCHEDULE_DELAY` environment variable. Defaults to 5000. | `OTEL_BSP_SCHEDULE_DELAY` | -| `instrumentation_config` | Specifies a dictionary of kwargs that will be applied to instrumentation configuration. You can specify which instrumentation you want to configure by name in the key field and value as a dictionary representing `kwargs` for the corresponding instrumentation. Can also be set via the `APPLICATIONINSIGHTS_INSTRUMENTATION_CONFIG` environment variable. Refer to the `Supported Library` section [above](#officially-supported-instrumentations) for the list of suppoprted library names. | `APPLICATIONINSIGHTS_INSTRUMENTATION_CONFIG` | +| `sampling_ratio` | Specifies the ratio of distributed tracing telemetry to be [sampled][application_insights_sampling]. Accepted values are in the range [0,1]. Defaults to 1.0, meaning no telemetry is sampled out. | `OTEL_TRACES_SAMPLER_ARG` | +| `tracing_export_interval_ms`| Specifies the distributed tracing export interval in milliseconds. Defaults to 5000. | `OTEL_BSP_SCHEDULE_DELAY` | +| `instrumentation_config` | Specifies a dictionary of kwargs that will be applied to instrumentation configuration. You can specify which instrumentation you want to configure by name in the key field and value as a dictionary representing `kwargs` for the corresponding instrumentation. Use JSON format if setting the `APPLICATIONINSIGHTS_INSTRUMENTATION_CONFIG` environment variable. Refer to the `Supported Library` section [above](#officially-supported-instrumentations) for the list of suppoprted library names. | `APPLICATIONINSIGHTS_INSTRUMENTATION_CONFIG` | Example for use of `instrumentation_config`: ```python diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py index 3f3b1ef6..a36fab14 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py @@ -5,7 +5,7 @@ # -------------------------------------------------------------------------- from json import loads -from logging import NOTSET +from logging import NOTSET, getLogger from os import environ from typing import Dict @@ -30,6 +30,10 @@ ) _CONFIGURATION_ENV_VAR_PREFIX = "APPLICATIONINSIGHTS_" +_INVALID_JSON_MESSAGE = "Value of %s must be valid JSON. Defaulting to %s: %s" +_INVALID_BOOLEAN_MESSAGE = "Value of %s must be a boolean. Defaulting to %s: %s" +_INVALID_INT_MESSAGE = "Value of %s must be an integer. Defaulting to %s: %s" +_INVALID_FLOAT_MESSAGE = "Value of %s must be a float. Defaulting to %s: %s" def _get_env_var_name(arg): @@ -47,14 +51,14 @@ def _get_env_var_name(arg): LOGGER_NAME_ENV_VAR = _get_env_var_name(LOGGER_NAME_ARG) # Speced out but unused by OTel SDK as of 1.15.0 LOGGING_EXPORT_INTERVAL_MS_ENV_VAR = "OTEL_BLRP_SCHEDULE_DELAY" -# TODO: leave as private until env var configuration logic is designed -_METRIC_READERS_ENV_VAR = _get_env_var_name(METRIC_READERS_ARG) -_VIEWS_ENV_VAR = _get_env_var_name(VIEWS_ARG) # TODO: remove when sampler uses env var instead SAMPLING_RATIO_ENV_VAR = OTEL_TRACES_SAMPLER_ARG INSTRUMENTATION_CONFIG_ENV_VAR = _get_env_var_name(INSTRUMENTATION_CONFIG_ARG) +_logger = getLogger(__name__) + + def _get_configurations(**kwargs) -> Dict[str, ConfigurationValue]: configurations = {} @@ -87,7 +91,10 @@ def _default_exclude_instrumentations(configurations): if EXCLUDE_INSTRUMENTATIONS_ARG not in configurations: default = [] if EXCLUDE_INSTRUMENTATIONS_ENV_VAR in environ: - default = loads(environ[EXCLUDE_INSTRUMENTATIONS_ENV_VAR]) + try: + default = loads(environ[EXCLUDE_INSTRUMENTATIONS_ENV_VAR]) + except ValueError as e: + _logger.error(_INVALID_JSON_MESSAGE % (EXCLUDE_INSTRUMENTATIONS_ENV_VAR, default, e)) configurations[EXCLUDE_INSTRUMENTATIONS_ARG] = default @@ -95,7 +102,10 @@ def _default_disable_logging(configurations): if DISABLE_LOGGING_ARG not in configurations: default = False if DISABLE_LOGGING_ENV_VAR in environ: - default = bool(environ[DISABLE_LOGGING_ENV_VAR]) + try: + default = bool(environ[DISABLE_LOGGING_ENV_VAR]) + except ValueError as e: + _logger.error(_INVALID_BOOLEAN_MESSAGE % (DISABLE_LOGGING_ENV_VAR, default, e)) configurations[DISABLE_LOGGING_ARG] = default @@ -103,7 +113,10 @@ def _default_disable_metrics(configurations): if DISABLE_METRICS_ARG not in configurations: default = False if DISABLE_METRICS_ENV_VAR in environ: - default = bool(environ[DISABLE_METRICS_ENV_VAR]) + try: + default = bool(environ[DISABLE_METRICS_ENV_VAR]) + except ValueError as e: + _logger.error(_INVALID_BOOLEAN_MESSAGE % (DISABLE_METRICS_ENV_VAR, default, e)) configurations[DISABLE_METRICS_ARG] = default @@ -111,7 +124,10 @@ def _default_disable_tracing(configurations): if DISABLE_TRACING_ARG not in configurations: default = False if DISABLE_TRACING_ENV_VAR in environ: - default = bool(environ[DISABLE_TRACING_ENV_VAR]) + try: + default = bool(environ[DISABLE_TRACING_ENV_VAR]) + except ValueError as e: + _logger.error(_INVALID_BOOLEAN_MESSAGE % (DISABLE_TRACING_ENV_VAR, default, e)) configurations[DISABLE_TRACING_ARG] = default @@ -119,8 +135,11 @@ def _default_logging_level(configurations): if LOGGING_LEVEL_ARG not in configurations: default = NOTSET if LOGGING_LEVEL_ENV_VAR in environ: - default = int(environ[LOGGING_LEVEL_ENV_VAR]) # TODO: Match OTel env var usage when it is determined. + try: + default = int(environ[LOGGING_LEVEL_ENV_VAR]) + except ValueError as e: + _logger.error(_INVALID_INT_MESSAGE % (LOGGING_LEVEL_ENV_VAR, default, e)) configurations[LOGGING_LEVEL_ARG] = default @@ -136,27 +155,21 @@ def _default_logging_export_interval_ms(configurations): if LOGGING_EXPORT_INTERVAL_MS_ARG not in configurations: default = 5000 if LOGGING_EXPORT_INTERVAL_MS_ENV_VAR in environ: - default = int(environ[LOGGING_EXPORT_INTERVAL_MS_ENV_VAR]) + try: + 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)) configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] = default -# TODO: Design metric readers env var usage def _default_metric_readers(configurations): if METRIC_READERS_ARG not in configurations: - default = [] - if _METRIC_READERS_ENV_VAR in environ: - default = loads(environ[_METRIC_READERS_ENV_VAR]) - configurations[METRIC_READERS_ARG] = default + configurations[METRIC_READERS_ARG] = [] -# TODO: Design views env var usage def _default_views(configurations): if VIEWS_ARG not in configurations: - # TODO tuple or list - default = [] - if _VIEWS_ENV_VAR in environ: - default = loads(environ[_VIEWS_ENV_VAR]) - configurations[VIEWS_ARG] = default + configurations[VIEWS_ARG] = [] # TODO: remove when sampler uses env var instead @@ -164,7 +177,10 @@ def _default_sampling_ratio(configurations): if SAMPLING_RATIO_ARG not in configurations: default = 1.0 if SAMPLING_RATIO_ENV_VAR in environ: - default = float(environ[SAMPLING_RATIO_ENV_VAR]) + try: + default = float(environ[SAMPLING_RATIO_ENV_VAR]) + except ValueError as e: + _logger.error(_INVALID_FLOAT_MESSAGE % (SAMPLING_RATIO_ENV_VAR, default, e)) configurations[SAMPLING_RATIO_ARG] = default @@ -177,5 +193,8 @@ def _default_instrumentation_config(configurations): if INSTRUMENTATION_CONFIG_ARG not in configurations: default = {} if INSTRUMENTATION_CONFIG_ENV_VAR in environ: - default = loads(environ[INSTRUMENTATION_CONFIG_ENV_VAR]) + try: + default = loads(environ[INSTRUMENTATION_CONFIG_ENV_VAR]) + except ValueError as e: + _logger.error(_INVALID_JSON_MESSAGE % (INSTRUMENTATION_CONFIG_ENV_VAR, default, e)) configurations[INSTRUMENTATION_CONFIG_ARG] = default diff --git a/azure-monitor-opentelemetry/tests/configuration/test_util.py b/azure-monitor-opentelemetry/tests/configuration/test_util.py index b886d91a..df8ad42c 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_util.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_util.py @@ -17,8 +17,6 @@ from unittest.mock import patch from azure.monitor.opentelemetry.util.configurations import ( - _METRIC_READERS_ENV_VAR, - _VIEWS_ENV_VAR, DISABLE_LOGGING_ENV_VAR, DISABLE_METRICS_ENV_VAR, DISABLE_TRACING_ENV_VAR, @@ -118,8 +116,6 @@ def test_get_configurations_validation(self): LOGGING_LEVEL_ENV_VAR: "30", LOGGER_NAME_ENV_VAR: "opentelemetry", LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "10000", - _METRIC_READERS_ENV_VAR: '["metricReader1", "metricReader2"]', - _VIEWS_ENV_VAR: '["view1", "view2"]', SAMPLING_RATIO_ENV_VAR: "0.5", INSTRUMENTATION_CONFIG_ENV_VAR: """{ "flask": { @@ -143,12 +139,44 @@ def test_get_configurations_env_vars(self): self.assertEqual(configurations["sampling_ratio"], 0.5) self.assertEqual(configurations["tracing_export_interval_ms"], None) self.assertEqual(configurations["logging_export_interval_ms"], 10000) - self.assertEqual( - configurations["metric_readers"], - ["metricReader1", "metricReader2"], - ) - self.assertEqual(configurations["views"], ["view1", "view2"]) + self.assertEqual(configurations["metric_readers"], []) + self.assertEqual(configurations["views"], []) self.assertEqual( configurations["instrumentation_config"], {"flask": {"excluded_urls": "http://localhost:8080/ignore"}}, ) + + @patch.dict( + "os.environ", + { + EXCLUDE_INSTRUMENTATIONS_ENV_VAR: '"flask', + DISABLE_LOGGING_ENV_VAR: "one", + DISABLE_METRICS_ENV_VAR: "", + DISABLE_TRACING_ENV_VAR: "0.5", + LOGGING_LEVEL_ENV_VAR: "Thirty", + LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "Ten Thousand", + SAMPLING_RATIO_ENV_VAR: "Half", + INSTRUMENTATION_CONFIG_ENV_VAR: """{ + "flask": + "excluded_urls": "http://localhost:8080/ignore" + }""", + }, + clear=True, + ) + def test_get_configurations_env_vars_validation(self): + configurations = _get_configurations() + + self.assertTrue("connection_string" not in configurations) + self.assertEqual(configurations["exclude_instrumentations"], []) + # self.assertEqual(configurations["disable_logging"], False) + self.assertEqual(configurations["disable_metrics"], False) + # self.assertEqual(configurations["disable_tracing"], False) + self.assertEqual(configurations["logging_level"], NOTSET) + self.assertEqual(configurations["logger_name"], "") + self.assertTrue("resource" not in configurations) + self.assertEqual(configurations["sampling_ratio"], 1.0) + self.assertEqual(configurations["tracing_export_interval_ms"], None) + self.assertEqual(configurations["logging_export_interval_ms"], 5000) + self.assertEqual(configurations["metric_readers"], []) + self.assertEqual(configurations["views"], []) + self.assertEqual(configurations["instrumentation_config"], {}) From 7e58b228ae2e1df34c6b2c51ea41d4e6a3ba16b7 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Mon, 27 Mar 2023 14:38:09 -0700 Subject: [PATCH 13/19] Added boolean tests --- .../opentelemetry/util/configurations.py | 46 +++++++++------ .../tests/configuration/test_util.py | 58 ++++++++++++++++++- 2 files changed, 84 insertions(+), 20 deletions(-) diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py index a36fab14..c9957c3b 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py @@ -31,7 +31,6 @@ _CONFIGURATION_ENV_VAR_PREFIX = "APPLICATIONINSIGHTS_" _INVALID_JSON_MESSAGE = "Value of %s must be valid JSON. Defaulting to %s: %s" -_INVALID_BOOLEAN_MESSAGE = "Value of %s must be a boolean. Defaulting to %s: %s" _INVALID_INT_MESSAGE = "Value of %s must be an integer. Defaulting to %s: %s" _INVALID_FLOAT_MESSAGE = "Value of %s must be a float. Defaulting to %s: %s" @@ -94,7 +93,10 @@ def _default_exclude_instrumentations(configurations): try: default = loads(environ[EXCLUDE_INSTRUMENTATIONS_ENV_VAR]) except ValueError as e: - _logger.error(_INVALID_JSON_MESSAGE % (EXCLUDE_INSTRUMENTATIONS_ENV_VAR, default, e)) + _logger.error( + _INVALID_JSON_MESSAGE + % (EXCLUDE_INSTRUMENTATIONS_ENV_VAR, default, e) + ) configurations[EXCLUDE_INSTRUMENTATIONS_ARG] = default @@ -102,10 +104,9 @@ def _default_disable_logging(configurations): if DISABLE_LOGGING_ARG not in configurations: default = False if DISABLE_LOGGING_ENV_VAR in environ: - try: - default = bool(environ[DISABLE_LOGGING_ENV_VAR]) - except ValueError as e: - _logger.error(_INVALID_BOOLEAN_MESSAGE % (DISABLE_LOGGING_ENV_VAR, default, e)) + env_var = environ[DISABLE_LOGGING_ENV_VAR] + if env_var.lower() == "true": + default = True configurations[DISABLE_LOGGING_ARG] = default @@ -113,10 +114,9 @@ def _default_disable_metrics(configurations): if DISABLE_METRICS_ARG not in configurations: default = False if DISABLE_METRICS_ENV_VAR in environ: - try: - default = bool(environ[DISABLE_METRICS_ENV_VAR]) - except ValueError as e: - _logger.error(_INVALID_BOOLEAN_MESSAGE % (DISABLE_METRICS_ENV_VAR, default, e)) + env_var = environ[DISABLE_METRICS_ENV_VAR] + if env_var.lower() == "true": + default = True configurations[DISABLE_METRICS_ARG] = default @@ -124,10 +124,9 @@ def _default_disable_tracing(configurations): if DISABLE_TRACING_ARG not in configurations: default = False if DISABLE_TRACING_ENV_VAR in environ: - try: - default = bool(environ[DISABLE_TRACING_ENV_VAR]) - except ValueError as e: - _logger.error(_INVALID_BOOLEAN_MESSAGE % (DISABLE_TRACING_ENV_VAR, default, e)) + env_var = environ[DISABLE_TRACING_ENV_VAR] + if env_var.lower() == "true": + default = True configurations[DISABLE_TRACING_ARG] = default @@ -139,7 +138,9 @@ def _default_logging_level(configurations): try: default = int(environ[LOGGING_LEVEL_ENV_VAR]) except ValueError as e: - _logger.error(_INVALID_INT_MESSAGE % (LOGGING_LEVEL_ENV_VAR, default, e)) + _logger.error( + _INVALID_INT_MESSAGE % (LOGGING_LEVEL_ENV_VAR, default, e) + ) configurations[LOGGING_LEVEL_ARG] = default @@ -158,7 +159,10 @@ def _default_logging_export_interval_ms(configurations): try: 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)) + _logger.error( + _INVALID_INT_MESSAGE + % (LOGGING_EXPORT_INTERVAL_MS_ENV_VAR, default, e) + ) configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] = default @@ -180,7 +184,10 @@ def _default_sampling_ratio(configurations): try: default = float(environ[SAMPLING_RATIO_ENV_VAR]) except ValueError as e: - _logger.error(_INVALID_FLOAT_MESSAGE % (SAMPLING_RATIO_ENV_VAR, default, e)) + _logger.error( + _INVALID_FLOAT_MESSAGE + % (SAMPLING_RATIO_ENV_VAR, default, e) + ) configurations[SAMPLING_RATIO_ARG] = default @@ -196,5 +203,8 @@ def _default_instrumentation_config(configurations): try: default = loads(environ[INSTRUMENTATION_CONFIG_ENV_VAR]) except ValueError as e: - _logger.error(_INVALID_JSON_MESSAGE % (INSTRUMENTATION_CONFIG_ENV_VAR, default, e)) + _logger.error( + _INVALID_JSON_MESSAGE + % (INSTRUMENTATION_CONFIG_ENV_VAR, default, e) + ) configurations[INSTRUMENTATION_CONFIG_ARG] = default diff --git a/azure-monitor-opentelemetry/tests/configuration/test_util.py b/azure-monitor-opentelemetry/tests/configuration/test_util.py index df8ad42c..40901dfe 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_util.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_util.py @@ -168,9 +168,63 @@ def test_get_configurations_env_vars_validation(self): self.assertTrue("connection_string" not in configurations) self.assertEqual(configurations["exclude_instrumentations"], []) - # self.assertEqual(configurations["disable_logging"], False) + self.assertEqual(configurations["disable_logging"], False) self.assertEqual(configurations["disable_metrics"], False) - # self.assertEqual(configurations["disable_tracing"], False) + self.assertEqual(configurations["disable_tracing"], False) + self.assertEqual(configurations["logging_level"], NOTSET) + self.assertEqual(configurations["logger_name"], "") + self.assertTrue("resource" not in configurations) + self.assertEqual(configurations["sampling_ratio"], 1.0) + self.assertEqual(configurations["tracing_export_interval_ms"], None) + self.assertEqual(configurations["logging_export_interval_ms"], 5000) + self.assertEqual(configurations["metric_readers"], []) + self.assertEqual(configurations["views"], []) + self.assertEqual(configurations["instrumentation_config"], {}) + + @patch.dict( + "os.environ", + { + DISABLE_LOGGING_ENV_VAR: "false", + DISABLE_METRICS_ENV_VAR: "False", + DISABLE_TRACING_ENV_VAR: "FALSE", + }, + clear=True, + ) + def test_get_configurations_env_vars_false_bools(self): + configurations = _get_configurations() + + self.assertTrue("connection_string" not in configurations) + self.assertEqual(configurations["exclude_instrumentations"], []) + self.assertEqual(configurations["disable_logging"], False) + self.assertEqual(configurations["disable_metrics"], False) + self.assertEqual(configurations["disable_tracing"], False) + self.assertEqual(configurations["logging_level"], NOTSET) + self.assertEqual(configurations["logger_name"], "") + self.assertTrue("resource" not in configurations) + self.assertEqual(configurations["sampling_ratio"], 1.0) + self.assertEqual(configurations["tracing_export_interval_ms"], None) + self.assertEqual(configurations["logging_export_interval_ms"], 5000) + self.assertEqual(configurations["metric_readers"], []) + self.assertEqual(configurations["views"], []) + self.assertEqual(configurations["instrumentation_config"], {}) + + @patch.dict( + "os.environ", + { + DISABLE_LOGGING_ENV_VAR: "true", + DISABLE_METRICS_ENV_VAR: "True", + DISABLE_TRACING_ENV_VAR: "TRUE", + }, + clear=True, + ) + def test_get_configurations_env_vars_false_bools(self): + configurations = _get_configurations() + + self.assertTrue("connection_string" not in configurations) + self.assertEqual(configurations["exclude_instrumentations"], []) + self.assertEqual(configurations["disable_logging"], True) + self.assertEqual(configurations["disable_metrics"], True) + self.assertEqual(configurations["disable_tracing"], True) self.assertEqual(configurations["logging_level"], NOTSET) self.assertEqual(configurations["logger_name"], "") self.assertTrue("resource" not in configurations) From b992e18b4867e7ceb4557dd9f1368c96f08df728 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 29 Mar 2023 11:08:58 -0700 Subject: [PATCH 14/19] Removed documentation for Azure Monitor env vars --- azure-monitor-opentelemetry/README.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/azure-monitor-opentelemetry/README.md b/azure-monitor-opentelemetry/README.md index 109b6f8b..cfc551a0 100644 --- a/azure-monitor-opentelemetry/README.md +++ b/azure-monitor-opentelemetry/README.md @@ -55,19 +55,19 @@ You can use `configure_azure_monitor` to set up instrumentation for your app to | Parameter | Description | Environment Variable | |-------------------|----------------------------------------------------|----------------------| | `connection_string` | The [connection string][connection_string_doc] for your Application Insights resource. The connection string will be automatically populated from the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable if not explicitly passed in. | `APPLICATIONINSIGHTS_CONNECTION_STRING` | -| `exclude_instrumentations` | By default, all supported [instrumentations](#officially-supported-instrumentations) are enabled to collect telemetry. Specify instrumentations you do not want to enable to collect telemetry by passing in a comma separated list of instrumented library names. e.g. `["requests", "flask"]` | `APPLICATIONINSIGHTS_EXCLUDE_INSTRUMENTATIONS` | +| `exclude_instrumentations` | By default, all supported [instrumentations](#officially-supported-instrumentations) are enabled to collect telemetry. Specify instrumentations you do not want to enable to collect telemetry by passing in a comma separated list of instrumented library names. e.g. `["requests", "flask"]` | | | `resource` | Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior. This include configuration via the `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_SERVICE_NAME` environment variables. | `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_SERVICE_NAME` | -| `disable_logging` | If set to `True`, disables collection and export of logging telemetry. Defaults to `False`. | `APPLICATIONINSIGHTS_DISABLE_LOGGING` | -| `disable_metrics` | If set to `True`, disables collection and export of metric telemetry. Defaults to `False`. | `APPLICATIONINSIGHTS_DISABLE_METRICS` | -| `disable_tracing` | If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`. | `APPLICATIONINSIGHTS_DISABLE_TRACING` | -| `logging_level` | Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. In order to utilize the `OTEL_LOG_LEVEL` environment variable, set it to the number that represents the log leval, not a string representing that log level's name. For example, set to `30` for `logging.WARN`.Defaults to 0 which is `logging.NOTSET`. | `OTEL_LOG_LEVEL` | -| `logger_name` | Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Defaults to "" which corresponds to the root logger. | `APPLICATIONINSIGHTS_LOGGER_NAME` | +| `disable_logging` | If set to `True`, disables collection and export of logging telemetry. Defaults to `False`. | | +| `disable_metrics` | If set to `True`, disables collection and export of metric telemetry. Defaults to `False`. | | +| `disable_tracing` | If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`. | | +| `logging_level` | Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. In order to utilize the `OTEL_LOG_LEVEL` environment variable, set it to the number that represents the log leval, not a string representing that log level's name. For example, set to `30` for `logging.WARN`. Defaults to 0 which is `logging.NOTSET`. | `OTEL_LOG_LEVEL` | +| `logger_name` | Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Defaults to "" which corresponds to the root logger. | | | `logging_export_interval_ms`| Specifies the logging export interval in milliseconds. Defaults to 5000. | `OTEL_BLRP_SCHEDULE_DELAY` | | `metric_readers` | Specifies the [metric readers][ot_metric_reader] that you would like to use for your metric pipeline. Accepts a list of [metric readers][ot_sdk_python_metric_reader]. | | | `views` | Specifies the list of [views][opentelemetry_spec_view] to configure for the metric pipeline. See [here][ot_sdk_python_view_examples] for example usage. | | | `sampling_ratio` | Specifies the ratio of distributed tracing telemetry to be [sampled][application_insights_sampling]. Accepted values are in the range [0,1]. Defaults to 1.0, meaning no telemetry is sampled out. | `OTEL_TRACES_SAMPLER_ARG` | | `tracing_export_interval_ms`| Specifies the distributed tracing export interval in milliseconds. Defaults to 5000. | `OTEL_BSP_SCHEDULE_DELAY` | -| `instrumentation_config` | Specifies a dictionary of kwargs that will be applied to instrumentation configuration. You can specify which instrumentation you want to configure by name in the key field and value as a dictionary representing `kwargs` for the corresponding instrumentation. Use JSON format if setting the `APPLICATIONINSIGHTS_INSTRUMENTATION_CONFIG` environment variable. Refer to the `Supported Library` section [above](#officially-supported-instrumentations) for the list of suppoprted library names. | `APPLICATIONINSIGHTS_INSTRUMENTATION_CONFIG` | +| `instrumentation_config` | Specifies a dictionary of kwargs that will be applied to instrumentation configuration. You can specify which instrumentation you want to configure by name in the key field and value as a dictionary representing `kwargs` for the corresponding instrumentation. Refer to the `Supported Library` section [above](#officially-supported-instrumentations) for the list of supported library names. | | Example for use of `instrumentation_config`: ```python @@ -88,8 +88,6 @@ configure_azure_monitor( Take a look at the specific [instrumenation][ot_instrumentations] documentation for available configurations. -When configuring list or dictionary arguments via their respective environment variables, the environment variable values with be interpretted as JSON objects. - #### Azure monitor OpenTelemetry Exporter configurations You can pass Azure monitor OpenTelemetry exporter configuration parameters directly into `configure_azure_monitor`. See additional [configuration related to exporting here][exporter_configuration_docs]. From 7af89891a7d2786599435c67e4d8fbb74831421e Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 29 Mar 2023 12:56:18 -0700 Subject: [PATCH 15/19] lint --- azure-monitor-opentelemetry/tests/configuration/test_util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-monitor-opentelemetry/tests/configuration/test_util.py b/azure-monitor-opentelemetry/tests/configuration/test_util.py index 40901dfe..18941ffc 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_util.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_util.py @@ -190,7 +190,7 @@ def test_get_configurations_env_vars_validation(self): }, clear=True, ) - def test_get_configurations_env_vars_false_bools(self): + def test_get_configurations_env_vars_false(self): configurations = _get_configurations() self.assertTrue("connection_string" not in configurations) @@ -217,7 +217,7 @@ def test_get_configurations_env_vars_false_bools(self): }, clear=True, ) - def test_get_configurations_env_vars_false_bools(self): + def test_get_configurations_env_vars_true(self): configurations = _get_configurations() self.assertTrue("connection_string" not in configurations) From a5f9371b2550644baf4d0f222e177c496c568a72 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 29 Mar 2023 16:15:59 -0700 Subject: [PATCH 16/19] Changed views default to match otel --- .../azure/monitor/opentelemetry/util/configurations.py | 2 +- .../tests/configuration/test_util.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py index c9957c3b..f6032a56 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py @@ -173,7 +173,7 @@ def _default_metric_readers(configurations): def _default_views(configurations): if VIEWS_ARG not in configurations: - configurations[VIEWS_ARG] = [] + configurations[VIEWS_ARG] = () # TODO: remove when sampler uses env var instead diff --git a/azure-monitor-opentelemetry/tests/configuration/test_util.py b/azure-monitor-opentelemetry/tests/configuration/test_util.py index 18941ffc..0d97df15 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_util.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_util.py @@ -95,7 +95,7 @@ def test_get_configurations_defaults(self): self.assertEqual(configurations["tracing_export_interval_ms"], None) self.assertEqual(configurations["logging_export_interval_ms"], 5000) self.assertEqual(configurations["metric_readers"], []) - self.assertEqual(configurations["views"], []) + self.assertEqual(configurations["views"], ()) self.assertEqual(configurations["instrumentation_config"], {}) def test_get_configurations_validation(self): @@ -140,7 +140,7 @@ def test_get_configurations_env_vars(self): self.assertEqual(configurations["tracing_export_interval_ms"], None) self.assertEqual(configurations["logging_export_interval_ms"], 10000) self.assertEqual(configurations["metric_readers"], []) - self.assertEqual(configurations["views"], []) + self.assertEqual(configurations["views"], ()) self.assertEqual( configurations["instrumentation_config"], {"flask": {"excluded_urls": "http://localhost:8080/ignore"}}, @@ -178,7 +178,7 @@ def test_get_configurations_env_vars_validation(self): self.assertEqual(configurations["tracing_export_interval_ms"], None) self.assertEqual(configurations["logging_export_interval_ms"], 5000) self.assertEqual(configurations["metric_readers"], []) - self.assertEqual(configurations["views"], []) + self.assertEqual(configurations["views"], ()) self.assertEqual(configurations["instrumentation_config"], {}) @patch.dict( @@ -205,7 +205,7 @@ def test_get_configurations_env_vars_false(self): self.assertEqual(configurations["tracing_export_interval_ms"], None) self.assertEqual(configurations["logging_export_interval_ms"], 5000) self.assertEqual(configurations["metric_readers"], []) - self.assertEqual(configurations["views"], []) + self.assertEqual(configurations["views"], ()) self.assertEqual(configurations["instrumentation_config"], {}) @patch.dict( @@ -232,5 +232,5 @@ def test_get_configurations_env_vars_true(self): self.assertEqual(configurations["tracing_export_interval_ms"], None) self.assertEqual(configurations["logging_export_interval_ms"], 5000) self.assertEqual(configurations["metric_readers"], []) - self.assertEqual(configurations["views"], []) + self.assertEqual(configurations["views"], ()) self.assertEqual(configurations["instrumentation_config"], {}) From 6f5b42dc25b08aeb1b7bf5295974bb513699ea85 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Thu, 30 Mar 2023 13:42:27 -0700 Subject: [PATCH 17/19] Removed azmon env vars --- azure-monitor-opentelemetry/README.md | 2 +- .../opentelemetry/util/configurations.py | 93 ++---------------- .../tests/configuration/test_util.py | 94 +------------------ 3 files changed, 15 insertions(+), 174 deletions(-) diff --git a/azure-monitor-opentelemetry/README.md b/azure-monitor-opentelemetry/README.md index cfc551a0..25c7ee3d 100644 --- a/azure-monitor-opentelemetry/README.md +++ b/azure-monitor-opentelemetry/README.md @@ -60,7 +60,7 @@ You can use `configure_azure_monitor` to set up instrumentation for your app to | `disable_logging` | If set to `True`, disables collection and export of logging telemetry. Defaults to `False`. | | | `disable_metrics` | If set to `True`, disables collection and export of metric telemetry. Defaults to `False`. | | | `disable_tracing` | If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`. | | -| `logging_level` | Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. In order to utilize the `OTEL_LOG_LEVEL` environment variable, set it to the number that represents the log leval, not a string representing that log level's name. For example, set to `30` for `logging.WARN`. Defaults to 0 which is `logging.NOTSET`. | `OTEL_LOG_LEVEL` | +| `logging_level` | Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. Defaults to 0 which is `logging.NOTSET`. | | | `logger_name` | Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Defaults to "" which corresponds to the root logger. | | | `logging_export_interval_ms`| Specifies the logging export interval in milliseconds. Defaults to 5000. | `OTEL_BLRP_SCHEDULE_DELAY` | | `metric_readers` | Specifies the [metric readers][ot_metric_reader] that you would like to use for your metric pipeline. Accepts a list of [metric readers][ot_sdk_python_metric_reader]. | | diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py index f6032a56..1df8c387 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py @@ -4,7 +4,6 @@ # license information. # -------------------------------------------------------------------------- -from json import loads from logging import NOTSET, getLogger from os import environ from typing import Dict @@ -24,35 +23,15 @@ VIEWS_ARG, ) from azure.monitor.opentelemetry._types import ConfigurationValue -from opentelemetry.sdk.environment_variables import ( - OTEL_LOG_LEVEL, - OTEL_TRACES_SAMPLER_ARG, -) +from opentelemetry.sdk.environment_variables import OTEL_TRACES_SAMPLER_ARG -_CONFIGURATION_ENV_VAR_PREFIX = "APPLICATIONINSIGHTS_" -_INVALID_JSON_MESSAGE = "Value of %s must be valid JSON. Defaulting to %s: %s" -_INVALID_INT_MESSAGE = "Value of %s must be an integer. Defaulting to %s: %s" _INVALID_FLOAT_MESSAGE = "Value of %s must be a float. Defaulting to %s: %s" -def _get_env_var_name(arg): - return _CONFIGURATION_ENV_VAR_PREFIX + arg.upper() - - -EXCLUDE_INSTRUMENTATIONS_ENV_VAR = _get_env_var_name( - EXCLUDE_INSTRUMENTATIONS_ARG -) -DISABLE_LOGGING_ENV_VAR = _get_env_var_name(DISABLE_LOGGING_ARG) -DISABLE_METRICS_ENV_VAR = _get_env_var_name(DISABLE_METRICS_ARG) -DISABLE_TRACING_ENV_VAR = _get_env_var_name(DISABLE_TRACING_ARG) -# Speced out but unused by OTel SDK as of 1.15.0 -LOGGING_LEVEL_ENV_VAR = OTEL_LOG_LEVEL -LOGGER_NAME_ENV_VAR = _get_env_var_name(LOGGER_NAME_ARG) # Speced out but unused by OTel SDK as of 1.15.0 LOGGING_EXPORT_INTERVAL_MS_ENV_VAR = "OTEL_BLRP_SCHEDULE_DELAY" # TODO: remove when sampler uses env var instead SAMPLING_RATIO_ENV_VAR = OTEL_TRACES_SAMPLER_ARG -INSTRUMENTATION_CONFIG_ENV_VAR = _get_env_var_name(INSTRUMENTATION_CONFIG_ARG) _logger = getLogger(__name__) @@ -88,82 +67,37 @@ def _get_configurations(**kwargs) -> Dict[str, ConfigurationValue]: def _default_exclude_instrumentations(configurations): if EXCLUDE_INSTRUMENTATIONS_ARG not in configurations: - default = [] - if EXCLUDE_INSTRUMENTATIONS_ENV_VAR in environ: - try: - default = loads(environ[EXCLUDE_INSTRUMENTATIONS_ENV_VAR]) - except ValueError as e: - _logger.error( - _INVALID_JSON_MESSAGE - % (EXCLUDE_INSTRUMENTATIONS_ENV_VAR, default, e) - ) - configurations[EXCLUDE_INSTRUMENTATIONS_ARG] = default + configurations[EXCLUDE_INSTRUMENTATIONS_ARG] = [] def _default_disable_logging(configurations): if DISABLE_LOGGING_ARG not in configurations: - default = False - if DISABLE_LOGGING_ENV_VAR in environ: - env_var = environ[DISABLE_LOGGING_ENV_VAR] - if env_var.lower() == "true": - default = True - configurations[DISABLE_LOGGING_ARG] = default + configurations[DISABLE_LOGGING_ARG] = False def _default_disable_metrics(configurations): if DISABLE_METRICS_ARG not in configurations: - default = False - if DISABLE_METRICS_ENV_VAR in environ: - env_var = environ[DISABLE_METRICS_ENV_VAR] - if env_var.lower() == "true": - default = True - configurations[DISABLE_METRICS_ARG] = default + configurations[DISABLE_METRICS_ARG] = False def _default_disable_tracing(configurations): if DISABLE_TRACING_ARG not in configurations: - default = False - if DISABLE_TRACING_ENV_VAR in environ: - env_var = environ[DISABLE_TRACING_ENV_VAR] - if env_var.lower() == "true": - default = True - configurations[DISABLE_TRACING_ARG] = default + configurations[DISABLE_TRACING_ARG] = False def _default_logging_level(configurations): if LOGGING_LEVEL_ARG not in configurations: - default = NOTSET - if LOGGING_LEVEL_ENV_VAR in environ: - # TODO: Match OTel env var usage when it is determined. - try: - default = int(environ[LOGGING_LEVEL_ENV_VAR]) - except ValueError as e: - _logger.error( - _INVALID_INT_MESSAGE % (LOGGING_LEVEL_ENV_VAR, default, e) - ) - configurations[LOGGING_LEVEL_ARG] = default + configurations[LOGGING_LEVEL_ARG] = NOTSET def _default_logger_name(configurations): if LOGGER_NAME_ARG not in configurations: - default = "" - if LOGGER_NAME_ENV_VAR in environ: - default = environ[LOGGER_NAME_ENV_VAR] - configurations[LOGGER_NAME_ARG] = default + configurations[LOGGER_NAME_ARG] = "" def _default_logging_export_interval_ms(configurations): if LOGGING_EXPORT_INTERVAL_MS_ARG not in configurations: - default = 5000 - if LOGGING_EXPORT_INTERVAL_MS_ENV_VAR in environ: - try: - 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) - ) - configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] = default + configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] = 5000 def _default_metric_readers(configurations): @@ -198,13 +132,4 @@ def _default_tracing_export_interval_ms(configurations): def _default_instrumentation_config(configurations): if INSTRUMENTATION_CONFIG_ARG not in configurations: - default = {} - if INSTRUMENTATION_CONFIG_ENV_VAR in environ: - try: - default = loads(environ[INSTRUMENTATION_CONFIG_ENV_VAR]) - except ValueError as e: - _logger.error( - _INVALID_JSON_MESSAGE - % (INSTRUMENTATION_CONFIG_ENV_VAR, default, e) - ) - configurations[INSTRUMENTATION_CONFIG_ARG] = default + configurations[INSTRUMENTATION_CONFIG_ARG] = {} diff --git a/azure-monitor-opentelemetry/tests/configuration/test_util.py b/azure-monitor-opentelemetry/tests/configuration/test_util.py index 0d97df15..afff2205 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_util.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_util.py @@ -12,19 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from logging import NOTSET, WARN +from logging import NOTSET from unittest import TestCase from unittest.mock import patch from azure.monitor.opentelemetry.util.configurations import ( - DISABLE_LOGGING_ENV_VAR, - DISABLE_METRICS_ENV_VAR, - DISABLE_TRACING_ENV_VAR, - EXCLUDE_INSTRUMENTATIONS_ENV_VAR, - INSTRUMENTATION_CONFIG_ENV_VAR, - LOGGER_NAME_ENV_VAR, LOGGING_EXPORT_INTERVAL_MS_ENV_VAR, - LOGGING_LEVEL_ENV_VAR, SAMPLING_RATIO_ENV_VAR, _get_configurations, ) @@ -109,63 +102,14 @@ def test_get_configurations_validation(self): @patch.dict( "os.environ", { - EXCLUDE_INSTRUMENTATIONS_ENV_VAR: '["flask"]', - DISABLE_LOGGING_ENV_VAR: "True", - DISABLE_METRICS_ENV_VAR: "True", - DISABLE_TRACING_ENV_VAR: "True", - LOGGING_LEVEL_ENV_VAR: "30", - LOGGER_NAME_ENV_VAR: "opentelemetry", LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "10000", SAMPLING_RATIO_ENV_VAR: "0.5", - INSTRUMENTATION_CONFIG_ENV_VAR: """{ - "flask": { - "excluded_urls": "http://localhost:8080/ignore" - } - }""", }, clear=True, ) def test_get_configurations_env_vars(self): configurations = _get_configurations() - self.assertTrue("connection_string" not in configurations) - self.assertEqual(configurations["exclude_instrumentations"], ["flask"]) - self.assertEqual(configurations["disable_logging"], True) - self.assertEqual(configurations["disable_metrics"], True) - self.assertEqual(configurations["disable_tracing"], True) - self.assertEqual(configurations["logging_level"], WARN) - self.assertEqual(configurations["logger_name"], "opentelemetry") - self.assertTrue("resource" not in configurations) - self.assertEqual(configurations["sampling_ratio"], 0.5) - self.assertEqual(configurations["tracing_export_interval_ms"], None) - self.assertEqual(configurations["logging_export_interval_ms"], 10000) - self.assertEqual(configurations["metric_readers"], []) - self.assertEqual(configurations["views"], ()) - self.assertEqual( - configurations["instrumentation_config"], - {"flask": {"excluded_urls": "http://localhost:8080/ignore"}}, - ) - - @patch.dict( - "os.environ", - { - EXCLUDE_INSTRUMENTATIONS_ENV_VAR: '"flask', - DISABLE_LOGGING_ENV_VAR: "one", - DISABLE_METRICS_ENV_VAR: "", - DISABLE_TRACING_ENV_VAR: "0.5", - LOGGING_LEVEL_ENV_VAR: "Thirty", - LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "Ten Thousand", - SAMPLING_RATIO_ENV_VAR: "Half", - INSTRUMENTATION_CONFIG_ENV_VAR: """{ - "flask": - "excluded_urls": "http://localhost:8080/ignore" - }""", - }, - clear=True, - ) - def test_get_configurations_env_vars_validation(self): - configurations = _get_configurations() - self.assertTrue("connection_string" not in configurations) self.assertEqual(configurations["exclude_instrumentations"], []) self.assertEqual(configurations["disable_logging"], False) @@ -174,7 +118,7 @@ def test_get_configurations_env_vars_validation(self): self.assertEqual(configurations["logging_level"], NOTSET) self.assertEqual(configurations["logger_name"], "") self.assertTrue("resource" not in configurations) - self.assertEqual(configurations["sampling_ratio"], 1.0) + self.assertEqual(configurations["sampling_ratio"], 0.5) self.assertEqual(configurations["tracing_export_interval_ms"], None) self.assertEqual(configurations["logging_export_interval_ms"], 5000) self.assertEqual(configurations["metric_readers"], []) @@ -184,13 +128,12 @@ def test_get_configurations_env_vars_validation(self): @patch.dict( "os.environ", { - DISABLE_LOGGING_ENV_VAR: "false", - DISABLE_METRICS_ENV_VAR: "False", - DISABLE_TRACING_ENV_VAR: "FALSE", + LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "Ten Thousand", + SAMPLING_RATIO_ENV_VAR: "Half", }, clear=True, ) - def test_get_configurations_env_vars_false(self): + def test_get_configurations_env_vars_validation(self): configurations = _get_configurations() self.assertTrue("connection_string" not in configurations) @@ -207,30 +150,3 @@ def test_get_configurations_env_vars_false(self): self.assertEqual(configurations["metric_readers"], []) self.assertEqual(configurations["views"], ()) self.assertEqual(configurations["instrumentation_config"], {}) - - @patch.dict( - "os.environ", - { - DISABLE_LOGGING_ENV_VAR: "true", - DISABLE_METRICS_ENV_VAR: "True", - DISABLE_TRACING_ENV_VAR: "TRUE", - }, - clear=True, - ) - def test_get_configurations_env_vars_true(self): - configurations = _get_configurations() - - self.assertTrue("connection_string" not in configurations) - self.assertEqual(configurations["exclude_instrumentations"], []) - self.assertEqual(configurations["disable_logging"], True) - self.assertEqual(configurations["disable_metrics"], True) - self.assertEqual(configurations["disable_tracing"], True) - self.assertEqual(configurations["logging_level"], NOTSET) - self.assertEqual(configurations["logger_name"], "") - self.assertTrue("resource" not in configurations) - self.assertEqual(configurations["sampling_ratio"], 1.0) - self.assertEqual(configurations["tracing_export_interval_ms"], None) - self.assertEqual(configurations["logging_export_interval_ms"], 5000) - self.assertEqual(configurations["metric_readers"], []) - self.assertEqual(configurations["views"], ()) - self.assertEqual(configurations["instrumentation_config"], {}) From 07fbc16d6bcc3b32ae1607d0dd343bfeb8bdcf37 Mon Sep 17 00:00:00 2001 From: Jeremy Voss Date: Thu, 30 Mar 2023 14:29:38 -0700 Subject: [PATCH 18/19] Update azure-monitor-opentelemetry/README.md Co-authored-by: Leighton Chen --- azure-monitor-opentelemetry/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-monitor-opentelemetry/README.md b/azure-monitor-opentelemetry/README.md index 25c7ee3d..903e2688 100644 --- a/azure-monitor-opentelemetry/README.md +++ b/azure-monitor-opentelemetry/README.md @@ -56,7 +56,7 @@ You can use `configure_azure_monitor` to set up instrumentation for your app to |-------------------|----------------------------------------------------|----------------------| | `connection_string` | The [connection string][connection_string_doc] for your Application Insights resource. The connection string will be automatically populated from the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable if not explicitly passed in. | `APPLICATIONINSIGHTS_CONNECTION_STRING` | | `exclude_instrumentations` | By default, all supported [instrumentations](#officially-supported-instrumentations) are enabled to collect telemetry. Specify instrumentations you do not want to enable to collect telemetry by passing in a comma separated list of instrumented library names. e.g. `["requests", "flask"]` | | -| `resource` | Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior. This include configuration via the `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_SERVICE_NAME` environment variables. | `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_SERVICE_NAME` | +| `resource` | Specifies the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior. | [OTEL_SERVICE_NAME][opentelemetry_spec_service_name], [OTEL_RESOURCE_ATTRIBUTES][opentelemetry_spec_resource_attributes] | | `disable_logging` | If set to `True`, disables collection and export of logging telemetry. Defaults to `False`. | | | `disable_metrics` | If set to `True`, disables collection and export of metric telemetry. Defaults to `False`. | | | `disable_tracing` | If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`. | | From 574c6e1f367794c52329b1d947b46b2accfd6a80 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Thu, 30 Mar 2023 14:31:26 -0700 Subject: [PATCH 19/19] Added OTel resourc env var documentation --- azure-monitor-opentelemetry/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/azure-monitor-opentelemetry/README.md b/azure-monitor-opentelemetry/README.md index 25c7ee3d..8414ae53 100644 --- a/azure-monitor-opentelemetry/README.md +++ b/azure-monitor-opentelemetry/README.md @@ -144,6 +144,8 @@ Samples are available [here][samples] to demonstrate how to utilize the above co [ot_instrumentation_urllib3]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-urllib3 [ot_instrumentation_urllib3_version]: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3/package.py#L16 [opentelemetry_spec_resource]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#resource-sdk +[opentelemetry_spec_resource_attributes]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#specifying-resource-information-via-an-environment-variable +[opentelemetry_spec_service_name]: https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions#semantic-attributes-with-sdk-provided-default-value [opentelemetry_spec_view]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#view [pip]: https://pypi.org/project/pip/ [pypi_django]: https://pypi.org/project/Django/