Fix labelled heartbeat metrics reporting 0 with a buffered meter - #1593
Open
Mahnoor-Zaffar wants to merge 2 commits into
Open
Fix labelled heartbeat metrics reporting 0 with a buffered meter#1593Mahnoor-Zaffar wants to merge 2 commits into
Mahnoor-Zaffar wants to merge 2 commits into
Conversation
Sushisource
reviewed
Sep 8, 2026
Sushisource
left a comment
Member
There was a problem hiding this comment.
Overall I think this makes sense but we shouldn't need to be pulling in any updates from api_upstream in this PR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & Why
When a worker is configured with a buffered metric meter (e.g. the Python SDK's
MetricBuffer), every labelled worker-heartbeat metric — all slot counts and all poller counts — is reported to the server as0, even though the worker is demonstrably serving work. Unlabelled heartbeat metrics (total_processed_tasks, etc.) are unaffected.Root cause: Worker heartbeats do not query slot suppliers/pollers directly. They read
AtomicU64s that the metrics pipeline writes as a side effect viagauge_with_in_memory→HeartbeatMetricType::WithLabel. The label lookup inlabel_value_from_attributesonly handledPrometheus,OTel, andNoOp;MetricAttributes::Bufferfell through toNone, so the atomic was never written and kept its#[derive(Default)]value of0.The buffered handle is an opaque
LazyRef<Arc<dyn CustomMetricAttributes>>(a Python-heldPyDictin the Python bridge), which core cannot read without taking a GIL — exactly what the buffered design avoids. So core retains theVec<MetricKeyValue>it already has in hand at attribute-creation time instead.Changes
temporalio-common:MetricAttributes::Buffernow also carries a core-sidekvs: Arc<Vec<MetricKeyValue>>snapshot;label_value_from_attributesresolves labels from it.temporalio-sdk-core:MetricsCallBuffer::new_attributes/extend_attributescapture the kvs (merging last-wins on extend);BufferInstrument::senddestructures the new shape. TheMetricEventprotocol is unchanged, so language bridges compile untouched.HeartbeatMetricTypeandMetricsContext/in_memory_meterlevels, plus abufferedbacking added to the worker-heartbeat integration test.Unreleased.Validation
cargo test -p temporalio-common --features core-telemetry-bridge --lib in_memory_attributes_provide_label_values— passcargo test -p temporalio-sdk-core --lib telemetry::metrics— pass (incl. new regression; confirmed it fails without the fix)cargo +nightly fmt --checkclean.Fixes the Python SDK issue reported in temporalio/sdk-python#1817.