Skip to content

Commit

Permalink
First propagation of filter and reservoir factory
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Aug 12, 2024
1 parent 3b1e40d commit 05ebc34
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 37 deletions.
3 changes: 3 additions & 0 deletions opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from opentelemetry.sdk.metrics._internal import Meter, MeterProvider
from opentelemetry.sdk.metrics._internal.exceptions import MetricsTimeoutError
from opentelemetry.sdk.metrics._internal.exemplar import ExemplarFilter, ExemplarReservoir
from opentelemetry.sdk.metrics._internal.instrument import Counter
from opentelemetry.sdk.metrics._internal.instrument import Gauge as _Gauge
from opentelemetry.sdk.metrics._internal.instrument import (
Expand All @@ -26,6 +27,8 @@
)

__all__ = [
"ExemplarFilter",
"ExemplarReservoir",
"Meter",
"MeterProvider",
"MetricsTimeoutError",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from opentelemetry.metrics import _Gauge as APIGauge
from opentelemetry.sdk.environment_variables import OTEL_SDK_DISABLED
from opentelemetry.sdk.metrics._internal.exceptions import MetricsTimeoutError
from opentelemetry.sdk.metrics._internal.exemplar import ExemplarFilter, TraceBasedExemplarFilter
from opentelemetry.sdk.metrics._internal.instrument import (
_Counter,
_Gauge,
Expand Down Expand Up @@ -381,6 +382,7 @@ def __init__(
"opentelemetry.sdk.metrics.export.MetricReader"
] = (),
resource: Resource = None,
exemplar_filter: Optional[ExemplarFilter] = None,
shutdown_on_exit: bool = True,
views: Sequence["opentelemetry.sdk.metrics.view.View"] = (),
):
Expand All @@ -390,6 +392,7 @@ def __init__(
if resource is None:
resource = Resource.create({})
self._sdk_config = SdkConfiguration(
exemplar_filter = TraceBasedExemplarFilter() if exemplar_filter is None else exemplar_filter,
resource=resource,
metric_readers=metric_readers,
views=views,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def conflicts(self, other: "_ViewInstrumentMatch") -> bool:
return result

# pylint: disable=protected-access
def consume_measurement(self, measurement: Measurement) -> None:
def consume_measurement(self, measurement: Measurement, should_sample_exemplar: bool = True) -> None:

if self._view._attribute_keys is not None:

Expand All @@ -107,6 +107,7 @@ def consume_measurement(self, measurement: Measurement) -> None:
self._view._aggregation._create_aggregation(
self._instrument,
attributes,
self._view._exemplar_reservoir_factory,
self._start_time_unix_nano,
)
)
Expand All @@ -116,11 +117,12 @@ def consume_measurement(self, measurement: Measurement) -> None:
]._create_aggregation(
self._instrument,
attributes,
self._view._exemplar_reservoir_factory,
self._start_time_unix_nano,
)
self._attributes_aggregation[aggr_key] = aggregation

self._attributes_aggregation[aggr_key].aggregate(measurement)
self._attributes_aggregation[aggr_key].aggregate(measurement, should_sample_exemplar)

def collect(
self,
Expand Down
Loading

0 comments on commit 05ebc34

Please sign in to comment.