You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I expect the following code to show both gauge & counter every 1s in the console (or when scrapped by prometheus client) but it does not. counter is always there. gauge is there when launching the script (very first seconds) then disapears.
import random
import time
from prometheus_client import start_http_server
from opentelemetry.exporter.prometheus import PrometheusMetricReader
from opentelemetry.metrics import get_meter_provider, set_meter_provider
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import (
ConsoleMetricExporter,
PeriodicExportingMetricReader,
)
# Start Prometheus client
start_http_server(port=8000, addr="0.0.0.0")
# Exporter to export metrics to Prometheus
prefix = "MyAppPrefix"
reader = PrometheusMetricReader(prefix)
reader2 = PeriodicExportingMetricReader(ConsoleMetricExporter(), export_interval_millis=1_000)
# Meter is responsible for creating and recording metrics
set_meter_provider(MeterProvider(metric_readers=[reader, reader2]))
meter = get_meter_provider().get_meter("view-name-change", "0.1.2")
my_counter = meter.create_counter("my.counter")
my_gauge = meter.create_gauge("my.gauge")
while 1:
my_gauge.set(random.randint(1, 10))
my_counter.add(random.randint(1, 10))
time.sleep(61)
This is the expected behavior no? Like, gauge uses LastValueAggregation, it will be exported when you have a new value to export, like when you call gauge.set() again
This is the expected behavior no? Like, gauge uses LastValueAggregation, it will be exported when you have a new value to export, like when you call gauge.set() again
For synchronous instruments with Cumulative aggregation temporality, MetricReader.Collect MUST receive data points exposed in previous collections regardless of whether new measurements have been recorded.
This is the expected behavior no? Like, gauge uses LastValueAggregation, it will be exported when you have a new value to export, like when you call gauge.set() again
For synchronous instruments with Cumulative aggregation temporality, MetricReader.Collect MUST receive data points exposed in previous collections regardless of whether new measurements have been recorded.
Cumulative is the default temporality
hmmm. Indeed, this should be fixed then. Just checked go-sdk and it retains the last value for synchronous instruments when the reader uses cumulative temporality
A simple test that fails at main if useful. Thanks and feel free to open a PR
I was also unsure if it's a bug since Gauge points don't have a temporality, but taking a closer look at the spec it's pretty clear (emphasis added)
For synchronous instruments with Cumulative aggregation temporality, MetricReader.Collect MUST receive data points exposed in previous collections regardless of whether new measurements have been recorded. [...] These rules apply to all metrics, not just those whose point kinds includes an aggregation temporality field.
Activity
emdneto commentedon Apr 3, 2025
This is the expected behavior no? Like, gauge uses LastValueAggregation, it will be exported when you have a new value to export, like when you call gauge.set() again
pmcollins commentedon Apr 7, 2025
Hi @Filigran-Automation -- have you looked at using an
ObservableGaugeinstead?kacper-wolkiewicz-reef commentedon Sep 4, 2026
I think it's contrary to otel specification and should be fixed: https://opentelemetry.io/docs/specs/otel/metrics/sdk/?utm_source=chatgpt.com#metricreader
Cumulative is the default temporality
emdneto commentedon Sep 4, 2026
hmmm. Indeed, this should be fixed then. Just checked go-sdk and it retains the last value for synchronous instruments when the reader uses cumulative temporality
A simple test that fails at main if useful. Thanks and feel free to open a PR
fix(opentelemetry-sdk): keep synchronous gauge values across cumulati…
kacper-wolkiewicz-reef commentedon Sep 7, 2026
@emdneto Here it is! #5637
aabmass commentedon Sep 10, 2026
I was also unsure if it's a bug since Gauge points don't have a temporality, but taking a closer look at the spec it's pretty clear (emphasis added)
fix(opentelemetry-sdk): keep synchronous gauge values across cumulati…