-
Notifications
You must be signed in to change notification settings - Fork 13
feat: Setup metric provider for manual and auto-instrumented measurements #126
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
morgan-wowk
wants to merge
1
commit into
signal-specific-exporters
Choose a base branch
from
setup-metric-provider
base: signal-specific-exporters
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
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
30 changes: 30 additions & 0 deletions
30
cloud_pipelines_backend/instrumentation/opentelemetry/_internal/temporality.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,30 @@ | ||
| """ | ||
| Maps string-based temporality configuration to OTel SDK types. | ||
| """ | ||
|
|
||
| from opentelemetry import metrics as otel_metrics | ||
| from opentelemetry.sdk import metrics as otel_sdk_metrics | ||
| from opentelemetry.sdk.metrics import export as otel_metrics_export | ||
|
|
||
| from cloud_pipelines_backend.instrumentation.opentelemetry._internal import config | ||
|
|
||
| _TEMPORALITY_MAP = { | ||
| config.AggregationTemporality.DELTA: otel_metrics_export.AggregationTemporality.DELTA, | ||
| config.AggregationTemporality.CUMULATIVE: otel_metrics_export.AggregationTemporality.CUMULATIVE, | ||
| } | ||
|
|
||
|
|
||
| def build_preferred_temporality( | ||
| temporality: config.MetricsTemporalityConfig, | ||
| ) -> dict[type[otel_metrics.Instrument], otel_metrics_export.AggregationTemporality]: | ||
| return { | ||
| otel_sdk_metrics.Counter: _TEMPORALITY_MAP[temporality.counter], | ||
| otel_sdk_metrics.ObservableCounter: _TEMPORALITY_MAP[ | ||
| temporality.observable_counter | ||
| ], | ||
| otel_sdk_metrics.UpDownCounter: _TEMPORALITY_MAP[temporality.up_down_counter], | ||
| otel_sdk_metrics.ObservableUpDownCounter: _TEMPORALITY_MAP[ | ||
| temporality.observable_up_down_counter | ||
| ], | ||
| otel_sdk_metrics.Histogram: _TEMPORALITY_MAP[temporality.histogram], | ||
| } |
12 changes: 8 additions & 4 deletions
12
cloud_pipelines_backend/instrumentation/opentelemetry/_internal/tests/conftest.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 |
|---|---|---|
| @@ -1,14 +1,18 @@ | ||
| import pytest | ||
| from opentelemetry import metrics as otel_metrics | ||
| from opentelemetry import trace | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def reset_otel_tracer_provider(): | ||
| """Reset the global OTel tracer provider between tests. | ||
| def reset_otel_providers(): | ||
| """Reset global OTel providers between tests. | ||
|
|
||
| OTel only allows set_tracer_provider to be called once per process. | ||
| We reset the internal guard so each test gets a clean slate. | ||
| OTel only allows set_tracer_provider / set_meter_provider to be called | ||
| once per process. We reset the internal guards so each test gets a | ||
| clean slate. | ||
| """ | ||
| yield | ||
| trace._TRACER_PROVIDER_SET_ONCE._done = False | ||
| trace._TRACER_PROVIDER = trace.ProxyTracerProvider() | ||
| otel_metrics._internal._METER_PROVIDER_SET_ONCE._done = False | ||
| otel_metrics._internal._METER_PROVIDER = None |
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.