Skip to content

Commit 6f5b42d

Browse files
committed
Removed azmon env vars
1 parent a5f9371 commit 6f5b42d

File tree

3 files changed

+15
-174
lines changed

3 files changed

+15
-174
lines changed

azure-monitor-opentelemetry/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ You can use `configure_azure_monitor` to set up instrumentation for your app to
6060
| `disable_logging` | If set to `True`, disables collection and export of logging telemetry. Defaults to `False`. | |
6161
| `disable_metrics` | If set to `True`, disables collection and export of metric telemetry. Defaults to `False`. | |
6262
| `disable_tracing` | If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`. | |
63-
| `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` |
63+
| `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`. | |
6464
| `logger_name` | Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Defaults to "" which corresponds to the root logger. | |
6565
| `logging_export_interval_ms`| Specifies the logging export interval in milliseconds. Defaults to 5000. | `OTEL_BLRP_SCHEDULE_DELAY` |
6666
| `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]. | |

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

Lines changed: 9 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# license information.
55
# --------------------------------------------------------------------------
66

7-
from json import loads
87
from logging import NOTSET, getLogger
98
from os import environ
109
from typing import Dict
@@ -24,35 +23,15 @@
2423
VIEWS_ARG,
2524
)
2625
from azure.monitor.opentelemetry._types import ConfigurationValue
27-
from opentelemetry.sdk.environment_variables import (
28-
OTEL_LOG_LEVEL,
29-
OTEL_TRACES_SAMPLER_ARG,
30-
)
26+
from opentelemetry.sdk.environment_variables import OTEL_TRACES_SAMPLER_ARG
3127

32-
_CONFIGURATION_ENV_VAR_PREFIX = "APPLICATIONINSIGHTS_"
33-
_INVALID_JSON_MESSAGE = "Value of %s must be valid JSON. Defaulting to %s: %s"
34-
_INVALID_INT_MESSAGE = "Value of %s must be an integer. Defaulting to %s: %s"
3528
_INVALID_FLOAT_MESSAGE = "Value of %s must be a float. Defaulting to %s: %s"
3629

3730

38-
def _get_env_var_name(arg):
39-
return _CONFIGURATION_ENV_VAR_PREFIX + arg.upper()
40-
41-
42-
EXCLUDE_INSTRUMENTATIONS_ENV_VAR = _get_env_var_name(
43-
EXCLUDE_INSTRUMENTATIONS_ARG
44-
)
45-
DISABLE_LOGGING_ENV_VAR = _get_env_var_name(DISABLE_LOGGING_ARG)
46-
DISABLE_METRICS_ENV_VAR = _get_env_var_name(DISABLE_METRICS_ARG)
47-
DISABLE_TRACING_ENV_VAR = _get_env_var_name(DISABLE_TRACING_ARG)
48-
# Speced out but unused by OTel SDK as of 1.15.0
49-
LOGGING_LEVEL_ENV_VAR = OTEL_LOG_LEVEL
50-
LOGGER_NAME_ENV_VAR = _get_env_var_name(LOGGER_NAME_ARG)
5131
# Speced out but unused by OTel SDK as of 1.15.0
5232
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR = "OTEL_BLRP_SCHEDULE_DELAY"
5333
# TODO: remove when sampler uses env var instead
5434
SAMPLING_RATIO_ENV_VAR = OTEL_TRACES_SAMPLER_ARG
55-
INSTRUMENTATION_CONFIG_ENV_VAR = _get_env_var_name(INSTRUMENTATION_CONFIG_ARG)
5635

5736

5837
_logger = getLogger(__name__)
@@ -88,82 +67,37 @@ def _get_configurations(**kwargs) -> Dict[str, ConfigurationValue]:
8867

8968
def _default_exclude_instrumentations(configurations):
9069
if EXCLUDE_INSTRUMENTATIONS_ARG not in configurations:
91-
default = []
92-
if EXCLUDE_INSTRUMENTATIONS_ENV_VAR in environ:
93-
try:
94-
default = loads(environ[EXCLUDE_INSTRUMENTATIONS_ENV_VAR])
95-
except ValueError as e:
96-
_logger.error(
97-
_INVALID_JSON_MESSAGE
98-
% (EXCLUDE_INSTRUMENTATIONS_ENV_VAR, default, e)
99-
)
100-
configurations[EXCLUDE_INSTRUMENTATIONS_ARG] = default
70+
configurations[EXCLUDE_INSTRUMENTATIONS_ARG] = []
10171

10272

10373
def _default_disable_logging(configurations):
10474
if DISABLE_LOGGING_ARG not in configurations:
105-
default = False
106-
if DISABLE_LOGGING_ENV_VAR in environ:
107-
env_var = environ[DISABLE_LOGGING_ENV_VAR]
108-
if env_var.lower() == "true":
109-
default = True
110-
configurations[DISABLE_LOGGING_ARG] = default
75+
configurations[DISABLE_LOGGING_ARG] = False
11176

11277

11378
def _default_disable_metrics(configurations):
11479
if DISABLE_METRICS_ARG not in configurations:
115-
default = False
116-
if DISABLE_METRICS_ENV_VAR in environ:
117-
env_var = environ[DISABLE_METRICS_ENV_VAR]
118-
if env_var.lower() == "true":
119-
default = True
120-
configurations[DISABLE_METRICS_ARG] = default
80+
configurations[DISABLE_METRICS_ARG] = False
12181

12282

12383
def _default_disable_tracing(configurations):
12484
if DISABLE_TRACING_ARG not in configurations:
125-
default = False
126-
if DISABLE_TRACING_ENV_VAR in environ:
127-
env_var = environ[DISABLE_TRACING_ENV_VAR]
128-
if env_var.lower() == "true":
129-
default = True
130-
configurations[DISABLE_TRACING_ARG] = default
85+
configurations[DISABLE_TRACING_ARG] = False
13186

13287

13388
def _default_logging_level(configurations):
13489
if LOGGING_LEVEL_ARG not in configurations:
135-
default = NOTSET
136-
if LOGGING_LEVEL_ENV_VAR in environ:
137-
# TODO: Match OTel env var usage when it is determined.
138-
try:
139-
default = int(environ[LOGGING_LEVEL_ENV_VAR])
140-
except ValueError as e:
141-
_logger.error(
142-
_INVALID_INT_MESSAGE % (LOGGING_LEVEL_ENV_VAR, default, e)
143-
)
144-
configurations[LOGGING_LEVEL_ARG] = default
90+
configurations[LOGGING_LEVEL_ARG] = NOTSET
14591

14692

14793
def _default_logger_name(configurations):
14894
if LOGGER_NAME_ARG not in configurations:
149-
default = ""
150-
if LOGGER_NAME_ENV_VAR in environ:
151-
default = environ[LOGGER_NAME_ENV_VAR]
152-
configurations[LOGGER_NAME_ARG] = default
95+
configurations[LOGGER_NAME_ARG] = ""
15396

15497

15598
def _default_logging_export_interval_ms(configurations):
15699
if LOGGING_EXPORT_INTERVAL_MS_ARG not in configurations:
157-
default = 5000
158-
if LOGGING_EXPORT_INTERVAL_MS_ENV_VAR in environ:
159-
try:
160-
default = int(environ[LOGGING_EXPORT_INTERVAL_MS_ENV_VAR])
161-
except ValueError as e:
162-
_logger.error(
163-
_INVALID_INT_MESSAGE
164-
% (LOGGING_EXPORT_INTERVAL_MS_ENV_VAR, default, e)
165-
)
166-
configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] = default
100+
configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] = 5000
167101

168102

169103
def _default_metric_readers(configurations):
@@ -198,13 +132,4 @@ def _default_tracing_export_interval_ms(configurations):
198132

199133
def _default_instrumentation_config(configurations):
200134
if INSTRUMENTATION_CONFIG_ARG not in configurations:
201-
default = {}
202-
if INSTRUMENTATION_CONFIG_ENV_VAR in environ:
203-
try:
204-
default = loads(environ[INSTRUMENTATION_CONFIG_ENV_VAR])
205-
except ValueError as e:
206-
_logger.error(
207-
_INVALID_JSON_MESSAGE
208-
% (INSTRUMENTATION_CONFIG_ENV_VAR, default, e)
209-
)
210-
configurations[INSTRUMENTATION_CONFIG_ARG] = default
135+
configurations[INSTRUMENTATION_CONFIG_ARG] = {}

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

Lines changed: 5 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from logging import NOTSET, WARN
15+
from logging import NOTSET
1616
from unittest import TestCase
1717
from unittest.mock import patch
1818

1919
from azure.monitor.opentelemetry.util.configurations import (
20-
DISABLE_LOGGING_ENV_VAR,
21-
DISABLE_METRICS_ENV_VAR,
22-
DISABLE_TRACING_ENV_VAR,
23-
EXCLUDE_INSTRUMENTATIONS_ENV_VAR,
24-
INSTRUMENTATION_CONFIG_ENV_VAR,
25-
LOGGER_NAME_ENV_VAR,
2620
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR,
27-
LOGGING_LEVEL_ENV_VAR,
2821
SAMPLING_RATIO_ENV_VAR,
2922
_get_configurations,
3023
)
@@ -109,63 +102,14 @@ def test_get_configurations_validation(self):
109102
@patch.dict(
110103
"os.environ",
111104
{
112-
EXCLUDE_INSTRUMENTATIONS_ENV_VAR: '["flask"]',
113-
DISABLE_LOGGING_ENV_VAR: "True",
114-
DISABLE_METRICS_ENV_VAR: "True",
115-
DISABLE_TRACING_ENV_VAR: "True",
116-
LOGGING_LEVEL_ENV_VAR: "30",
117-
LOGGER_NAME_ENV_VAR: "opentelemetry",
118105
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "10000",
119106
SAMPLING_RATIO_ENV_VAR: "0.5",
120-
INSTRUMENTATION_CONFIG_ENV_VAR: """{
121-
"flask": {
122-
"excluded_urls": "http://localhost:8080/ignore"
123-
}
124-
}""",
125107
},
126108
clear=True,
127109
)
128110
def test_get_configurations_env_vars(self):
129111
configurations = _get_configurations()
130112

131-
self.assertTrue("connection_string" not in configurations)
132-
self.assertEqual(configurations["exclude_instrumentations"], ["flask"])
133-
self.assertEqual(configurations["disable_logging"], True)
134-
self.assertEqual(configurations["disable_metrics"], True)
135-
self.assertEqual(configurations["disable_tracing"], True)
136-
self.assertEqual(configurations["logging_level"], WARN)
137-
self.assertEqual(configurations["logger_name"], "opentelemetry")
138-
self.assertTrue("resource" not in configurations)
139-
self.assertEqual(configurations["sampling_ratio"], 0.5)
140-
self.assertEqual(configurations["tracing_export_interval_ms"], None)
141-
self.assertEqual(configurations["logging_export_interval_ms"], 10000)
142-
self.assertEqual(configurations["metric_readers"], [])
143-
self.assertEqual(configurations["views"], ())
144-
self.assertEqual(
145-
configurations["instrumentation_config"],
146-
{"flask": {"excluded_urls": "http://localhost:8080/ignore"}},
147-
)
148-
149-
@patch.dict(
150-
"os.environ",
151-
{
152-
EXCLUDE_INSTRUMENTATIONS_ENV_VAR: '"flask',
153-
DISABLE_LOGGING_ENV_VAR: "one",
154-
DISABLE_METRICS_ENV_VAR: "",
155-
DISABLE_TRACING_ENV_VAR: "0.5",
156-
LOGGING_LEVEL_ENV_VAR: "Thirty",
157-
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "Ten Thousand",
158-
SAMPLING_RATIO_ENV_VAR: "Half",
159-
INSTRUMENTATION_CONFIG_ENV_VAR: """{
160-
"flask":
161-
"excluded_urls": "http://localhost:8080/ignore"
162-
}""",
163-
},
164-
clear=True,
165-
)
166-
def test_get_configurations_env_vars_validation(self):
167-
configurations = _get_configurations()
168-
169113
self.assertTrue("connection_string" not in configurations)
170114
self.assertEqual(configurations["exclude_instrumentations"], [])
171115
self.assertEqual(configurations["disable_logging"], False)
@@ -174,7 +118,7 @@ def test_get_configurations_env_vars_validation(self):
174118
self.assertEqual(configurations["logging_level"], NOTSET)
175119
self.assertEqual(configurations["logger_name"], "")
176120
self.assertTrue("resource" not in configurations)
177-
self.assertEqual(configurations["sampling_ratio"], 1.0)
121+
self.assertEqual(configurations["sampling_ratio"], 0.5)
178122
self.assertEqual(configurations["tracing_export_interval_ms"], None)
179123
self.assertEqual(configurations["logging_export_interval_ms"], 5000)
180124
self.assertEqual(configurations["metric_readers"], [])
@@ -184,13 +128,12 @@ def test_get_configurations_env_vars_validation(self):
184128
@patch.dict(
185129
"os.environ",
186130
{
187-
DISABLE_LOGGING_ENV_VAR: "false",
188-
DISABLE_METRICS_ENV_VAR: "False",
189-
DISABLE_TRACING_ENV_VAR: "FALSE",
131+
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "Ten Thousand",
132+
SAMPLING_RATIO_ENV_VAR: "Half",
190133
},
191134
clear=True,
192135
)
193-
def test_get_configurations_env_vars_false(self):
136+
def test_get_configurations_env_vars_validation(self):
194137
configurations = _get_configurations()
195138

196139
self.assertTrue("connection_string" not in configurations)
@@ -207,30 +150,3 @@ def test_get_configurations_env_vars_false(self):
207150
self.assertEqual(configurations["metric_readers"], [])
208151
self.assertEqual(configurations["views"], ())
209152
self.assertEqual(configurations["instrumentation_config"], {})
210-
211-
@patch.dict(
212-
"os.environ",
213-
{
214-
DISABLE_LOGGING_ENV_VAR: "true",
215-
DISABLE_METRICS_ENV_VAR: "True",
216-
DISABLE_TRACING_ENV_VAR: "TRUE",
217-
},
218-
clear=True,
219-
)
220-
def test_get_configurations_env_vars_true(self):
221-
configurations = _get_configurations()
222-
223-
self.assertTrue("connection_string" not in configurations)
224-
self.assertEqual(configurations["exclude_instrumentations"], [])
225-
self.assertEqual(configurations["disable_logging"], True)
226-
self.assertEqual(configurations["disable_metrics"], True)
227-
self.assertEqual(configurations["disable_tracing"], True)
228-
self.assertEqual(configurations["logging_level"], NOTSET)
229-
self.assertEqual(configurations["logger_name"], "")
230-
self.assertTrue("resource" not in configurations)
231-
self.assertEqual(configurations["sampling_ratio"], 1.0)
232-
self.assertEqual(configurations["tracing_export_interval_ms"], None)
233-
self.assertEqual(configurations["logging_export_interval_ms"], 5000)
234-
self.assertEqual(configurations["metric_readers"], [])
235-
self.assertEqual(configurations["views"], ())
236-
self.assertEqual(configurations["instrumentation_config"], {})

0 commit comments

Comments
 (0)