Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NH-76217 Fix init event logging #345

Merged
merged 1 commit into from
Mar 26, 2024
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
6 changes: 6 additions & 0 deletions solarwinds_apm/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def _configure(self, **kwargs: int) -> None:
apm_config = SolarWindsApmConfig()
oboe_api = apm_config.oboe_api

# Reporter may be no-op e.g. disabled, lambda
reporter = self._initialize_solarwinds_reporter(apm_config)
self._configure_otel_components(
apm_txname_manager,
Expand All @@ -99,6 +100,11 @@ def _configure(self, **kwargs: int) -> None:
reporter,
oboe_api,
)

if apm_config.is_lambda:
logger.debug("No init event in lambda")
return

# Report reporter init status event after everything is done.
init_event = self._create_init_event(reporter, apm_config)
if init_event:
Expand Down
59 changes: 53 additions & 6 deletions tests/unit/test_configurator/test_configurator_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,63 @@
from solarwinds_apm import configurator

class TestConfiguratorConfigure:
def test_configurator_configure_init_success(
def test_configurator_configure_init_lambda(
self,
mocker,
mock_txn_name_manager_init,
mock_fwkv_manager_init,
mock_apmconfig_enabled,
mock_init_sw_reporter,
mock_config_otel_components,
mock_create_init,
mock_report_init,
):
mock_apmconfig = mocker.Mock(
**{
"is_lambda": True,
}
)
apmconfig_init = mocker.patch(
"solarwinds_apm.configurator.SolarWindsApmConfig",
return_value=mock_apmconfig,
)

test_configurator = configurator.SolarWindsConfigurator()
test_configurator._configure()

mock_txn_name_manager_init.assert_called_once()
mock_fwkv_manager_init.assert_called_once()
mock_apmconfig_enabled.assert_called_once()
apmconfig_init.assert_called_once()
mock_init_sw_reporter.assert_called_once()
mock_config_otel_components.assert_called_once()
mock_create_init.assert_not_called()
mock_report_init.assert_not_called()

def test_configurator_configure_init_success(
self,
mocker,
mock_txn_name_manager_init,
mock_fwkv_manager_init,
mock_init_sw_reporter,
mock_config_otel_components,
mock_create_init,
mock_report_init,
):
mock_apmconfig = mocker.Mock(
**{
"is_lambda": False,
}
)
apmconfig_init = mocker.patch(
"solarwinds_apm.configurator.SolarWindsApmConfig",
return_value=mock_apmconfig,
)

test_configurator = configurator.SolarWindsConfigurator()
test_configurator._configure()

mock_txn_name_manager_init.assert_called_once()
mock_fwkv_manager_init.assert_called_once()
apmconfig_init.assert_called_once()
mock_init_sw_reporter.assert_called_once()
mock_config_otel_components.assert_called_once()
mock_create_init.assert_called_once()
Expand All @@ -35,12 +74,21 @@ def test_configurator_configure_init_failure(
mocker,
mock_txn_name_manager_init,
mock_fwkv_manager_init,
mock_apmconfig_enabled,
mock_init_sw_reporter,
mock_config_otel_components,
mock_create_init_fail,
mock_report_init,
):
mock_apmconfig = mocker.Mock(
**{
"is_lambda": False,
}
)
apmconfig_init = mocker.patch(
"solarwinds_apm.configurator.SolarWindsApmConfig",
return_value=mock_apmconfig,
)

mock_log_error = mocker.Mock()
mock_logger = mocker.patch(
"solarwinds_apm.configurator.logger"
Expand All @@ -56,8 +104,7 @@ def test_configurator_configure_init_failure(

mock_txn_name_manager_init.assert_called_once()
mock_fwkv_manager_init.assert_called_once()
mock_apmconfig_enabled.assert_called_once()

apmconfig_init.assert_called_once()
mock_init_sw_reporter.assert_called_once()
mock_config_otel_components.assert_called_once()
mock_create_init_fail.assert_called_once()
Expand Down