Skip to content

Commit c1ba59c

Browse files
authored
Merge pull request #278 from jeremydvoss/exporter-pillar-disable
Infer pillar disablement from exporter env vars.
2 parents 4fe88bd + 1ffd4c4 commit c1ba59c

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## [1.0.0b11](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b11) - 2023-04-12
66

7+
- Infer telemetry category disablement from exporter environment variables
8+
([#278](https://github.com/microsoft/ApplicationInsights-Python/pull/278))
79
- Reverse default behavior of instrumentations and implement configuration for exclusion
810
([#253](https://github.com/microsoft/ApplicationInsights-Python/pull/253))
911
- Use entrypoints instead of importlib to load instrumentations

azure-monitor-opentelemetry/azure/monitor/opentelemetry/util/configurations.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
VIEWS_ARG,
2424
)
2525
from azure.monitor.opentelemetry._types import ConfigurationValue
26+
from opentelemetry.environment_variables import (
27+
OTEL_LOGS_EXPORTER,
28+
OTEL_METRICS_EXPORTER,
29+
OTEL_TRACES_EXPORTER,
30+
)
2631
from opentelemetry.sdk.environment_variables import OTEL_TRACES_SAMPLER_ARG
2732

2833
_INVALID_FLOAT_MESSAGE = "Value of %s must be a float. Defaulting to %s: %s"
@@ -72,17 +77,29 @@ def _default_exclude_instrumentations(configurations):
7277

7378
def _default_disable_logging(configurations):
7479
if DISABLE_LOGGING_ARG not in configurations:
75-
configurations[DISABLE_LOGGING_ARG] = False
80+
default = False
81+
if OTEL_LOGS_EXPORTER in environ:
82+
if environ[OTEL_LOGS_EXPORTER].lower().strip() == "none":
83+
default = True
84+
configurations[DISABLE_LOGGING_ARG] = default
7685

7786

7887
def _default_disable_metrics(configurations):
7988
if DISABLE_METRICS_ARG not in configurations:
80-
configurations[DISABLE_METRICS_ARG] = False
89+
default = False
90+
if OTEL_METRICS_EXPORTER in environ:
91+
if environ[OTEL_METRICS_EXPORTER].lower().strip() == "none":
92+
default = True
93+
configurations[DISABLE_METRICS_ARG] = default
8194

8295

8396
def _default_disable_tracing(configurations):
8497
if DISABLE_TRACING_ARG not in configurations:
85-
configurations[DISABLE_TRACING_ARG] = False
98+
default = False
99+
if OTEL_TRACES_EXPORTER in environ:
100+
if environ[OTEL_TRACES_EXPORTER].lower().strip() == "none":
101+
default = True
102+
configurations[DISABLE_TRACING_ARG] = default
86103

87104

88105
def _default_logging_level(configurations):

azure-monitor-opentelemetry/samples/logging/logs_with_traces.py

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
logger_name=__name__,
1515
logging_level=WARNING,
1616
disable_metrics=True,
17-
instrumentations=["flask"],
1817
tracing_export_interval_ms=15000,
1918
)
2019

azure-monitor-opentelemetry/tests/configuration/test_util.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
SAMPLING_RATIO_ENV_VAR,
2222
_get_configurations,
2323
)
24+
from opentelemetry.environment_variables import (
25+
OTEL_LOGS_EXPORTER,
26+
OTEL_METRICS_EXPORTER,
27+
OTEL_TRACES_EXPORTER,
28+
)
2429

2530

2631
class TestUtil(TestCase):
@@ -31,7 +36,6 @@ def test_get_configurations(self):
3136
disable_logging="test_disable_logging",
3237
disable_metrics="test_disable_metrics",
3338
disable_tracing="test_disable_tracing",
34-
instrumentations=["test_instrumentation"],
3539
logging_level="test_logging_level",
3640
logger_name="test_logger_name",
3741
resource="test_resource",
@@ -104,6 +108,9 @@ def test_get_configurations_validation(self):
104108
{
105109
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "10000",
106110
SAMPLING_RATIO_ENV_VAR: "0.5",
111+
OTEL_TRACES_EXPORTER: "None",
112+
OTEL_LOGS_EXPORTER: "none",
113+
OTEL_METRICS_EXPORTER: "NONE",
107114
},
108115
clear=True,
109116
)
@@ -112,9 +119,9 @@ def test_get_configurations_env_vars(self):
112119

113120
self.assertTrue("connection_string" not in configurations)
114121
self.assertEqual(configurations["exclude_instrumentations"], [])
115-
self.assertEqual(configurations["disable_logging"], False)
116-
self.assertEqual(configurations["disable_metrics"], False)
117-
self.assertEqual(configurations["disable_tracing"], False)
122+
self.assertEqual(configurations["disable_logging"], True)
123+
self.assertEqual(configurations["disable_metrics"], True)
124+
self.assertEqual(configurations["disable_tracing"], True)
118125
self.assertEqual(configurations["logging_level"], NOTSET)
119126
self.assertEqual(configurations["logger_name"], "")
120127
self.assertTrue("resource" not in configurations)
@@ -130,6 +137,9 @@ def test_get_configurations_env_vars(self):
130137
{
131138
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "Ten Thousand",
132139
SAMPLING_RATIO_ENV_VAR: "Half",
140+
OTEL_TRACES_EXPORTER: "False",
141+
OTEL_LOGS_EXPORTER: "no",
142+
OTEL_METRICS_EXPORTER: "True",
133143
},
134144
clear=True,
135145
)

0 commit comments

Comments
 (0)