Removed instrumentations param from sample, added exporter env var

support for disable_x params
This commit is contained in:
jerevoss 2023-05-01 14:49:25 -07:00
Родитель 4fe88bd4cf
Коммит 032a063b3f
3 изменённых файлов: 30 добавлений и 8 удалений

Просмотреть файл

@ -24,6 +24,7 @@ from azure.monitor.opentelemetry._constants import (
)
from azure.monitor.opentelemetry._types import ConfigurationValue
from opentelemetry.sdk.environment_variables import OTEL_TRACES_SAMPLER_ARG
from opentelemetry.environment_variables import OTEL_LOGS_EXPORTER, OTEL_METRICS_EXPORTER, OTEL_TRACES_EXPORTER
_INVALID_FLOAT_MESSAGE = "Value of %s must be a float. Defaulting to %s: %s"
@ -72,17 +73,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):

Просмотреть файл

@ -14,7 +14,6 @@ configure_azure_monitor(
logger_name=__name__,
logging_level=WARNING,
disable_metrics=True,
instrumentations=["flask"],
tracing_export_interval_ms=15000,
)

Просмотреть файл

@ -21,6 +21,11 @@ from azure.monitor.opentelemetry.util.configurations import (
SAMPLING_RATIO_ENV_VAR,
_get_configurations,
)
from opentelemetry.environment_variables import (
OTEL_TRACES_EXPORTER,
OTEL_LOGS_EXPORTER,
OTEL_METRICS_EXPORTER,
)
class TestUtil(TestCase):
@ -31,7 +36,6 @@ class TestUtil(TestCase):
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 @@ class TestUtil(TestCase):
{
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 @@ class TestUtil(TestCase):
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 @@ class TestUtil(TestCase):
{
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,
)