-
Notifications
You must be signed in to change notification settings - Fork 867
feat: Add ability to selectively enable exporting of SDK internal metrics with the OTEL_PYTHON_SDK_INTERNAL_METRICS_ENABLED environment variable #5151
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
Open
herin049
wants to merge
11
commits into
open-telemetry:main
Choose a base branch
from
herin049:feat/skd-metrics-opt-in
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d9efda9
feat: Add ability to selectively enable exporting of SDK internal met…
herin049 6a737e7
refactor ProcessorMetrics
herin049 910a576
remove unused instance variable
herin049 e065402
minor refactor
herin049 e528cde
update naming of internal metric environment variable
herin049 62069a8
Merge branch 'main' into feat/skd-metrics-opt-in
herin049 e0e25b7
update exporter metrics
herin049 2f58d4c
implementation suggestions
herin049 bca66cd
fix test errors
herin049 e67e6b9
fix proto common test errors
herin049 7bda95e
small tweak to exporter metrics test
herin049 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
exporter/opentelemetry-exporter-otlp-proto-common/tests/test_exporter_metrics.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # Copyright The OpenTelemetry Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import unittest | ||
| from unittest.mock import Mock, patch | ||
| from urllib.parse import urlparse | ||
|
|
||
| from opentelemetry.exporter.otlp.proto.common._exporter_metrics import ( | ||
| ExporterMetrics, | ||
| NoOpExporterMetrics, | ||
| create_exporter_metrics, | ||
| ) | ||
| from opentelemetry.semconv._incubating.attributes.otel_attributes import ( | ||
| OtelComponentTypeValues, | ||
| ) | ||
|
|
||
|
|
||
| class TestExporterMetrics(unittest.TestCase): | ||
| def test_factory_returns_noop_when_disabled(self): | ||
| meter_provider = Mock() | ||
|
|
||
| with patch( | ||
| "opentelemetry.exporter.otlp.proto.common." | ||
| "_exporter_metrics.get_meter_provider" | ||
| ) as get_meter_provider: | ||
| metrics = create_exporter_metrics( | ||
| OtelComponentTypeValues.OTLP_HTTP_SPAN_EXPORTER, | ||
| "traces", | ||
| urlparse("http://localhost:4318/v1/traces"), | ||
| meter_provider, | ||
| False, | ||
| ) | ||
|
|
||
| self.assertIsInstance(metrics, NoOpExporterMetrics) | ||
| meter_provider.get_meter.assert_not_called() | ||
| get_meter_provider.assert_not_called() | ||
|
|
||
| def test_factory_returns_exporter_metrics_when_enabled(self): | ||
| meter_provider = Mock() | ||
| meter_provider.get_meter.return_value = Mock() | ||
|
|
||
| metrics = create_exporter_metrics( | ||
| OtelComponentTypeValues.OTLP_HTTP_SPAN_EXPORTER, | ||
| "traces", | ||
| urlparse("http://localhost:4318/v1/traces"), | ||
| meter_provider, | ||
| True, | ||
| ) | ||
|
|
||
| self.assertIsInstance(metrics, ExporterMetrics) | ||
| meter_provider.get_meter.assert_called_once_with("opentelemetry-sdk") | ||
|
|
||
| def test_noop_export_operation_yields_result(self): | ||
| metrics = NoOpExporterMetrics() | ||
|
|
||
| with metrics.export_operation(1) as result: | ||
| result.error = RuntimeError("error") | ||
|
|
||
| self.assertIsInstance(result.error, RuntimeError) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 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.
Uh oh!
There was an error while loading. Please reload this page.
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.
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_variablesymbol go away in a future sdk we break the contract.Uh oh!
There was an error while loading. Please reload this page.
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 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_PROVIDERfromopentelemetry.sdk.environment_variables, so technically we can never remove_OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDERanymore 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.