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-88274 Add support for SW_APM_EXPORT_METRICS_ENABLED #439

Merged
merged 18 commits into from
Oct 7, 2024

Conversation

tammy-baylis-swi
Copy link
Contributor

@tammy-baylis-swi tammy-baylis-swi commented Oct 3, 2024

Adds support for SW_APM_EXPORT_METRICS_ENABLED=true/false as an opt-in for OTLP metrics export. A documentation update PR will follow.

Under the hood, custom distro does several setdefault of configs. Please note that, even though setdefault is called for metrics endpoint, headers, etc, the metrics exporter will only be initialized by the Configurator if SW_APM_EXPORT_METRICS_ENABLED=true. Another key part is that setdefault only sets defaults; user can configure their own OTel metrics endpoint, headers, etc via environment variable and those will be respected by Configurator component inits.

To get all of metrics, logs and traces to export by OTLP, need to set all of SW_APM_EXPORT_METRICS_ENABLED, SW_APM_EXPORT_LOGS_ENABLED, and OTEL_EXPORTER_OTLP_PROTOCOL (one of http/protobuf, grpc).

See ticket comments for manual testing results.

Please let me know if any thoughts, questions, concerns! 😺

if not apm_config.agent_enabled:
logger.error("Tracing disabled. Cannot set trace exporter.")
logger.error(
"APM Python library disabled. Cannot set traces exporters."
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing _configure_traces_exporter, just updating docstring and error log for consistency.


def test_configure_metrics_exporter_flag_not_set(
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Comment on lines +471 to +475
if not apm_config.agent_enabled:
logger.error(
"APM Python library disabled. Cannot set logs exporters."
)
return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously missing for _configure_logs_exporter, so I've added it now.

Comment on lines +392 to +396
if not apm_config.agent_enabled:
logger.error(
"APM Python library disabled. Cannot set metrics exporters."
)
return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously missing for _configure_metrics_exporter, so I've added it now.

@tammy-baylis-swi tammy-baylis-swi force-pushed the NH-88274-sw-export-metrics-enabled branch from c4969a0 to 98a7bac Compare October 4, 2024 16:19
Comment on lines +449 to +452
# Use default interval 60s else OTEL_METRIC_EXPORT_INTERVAL
reader = PeriodicExportingMetricReader(
exporter,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes export outside of lambda which wasn't tested much before.

@tammy-baylis-swi tammy-baylis-swi marked this pull request as ready for review October 4, 2024 22:57
@tammy-baylis-swi tammy-baylis-swi requested a review from a team as a code owner October 4, 2024 22:57
@@ -169,6 +170,9 @@ def __init__(
self.metric_format = self._calculate_metric_format()
self.certificates = self._calculate_certificates()
self.__config["export_logs_enabled"] = self._calculate_logs_enabled()
self.__config["export_metrics_enabled"] = (

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.

Copy link
Contributor Author

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.

Copy link

@jerrytfleung jerrytfleung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I left a comment about nits.

@tammy-baylis-swi tammy-baylis-swi merged commit cb571fe into main Oct 7, 2024
59 checks passed
@tammy-baylis-swi tammy-baylis-swi deleted the NH-88274-sw-export-metrics-enabled branch October 7, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants