-
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
Conversation
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 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( |
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.
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.
if not apm_config.agent_enabled: | ||
logger.error( | ||
"APM Python library disabled. Cannot set logs exporters." | ||
) | ||
return |
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.
This was previously missing for _configure_logs_exporter
, so I've added it now.
if not apm_config.agent_enabled: | ||
logger.error( | ||
"APM Python library disabled. Cannot set metrics exporters." | ||
) | ||
return |
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.
This was previously missing for _configure_metrics_exporter
, so I've added it now.
c4969a0
to
98a7bac
Compare
# Use default interval 60s else OTEL_METRIC_EXPORT_INTERVAL | ||
reader = PeriodicExportingMetricReader( | ||
exporter, | ||
) |
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.
This fixes export outside of lambda which wasn't tested much before.
@@ -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"] = ( |
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.
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.
LGTM. I left a comment about nits.
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 thoughsetdefault
is called for metrics endpoint, headers, etc, the metrics exporter will only be initialized by the Configurator ifSW_APM_EXPORT_METRICS_ENABLED=true
. Another key part is thatsetdefault
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
, andOTEL_EXPORTER_OTLP_PROTOCOL
(one ofhttp/protobuf
,grpc
).See ticket comments for manual testing results.
Please let me know if any thoughts, questions, concerns! 😺