Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
logger_name=__name__,
logging_level=WARNING,
disable_metrics=True,
instrumentations=["flask"],
tracing_export_interval_ms=15000,
)

Expand Down
18 changes: 14 additions & 4 deletions azure-monitor-opentelemetry/tests/configuration/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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",
Expand Down Expand Up @@ -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,
)
Expand All @@ -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)
Expand All @@ -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,
)
Expand Down