Repository navigation
fix(metrics): assign start_time_unix_nano for Gauge metrics in SDK and encoders (#5849) - #5852
ImamWahyudiz wants to merge 3 commits into
Conversation
|
|
Pull request dashboard statusWaiting on reviewers · refreshed 2026-11-05 17:25 UTC Review the latest changes. Status above doesn't look right?
|
| @@ -0,0 +1 @@ | |||
| `opentelemetry-sdk`: assign and preserve `start_time_unix_nano` for Gauge metrics in `_LastValueAggregation` and OTLP encoders | |||
There was a problem hiding this comment.
As per CONTRIBUTING.md, the changelog filename should match the PR number: .changelog/5852.fixed.
There was a problem hiding this comment.
Thanks for the correction! renamed .changelog/5849.fixed to .changelog/5852.fixed to match the PR number.
| attributes: Attributes, | ||
| reservoir_builder: ExemplarReservoirBuilder, | ||
| instrument_is_synchronous: bool, | ||
| start_time_unix_nano: int = 0, |
There was a problem hiding this comment.
Should this default to None (int | None = None) to avoid setting start_time_unix_nano=0 (epoch 0) when no start time is provided?
There was a problem hiding this comment.
Good point.
Updated the default and annotation to int | None = None. This avoids defaulting to Unix epoch 0 when unsupplied, while preserving the optional Gauge start time semantics per the specification.
|
@Dotify71 Thanks for the review! I've spotted the inline notes about the changelog filename and default parameter typing. |
Dotify71
left a comment
There was a problem hiding this comment.
Thanks for updating both the changelog filename and the default parameter typing so quickly, @ImamWahyudiz
Everything looks very clean and well-aligned with the spec now. LGTM... Thanks
Pull Request: sdk/metrics: assign and encode start_time_unix_nano for Gauge (#5849)
Description
Per the MetricReader specification and Start timestamps specification,
StartTimeUnixNanorules apply to all metrics according to theMetricReader's configured temporality for the instrument kind, "not just those whose point kinds includes an aggregation temporality field."Prior to this PR,
GaugeandObservableGauge(LastValueaggregation) omittedstart_time_unix_nano:_LastValueAggregation.__init__omittedstart_time_unix_nano.DefaultAggregation._create_aggregation()andLastValueAggregation._create_aggregation()did not forwardstart_time_unix_nanoto_LastValueAggregation._LastValueAggregation.collect()explicitly assignedstart_time_unix_nano=Nonewhen creatingNumberDataPoint.proto/common/_internal/metrics_encoder/__init__.py) and OTLP JSON encoder (json/common/_internal/metrics_encoder/__init__.py) omittedstart_time_unix_nano=data_point.start_time_unix_nanowhen instantiatingpb2.NumberDataPointandJSONNumberDataPointfor Gauge metrics.Solution
opentelemetry-sdk:_LastValueAggregation.__init__to accept and storestart_time_unix_nano: int = 0.DefaultAggregation._create_aggregation()andLastValueAggregation._create_aggregation()to passstart_time_unix_nanointo_LastValueAggregation._LastValueAggregation.collect()to assignstart_time_unix_nano=self._start_time_unix_nanotoNumberDataPoint.opentelemetry-exporter-otlp-proto-common:start_time_unix_nano=data_point.start_time_unix_nanowhen instantiatingpb2.NumberDataPointfor Gauge metrics in_encode_metric().opentelemetry-exporter-otlp-json-common:start_time_unix_nano=data_point.start_time_unix_nanoin_encode_gauge_data_point().test_aggregation.pyto assertstart_time_unix_nano.test_encode_gauge_with_start_timeintest_metrics_encoder.pyfor Protobuf encoding.make_gauge()in JSON encoder tests and assertedstart_time_unix_nanointest_encode_gauge..changelog/5849.fixed.Type of Change
Testing & Verification
Checklist
ruff check,ruff format)..changelog/5849.fixed.