Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions solarwinds_apm/apm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ def _set_config_value(self, keys_str: str, val: Any) -> Any:
self.__config[key] = val
elif keys == ["transaction_name"]:
self.__config[key] = val
# TODO NH-101930 remove export_logs_enabled
elif keys in [["export_logs_enabled"], ["export_metrics_enabled"]]:
val = self.convert_to_bool(val)
if val not in (True, False):
Expand Down
26 changes: 13 additions & 13 deletions solarwinds_apm/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,21 @@ def _configure(self, **kwargs: int) -> None:
resource=apm_resource,
)

# Only emit log event telemetry (auto-instrument logs) if feature enabled,
# with settings precedence: OTEL_* > SW_APM_EXPORT_LOGS_ENABLED.
# TODO NH-107164 drop support of SW config, and super() will only check OTEL config
setup_logging_handler = False
# We don't set a default, so this could be None
otel_log_enabled = SolarWindsApmConfig.convert_to_bool(
os.environ.get(_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED)
# Only emit log event telemetry (auto-instrument logs) if feature enabled.
# Distro does not set a default, so this could be None
setup_logging_handler = SolarWindsApmConfig.convert_to_bool(
os.environ.get(
_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, False
)
)
# SW config is False by default
# TODO NH-101930 remove this check
sw_log_enabled = self.apm_config.get("export_logs_enabled")
if otel_log_enabled is not None:
if otel_log_enabled is True:
setup_logging_handler = True
elif sw_log_enabled:
setup_logging_handler = True
if sw_log_enabled:
logger.warning(
"Support for SW_APM_EXPORT_LOG_ENABLED / exportLogsEnabled "
"has been dropped. Please update use "
"OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED instead."
)

_init_logging(log_exporters, apm_resource, setup_logging_handler)

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_configurator/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def get_apmconfig_mocks(
def get_side_effect(param):
if param == "export_metrics_enabled":
return export_metrics_enabled
# TODO NH-101930 remove export_logs_enabled
elif param == "export_logs_enabled":
return export_logs_enabled
elif param == "service_key":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

import logging
import os
import pytest
import uuid

from opentelemetry.sdk.environment_variables import (
Expand All @@ -15,6 +17,12 @@
from solarwinds_apm import configurator


@pytest.fixture
def setup_caplog():
apm_logger = logging.getLogger("solarwinds_apm")
apm_logger.propagate = True


class TestConfiguratorCreateApmResource:
def test_create_apm_resource_basic(self, mocker, mock_apmconfig_enabled):
mocker.patch(
Expand Down Expand Up @@ -156,6 +164,8 @@ def helper_test_configure_otel_components_logs_enabled(

def test_configure_otel_components_logs_enabled_true_by_otel_sw_default(
self,
caplog,
setup_caplog,
mocker,
mock_apmconfig_enabled_export_logs_false,

Expand All @@ -176,12 +186,15 @@ def test_configure_otel_components_logs_enabled_true_by_otel_sw_default(
mock_config_propagator,
mock_config_response_propagator,
"true",
True,
True, # True because OTEL log instrumentation set to true
True,
)
assert "Support for SW_APM_EXPORT_LOG_ENABLED / exportLogsEnabled has been dropped" not in caplog.text

def test_configure_otel_components_logs_enabled_otel_none_sw_default(self,
mocker,
caplog,
setup_caplog,
mock_apmconfig_enabled_export_logs_false,

mock_config_serviceentry_processor,
Expand All @@ -201,10 +214,13 @@ def test_configure_otel_components_logs_enabled_otel_none_sw_default(self,
mock_config_propagator,
mock_config_response_propagator,
"",
False,
None, # none because OTEL log instrumentation not set
)
assert "Support for SW_APM_EXPORT_LOG_ENABLED / exportLogsEnabled has been dropped" not in caplog.text

def test_configure_otel_components_logs_enabled_otel_none_sw_true(self,
caplog,
setup_caplog,
mocker,
mock_apmconfig_enabled,

Expand All @@ -225,11 +241,14 @@ def test_configure_otel_components_logs_enabled_otel_none_sw_true(self,
mock_config_propagator,
mock_config_response_propagator,
"",
True, # true because SW next in precedence
None, # none because OTEL log instrumentation not set
)
assert "Support for SW_APM_EXPORT_LOG_ENABLED / exportLogsEnabled has been dropped" in caplog.text

def test_configure_otel_components_logs_enabled_otel_false_sw_default(self,
mocker,
caplog,
setup_caplog,
mock_apmconfig_enabled_export_logs_false,

mock_config_serviceentry_processor,
Expand All @@ -249,10 +268,14 @@ def test_configure_otel_components_logs_enabled_otel_false_sw_default(self,
mock_config_propagator,
mock_config_response_propagator,
"false",
False, # False because OTEL log instrumentation False
False,
)
assert "Support for SW_APM_EXPORT_LOG_ENABLED / exportLogsEnabled has been dropped" not in caplog.text

def test_configure_otel_components_logs_enabled_otel_false_sw_true(self,
caplog,
setup_caplog,
mocker,
mock_apmconfig_enabled,

Expand All @@ -276,9 +299,12 @@ def test_configure_otel_components_logs_enabled_otel_false_sw_true(self,
False, # should be false because OTEL explicitly false, even if SW true
False,
)
assert "Support for SW_APM_EXPORT_LOG_ENABLED / exportLogsEnabled has been dropped" in caplog.text

def test_configure_otel_components_logs_enabled_otel_invalid(self,
mocker,
caplog,
setup_caplog,
mock_apmconfig_enabled_export_logs_false,

mock_config_serviceentry_processor,
Expand All @@ -298,8 +324,9 @@ def test_configure_otel_components_logs_enabled_otel_invalid(self,
mock_config_propagator,
mock_config_response_propagator,
"not-a-bool-string",
False,
None, # None because OTEL log instrumentation not valid bool
)
assert "Support for SW_APM_EXPORT_LOG_ENABLED / exportLogsEnabled has been dropped" not in caplog.text

def test_configure_otel_components_agent_enabled(
self,
Expand All @@ -318,6 +345,11 @@ def test_configure_otel_components_agent_enabled(
"solarwinds_apm.configurator.SolarWindsApmConfig",
return_value=mock_apmconfig_enabled,
)
# Mock return of _OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED
mocker.patch(
"solarwinds_apm.configurator.SolarWindsApmConfig.convert_to_bool",
return_value=False,
)
mock_apm_sampler = mocker.Mock()
mocker.patch(
"solarwinds_apm.configurator.ParentBasedSwSampler",
Expand Down
Loading