Skip to content

Commit 6c3b703

Browse files
authored
Fix start_time_unix nano for delta collection temporality for ExplicitBucketHistogramAggregation (#4009)
Fixes #4008
1 parent c6fb299 commit 6c3b703

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10-
- Fix `start_time_unix_nano` for delta collection for sum aggregation
10+
- Fix `start_time_unix_nano` for delta collection for explicit bucket histogram aggregation
1111
([#4009](https://github.com/open-telemetry/opentelemetry-python/pull/4009))
12+
- Fix `start_time_unix_nano` for delta collection for sum aggregation
13+
([#4011](https://github.com/open-telemetry/opentelemetry-python/pull/4011))
1214
- Do not execute Flask Tests in debug mode
1315
([#3956](https://github.com/open-telemetry/opentelemetry-python/pull/3956))
1416
- When encountering an error encoding metric attributes in the OTLP exporter, log the key that had an error.

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/aggregation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -471,16 +471,16 @@ def collect(
471471
is AggregationTemporality.DELTA
472472
):
473473

474-
if current_value is None:
475-
return None
476-
477474
previous_collection_start_nano = (
478475
self._previous_collection_start_nano
479476
)
480477
self._previous_collection_start_nano = (
481478
collection_start_nano
482479
)
483480

481+
if current_value is None:
482+
return None
483+
484484
return HistogramDataPoint(
485485
attributes=self._attributes,
486486
start_time_unix_nano=previous_collection_start_nano,

opentelemetry-sdk/tests/metrics/integration_test/test_explicit_bucket_histogram_aggregation.py

+35-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
from platform import system
16+
from time import sleep
1617
from unittest import TestCase
1718

1819
from pytest import mark
@@ -123,11 +124,43 @@ def test_synchronous_delta_temporality(self):
123124

124125
results.append(reader.get_metrics_data())
125126

126-
provider.shutdown()
127-
128127
for metrics_data in results:
129128
self.assertIsNone(metrics_data)
130129

130+
results = []
131+
132+
histogram.record(1)
133+
results.append(reader.get_metrics_data())
134+
135+
sleep(0.1)
136+
results.append(reader.get_metrics_data())
137+
138+
histogram.record(2)
139+
results.append(reader.get_metrics_data())
140+
141+
metric_data_0 = (
142+
results[0]
143+
.resource_metrics[0]
144+
.scope_metrics[0]
145+
.metrics[0]
146+
.data.data_points[0]
147+
)
148+
metric_data_2 = (
149+
results[2]
150+
.resource_metrics[0]
151+
.scope_metrics[0]
152+
.metrics[0]
153+
.data.data_points[0]
154+
)
155+
156+
self.assertIsNone(results[1])
157+
158+
self.assertGreater(
159+
metric_data_2.start_time_unix_nano, metric_data_0.time_unix_nano
160+
)
161+
162+
provider.shutdown()
163+
131164
@mark.skipif(
132165
system() != "Linux",
133166
reason=(

0 commit comments

Comments
 (0)