Skip to content

Commit

Permalink
Merge pull request #311 from lzchen/remove
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored Aug 15, 2023
2 parents a70f837 + 3a7379b commit c4d7fb6
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 49 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Unpin OTel SDK/API version
([#310](https://github.com/microsoft/ApplicationInsights-Python/pull/310))
- Replace explicit log processor exporter interval env var with OT SDK env var
([#311](https://github.com/microsoft/ApplicationInsights-Python/pull/311))

## [1.0.0b15](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b15) - 2023-07-17

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
DISABLE_METRICS_ARG,
DISABLE_TRACING_ARG,
DISABLED_INSTRUMENTATIONS_ARG,
LOGGING_EXPORT_INTERVAL_MS_ARG,
SAMPLING_RATIO_ARG,
)
from azure.monitor.opentelemetry._types import ConfigurationValue
Expand Down Expand Up @@ -113,14 +112,11 @@ def _setup_tracing(configurations: Dict[str, ConfigurationValue]):


def _setup_logging(configurations: Dict[str, ConfigurationValue]):
# TODO: Remove after upgrading to OTel SDK 1.18
logging_export_interval_ms = configurations[LOGGING_EXPORT_INTERVAL_MS_ARG]
logger_provider = LoggerProvider()
set_logger_provider(logger_provider)
log_exporter = AzureMonitorLogExporter(**configurations)
log_record_processor = BatchLogRecordProcessor(
log_exporter,
schedule_delay_millis=logging_export_interval_ms,
)
get_logger_provider().add_log_record_processor(log_record_processor)
handler = LoggingHandler(logger_provider=get_logger_provider())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
DISABLE_METRICS_ARG = "disable_metrics"
DISABLE_TRACING_ARG = "disable_tracing"
DISABLED_INSTRUMENTATIONS_ARG = "disabled_instrumentations"
LOGGING_EXPORT_INTERVAL_MS_ARG = "logging_export_interval_ms"
SAMPLING_RATIO_ARG = "sampling_ratio"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
DISABLE_METRICS_ARG,
DISABLE_TRACING_ARG,
DISABLED_INSTRUMENTATIONS_ARG,
LOGGING_EXPORT_INTERVAL_MS_ARG,
SAMPLING_RATIO_ARG,
)
from azure.monitor.opentelemetry._types import ConfigurationValue
Expand All @@ -32,8 +31,6 @@
_INVALID_INT_MESSAGE = "Value of %s must be a integer. Defaulting to %s: %s"


# Speced out but unused by OTel SDK as of 1.17.0
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR = "OTEL_BLRP_SCHEDULE_DELAY"
# TODO: remove when sampler uses env var instead
SAMPLING_RATIO_ENV_VAR = OTEL_TRACES_SAMPLER_ARG

Expand All @@ -51,16 +48,9 @@ def _get_configurations(**kwargs) -> Dict[str, ConfigurationValue]:
_default_disable_metrics(configurations)
_default_disable_tracing(configurations)
_default_disabled_instrumentations(configurations)
_default_logging_export_interval_ms(configurations)
_default_sampling_ratio(configurations)
_default_disable_azure_core_tracing(configurations)

# TODO: remove when validation added to BLRP
if configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] <= 0:
raise ValueError(
"%s must be positive." % LOGGING_EXPORT_INTERVAL_MS_ARG
)

return configurations


Expand Down Expand Up @@ -101,21 +91,6 @@ def _default_disabled_instrumentations(configurations):
configurations[DISABLED_INSTRUMENTATIONS_ARG] = disabled_instrumentation


def _default_logging_export_interval_ms(configurations):
default = 5000
if LOGGING_EXPORT_INTERVAL_MS_ENV_VAR in environ:
try:
default = int(environ[LOGGING_EXPORT_INTERVAL_MS_ENV_VAR])
except ValueError as e:
_logger.error(
_INVALID_INT_MESSAGE,
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR,
default,
e,
)
configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] = default


# TODO: remove when sampler uses env var instead
def _default_sampling_ratio(configurations):
default = 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ def test_setup_logging(

configurations = {
"connection_string": "test_cs",
"logging_export_interval_ms": 10000,
}
_setup_logging(configurations)

Expand All @@ -279,7 +278,7 @@ def test_setup_logging(
get_logger_provider_mock.assert_called()
log_exporter_mock.assert_called_once_with(**configurations)
blrp_mock.assert_called_once_with(
log_exp_init_mock, schedule_delay_millis=10000
log_exp_init_mock,
)
lp_init_mock.add_log_record_processor.assert_called_once_with(
blrp_init_mock
Expand Down
17 changes: 0 additions & 17 deletions azure-monitor-opentelemetry/tests/configuration/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS,
)
from azure.monitor.opentelemetry.util.configurations import (
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR,
SAMPLING_RATIO_ENV_VAR,
_get_configurations,
)
Expand All @@ -44,7 +43,6 @@ def test_get_configurations(self):
self.assertEqual(configurations["disable_tracing"], False)
self.assertEqual(configurations["disabled_instrumentations"], [])
self.assertEqual(configurations["sampling_ratio"], 1.0)
self.assertEqual(configurations["logging_export_interval_ms"], 5000)
self.assertEqual(configurations["credential"], ("test_credential"))
self.assertTrue("storage_directory" not in configurations)

Expand All @@ -59,25 +57,13 @@ def test_get_configurations_defaults(self):
self.assertEqual(configurations["disable_tracing"], False)
self.assertEqual(configurations["disabled_instrumentations"], [])
self.assertEqual(configurations["sampling_ratio"], 1.0)
self.assertEqual(configurations["logging_export_interval_ms"], 5000)
self.assertTrue("credential" not in configurations)
self.assertTrue("storage_directory" not in configurations)

@patch.dict(
"os.environ",
{
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "-1",
},
clear=True,
)
def test_get_configurations_logging_export_validation(self):
self.assertRaises(ValueError, _get_configurations)

@patch.dict(
"os.environ",
{
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS: "flask , requests,fastapi",
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "10000",
SAMPLING_RATIO_ENV_VAR: "0.5",
OTEL_TRACES_EXPORTER: "None",
OTEL_LOGS_EXPORTER: "none",
Expand All @@ -98,12 +84,10 @@ def test_get_configurations_env_vars(self):
["flask", "requests", "fastapi"],
)
self.assertEqual(configurations["sampling_ratio"], 0.5)
self.assertEqual(configurations["logging_export_interval_ms"], 10000)

@patch.dict(
"os.environ",
{
LOGGING_EXPORT_INTERVAL_MS_ENV_VAR: "Ten Thousand",
SAMPLING_RATIO_ENV_VAR: "Half",
OTEL_TRACES_EXPORTER: "False",
OTEL_LOGS_EXPORTER: "no",
Expand All @@ -120,4 +104,3 @@ def test_get_configurations_env_vars_validation(self):
self.assertEqual(configurations["disable_metrics"], False)
self.assertEqual(configurations["disable_tracing"], False)
self.assertEqual(configurations["sampling_ratio"], 1.0)
self.assertEqual(configurations["logging_export_interval_ms"], 5000)

0 comments on commit c4d7fb6

Please sign in to comment.