Skip to content

Commit 032a063

Browse files
committed
Removed instrumentations param from sample, added exporter env var
support for disable_x params
1 parent 4fe88bd commit 032a063

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
)
2525
from azure.monitor.opentelemetry._types import ConfigurationValue
2626
from opentelemetry.sdk.environment_variables import OTEL_TRACES_SAMPLER_ARG
27+
from opentelemetry.environment_variables import OTEL_LOGS_EXPORTER, OTEL_METRICS_EXPORTER, OTEL_TRACES_EXPORTER
2728

2829
_INVALID_FLOAT_MESSAGE = "Value of %s must be a float. Defaulting to %s: %s"
2930

@@ -72,17 +73,29 @@ def _default_exclude_instrumentations(configurations):
7273

7374
def _default_disable_logging(configurations):
7475
if DISABLE_LOGGING_ARG not in configurations:
75-
configurations[DISABLE_LOGGING_ARG] = False
76+
default = False
77+
if OTEL_LOGS_EXPORTER in environ:
78+
if environ[OTEL_LOGS_EXPORTER].lower().strip() == "none":
79+
default = True
80+
configurations[DISABLE_LOGGING_ARG] = default
7681

7782

7883
def _default_disable_metrics(configurations):
7984
if DISABLE_METRICS_ARG not in configurations:
80-
configurations[DISABLE_METRICS_ARG] = False
85+
default = False
86+
if OTEL_METRICS_EXPORTER in environ:
87+
if environ[OTEL_METRICS_EXPORTER].lower().strip() == "none":
88+
default = True
89+
configurations[DISABLE_METRICS_ARG] = default
8190

8291

8392
def _default_disable_tracing(configurations):
8493
if DISABLE_TRACING_ARG not in configurations:
85-
configurations[DISABLE_TRACING_ARG] = False
94+
default = False
95+
if OTEL_TRACES_EXPORTER in environ:
96+
if environ[OTEL_TRACES_EXPORTER].lower().strip() == "none":
97+
default = True
98+
configurations[DISABLE_TRACING_ARG] = default
8699

87100

88101
def _default_logging_level(configurations):

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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 14 additions & 4 deletions
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_TRACES_EXPORTER,
26+
OTEL_LOGS_EXPORTER,
27+
OTEL_METRICS_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)