diff --git a/CHANGELOG.md b/CHANGELOG.md index 43fe00ae..be507ccc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ## [1.0.0b11](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b11) - 2023-04-12 +- Infer telemetry category disablement from exporter environment variables + ([#278](https://github.com/microsoft/ApplicationInsights-Python/pull/278)) - Reverse default behavior of instrumentations and implement configuration for exclusion ([#253](https://github.com/microsoft/ApplicationInsights-Python/pull/253)) - Use entrypoints instead of importlib to load instrumentations diff --git a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py index 1df8c387..5fa17b8a 100644 --- a/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py +++ b/azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py @@ -23,6 +23,11 @@ VIEWS_ARG, ) from azure.monitor.opentelemetry._types import ConfigurationValue +from opentelemetry.environment_variables import ( + OTEL_LOGS_EXPORTER, + OTEL_METRICS_EXPORTER, + OTEL_TRACES_EXPORTER, +) from opentelemetry.sdk.environment_variables import OTEL_TRACES_SAMPLER_ARG _INVALID_FLOAT_MESSAGE = "Value of %s must be a float. Defaulting to %s: %s" @@ -72,17 +77,29 @@ def _default_exclude_instrumentations(configurations): def _default_disable_logging(configurations): if DISABLE_LOGGING_ARG not in configurations: - configurations[DISABLE_LOGGING_ARG] = False + default = False + if OTEL_LOGS_EXPORTER in environ: + if environ[OTEL_LOGS_EXPORTER].lower().strip() == "none": + default = True + configurations[DISABLE_LOGGING_ARG] = default def _default_disable_metrics(configurations): if DISABLE_METRICS_ARG not in configurations: - configurations[DISABLE_METRICS_ARG] = False + default = False + if OTEL_METRICS_EXPORTER in environ: + if environ[OTEL_METRICS_EXPORTER].lower().strip() == "none": + default = True + configurations[DISABLE_METRICS_ARG] = default def _default_disable_tracing(configurations): if DISABLE_TRACING_ARG not in configurations: - configurations[DISABLE_TRACING_ARG] = False + default = False + if OTEL_TRACES_EXPORTER in environ: + if environ[OTEL_TRACES_EXPORTER].lower().strip() == "none": + default = True + configurations[DISABLE_TRACING_ARG] = default def _default_logging_level(configurations): diff --git a/azure-monitor-opentelemetry/samples/logging/logs_with_traces.py b/azure-monitor-opentelemetry/samples/logging/logs_with_traces.py index 658c20a2..ca3c5660 100644 --- a/azure-monitor-opentelemetry/samples/logging/logs_with_traces.py +++ b/azure-monitor-opentelemetry/samples/logging/logs_with_traces.py @@ -14,7 +14,6 @@ logger_name=__name__, logging_level=WARNING, disable_metrics=True, - instrumentations=["flask"], tracing_export_interval_ms=15000, ) diff --git a/azure-monitor-opentelemetry/tests/configuration/test_util.py b/azure-monitor-opentelemetry/tests/configuration/test_util.py index afff2205..34496868 100644 --- a/azure-monitor-opentelemetry/tests/configuration/test_util.py +++ b/azure-monitor-opentelemetry/tests/configuration/test_util.py @@ -21,6 +21,11 @@ SAMPLING_RATIO_ENV_VAR, _get_configurations, ) +from opentelemetry.environment_variables import ( + OTEL_LOGS_EXPORTER, + OTEL_METRICS_EXPORTER, + OTEL_TRACES_EXPORTER, +) class TestUtil(TestCase): @@ -31,7 +36,6 @@ def test_get_configurations(self): 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", resource="test_resource", @@ -104,6 +108,9 @@ def test_get_configurations_validation(self): { LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "10000", SAMPLING_RATIO_ENV_VAR: "0.5", + OTEL_TRACES_EXPORTER: "None", + OTEL_LOGS_EXPORTER: "none", + OTEL_METRICS_EXPORTER: "NONE", }, clear=True, ) @@ -112,9 +119,9 @@ def test_get_configurations_env_vars(self): 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["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) @@ -130,6 +137,9 @@ def test_get_configurations_env_vars(self): { LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "Ten Thousand", SAMPLING_RATIO_ENV_VAR: "Half", + OTEL_TRACES_EXPORTER: "False", + OTEL_LOGS_EXPORTER: "no", + OTEL_METRICS_EXPORTER: "True", }, clear=True, )