-
Notifications
You must be signed in to change notification settings - Fork 1
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-88274 Add support for SW_APM_EXPORT_METRICS_ENABLED #439
Changes from 2 commits
e5dbc15
1917ec6
72be5ca
cfbc9d7
98a7bac
5a2b775
e74df75
0f4055e
6b9ad75
2df8cae
05d39cf
d77c5f1
2c9e4ee
53fd4ff
86eea28
bd722fc
85c61b7
d0cb0f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -313,13 +313,15 @@ def _configure_traces_exporter( | |
apm_fwkv_manager: SolarWindsFrameworkKvManager, | ||
apm_config: SolarWindsApmConfig, | ||
) -> None: | ||
"""Configure SolarWinds OTel span exporters, defaults or environment | ||
configured, or none if agent disabled. | ||
"""Configure traces exporters if agent enabled. | ||
Links to global TracerProvider. | ||
|
||
Initialization of SolarWinds exporter requires a liboboe reporter | ||
Note: if reporter is no-op, the SW exporter will not export spans.""" | ||
If `reporter` is no-op, the SW exporter will not export spans.""" | ||
if not apm_config.agent_enabled: | ||
logger.error("Tracing disabled. Cannot set trace exporter.") | ||
logger.error( | ||
"APM Python library disabled. Cannot set traces exporters." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not changing |
||
) | ||
return | ||
|
||
# SolarWindsDistro._configure does setdefault before this is called | ||
|
@@ -384,8 +386,21 @@ def _configure_metrics_exporter( | |
self, | ||
apm_config: SolarWindsApmConfig, | ||
) -> None: | ||
"""Configure SolarWinds OTel metrics exporters if any configured. | ||
Links them to new metric readers and global MeterProvider.""" | ||
"""Configure OTel OTLP metrics exporters if enabled and agent enabled. | ||
Settings precedence: OTEL_* > SW_APM_EXPORT_METRICS_ENABLED. | ||
Links to new metric readers and global MeterProvider.""" | ||
if not apm_config.agent_enabled: | ||
logger.error( | ||
"APM Python library disabled. Cannot set metrics exporters." | ||
) | ||
return | ||
Comment on lines
+392
to
+396
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was previously missing for |
||
|
||
if not apm_config.get("export_metrics_enabled"): | ||
logger.debug( | ||
"APM OTLP metrics export disabled. Skipping init of metrics exporters" | ||
) | ||
return | ||
|
||
# SolarWindsDistro._configure does setdefault before this is called | ||
environ_exporter = os.environ.get( | ||
OTEL_METRICS_EXPORTER, | ||
|
@@ -450,9 +465,15 @@ def _configure_logs_exporter( | |
self, | ||
apm_config: SolarWindsApmConfig, | ||
) -> None: | ||
"""Configure OTel OTLP logs exporter if enabled. | ||
"""Configure OTel OTLP logs exporters if enabled and agent enabled. | ||
Settings precedence: OTEL_* > SW_APM_EXPORT_LOGS_ENABLED. | ||
Links to new global LoggerProvider.""" | ||
if not apm_config.agent_enabled: | ||
logger.error( | ||
"APM Python library disabled. Cannot set logs exporters." | ||
) | ||
return | ||
Comment on lines
+479
to
+483
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was previously missing for |
||
|
||
otel_ev = os.environ.get( | ||
_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED | ||
) | ||
|
@@ -469,7 +490,7 @@ def _configure_logs_exporter( | |
# then sw_enabled determines logs export setup. | ||
if not otlp_log_enabled and sw_enabled is False: | ||
logger.debug( | ||
"APM logs exports disabled. Skipping init of logs exporters" | ||
"APM OTLP logs export disabled. Skipping init of logs exporters" | ||
) | ||
return | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,11 +36,30 @@ def test_configure_metrics_exporter_disabled( | |
trace_mocks.get_tracer_provider().get_tracer.assert_not_called() | ||
mock_meterprovider.assert_not_called() | ||
|
||
def test_configure_metrics_exporter_sw_enabled_false( | ||
self, | ||
mocker, | ||
mock_apmconfig_metrics_enabled_false, | ||
mock_pemreader, | ||
mock_meterprovider, | ||
): | ||
# Mock Otel | ||
trace_mocks = get_trace_mocks(mocker) | ||
|
||
# Test! | ||
test_configurator = configurator.SolarWindsConfigurator() | ||
test_configurator._configure_metrics_exporter( | ||
mock_apmconfig_metrics_enabled_false, | ||
) | ||
mock_pemreader.assert_not_called() | ||
trace_mocks.get_tracer_provider.assert_not_called() | ||
trace_mocks.get_tracer_provider().get_tracer.assert_not_called() | ||
mock_meterprovider.assert_not_called() | ||
|
||
def test_configure_metrics_exporter_flag_not_set( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This must have tested an old flag that was temporarily implemented during early Lambda development. At some point I removed the flag but not the test, which didn't seem to be testing anything meaningful anymore. So I've repurposed to test new metrics enabled config. |
||
def test_configure_metrics_exporter_sw_enabled_none( | ||
self, | ||
mocker, | ||
mock_apmconfig_enabled, | ||
mock_apmconfig_metrics_enabled_none, | ||
mock_pemreader, | ||
mock_meterprovider, | ||
): | ||
|
@@ -50,7 +69,7 @@ def test_configure_metrics_exporter_flag_not_set( | |
# Test! | ||
test_configurator = configurator.SolarWindsConfigurator() | ||
test_configurator._configure_metrics_exporter( | ||
mock_apmconfig_enabled, | ||
mock_apmconfig_metrics_enabled_none, | ||
) | ||
mock_pemreader.assert_not_called() | ||
trace_mocks.get_tracer_provider.assert_not_called() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the bracket? I don't see the same in line 172.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linter did this, probably for slightly longer line char length.