feat: Add ability to selectively enable exporting of SDK internal metrics with the OTEL_PYTHON_SDK_INTERNAL_METRICS_ENABLED environment variable#5151
Conversation
MikeGoldsmith
left a comment
There was a problem hiding this comment.
Looks great, thanks @herin049.
It would be good to replace existing env var parsing with the new parse_boolean_environment_variable helper you've added in a follow-up PR.
…rics with the OTEL_PYTHON_SDK_METRIC_ENABLE environment variable
c224202 to
e528cde
Compare
There was a problem hiding this comment.
Cool. I was implementing this and just saw your PR today.
@herin049 wdyt to instead use the concept of a NoOpExporterMetrics? This way, we also avoid creating the instruments.
Something like:
class NoOpExporterMetrics:
@contextmanager
def export_operation(self, num_items: int) -> Iterator[ExportResult]:
yield ExportResult()
And from a factory, you check the env var
def create_exporter_metrics(signal, endpoint, meter_provider):
if not parse_boolean_environment_variable(
OTEL_PYTHON_SDK_INTERNAL_METRICS_ENABLED,
default=False,
):
return NoOpExporterMetrics()
return ExporterMetrics(signal, endpoint, meter_provider)
I'm ok with the env var name 👍🏻
Updated the PR based on the suggestions. I opted to keep environment variable parsing outside of the factory method to keep configuration separate from construction (and to prevent having to add |
| OTEL_EXPORTER_OTLP_TIMEOUT, | ||
| OTEL_PYTHON_SDK_INTERNAL_METRICS_ENABLED, | ||
| ) | ||
| from opentelemetry.sdk.environment_variables._internal import ( |
There was a problem hiding this comment.
The exporters does not depend on latest sdk version so either we bump the baseline or we add an helper in otlp.proto.common and live with the duplication.
We should probably also write this relationship somewhere in text or in tests against the baseline and not only latest sdk, not in this PR but just thinking out of loud.
There was a problem hiding this comment.
Actually it's old exporter with new sdk so something more hard to test. But yeah the point is that if the parse_boolean_environment_variable symbol go away in a future sdk we break the contract.
There was a problem hiding this comment.
The same issue applies to all of the other imports from the SDK that the exporters use. For example, we use the experimental _OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER from opentelemetry.sdk.environment_variables, so technically we can never remove _OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER anymore from the SDK without breaking older versions of the HTTP exporter. While not ideal, I'd be more in favor of pinning the version of the SDK that exporters depend on to avoid potential scenarios like these in the future. Perhaps something to bring up in the SIG to get some other opinions.
Description
Adds ability to selectively enable/disable exporting of SDK internal metric collection with the introduction of the
OTEL_PYTHON_SDK_METRIC_ENABLEDenvironment variable.Motivation
While the "Stable by Default" OTEP has not been finalized yet, it is still preferrable to not emit unstable metric by default.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Does This PR Require a Contrib Repo Change?
Checklist: