Skip to content
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

Fix start_time_unix_nano for delta collection temporality for SumAggregation #4011

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Fix `start_time_unix_nano` for delta collection for sum aggregation
([#4009](https://github.com/open-telemetry/opentelemetry-python/pull/4009))
- Do not execute Flask Tests in debug mode
([#3956](https://github.com/open-telemetry/opentelemetry-python/pull/3956))
- When encountering an error encoding metric attributes in the OTLP exporter, log the key that had an error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,16 @@ def collect(
is AggregationTemporality.DELTA
):

if current_value is None:
return None

previous_collection_start_nano = (
self._previous_collection_start_nano
)
self._previous_collection_start_nano = (
collection_start_nano
)

if current_value is None:
return None

return NumberDataPoint(
attributes=self._attributes,
start_time_unix_nano=previous_collection_start_nano,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from itertools import count
from logging import ERROR
from platform import system
from time import sleep
from unittest import TestCase

from pytest import mark
Expand Down Expand Up @@ -345,11 +346,43 @@ def test_synchronous_delta_temporality(self):

results.append(reader.get_metrics_data())

provider.shutdown()

for metrics_data in results:
self.assertIsNone(metrics_data)

results = []

counter.add(1)
results.append(reader.get_metrics_data())

sleep(0.1)
results.append(reader.get_metrics_data())

counter.add(2)
results.append(reader.get_metrics_data())

metric_data_0 = (
results[0]
.resource_metrics[0]
.scope_metrics[0]
.metrics[0]
.data.data_points[0]
)
metric_data_2 = (
results[2]
.resource_metrics[0]
.scope_metrics[0]
.metrics[0]
.data.data_points[0]
)

self.assertIsNone(results[1])

self.assertGreater(
metric_data_2.start_time_unix_nano, metric_data_0.time_unix_nano
)

provider.shutdown()

@mark.skipif(
system() != "Linux",
reason=(
Expand Down