Skip to content

feat(otel): add UseMonotonicCounters option for correct Prometheus counter type#2340

Open
apridosimarmata wants to merge 1 commit into
temporalio:mainfrom
apridosimarmata:fix/otel-monotonic-counter-option
Open

feat(otel): add UseMonotonicCounters option for correct Prometheus counter type#2340
apridosimarmata wants to merge 1 commit into
temporalio:mainfrom
apridosimarmata:fix/otel-monotonic-counter-option

Conversation

@apridosimarmata

Copy link
Copy Markdown

Problem

The OpenTelemetry metrics handler uses Int64UpDownCounter for all counters. This causes Prometheus to report Temporal counters (like workflow_completed) as gauges instead of counters with the _total suffix, since Int64UpDownCounter is non-monotonic.

See #2140 for details.

Solution

Added a UseMonotonicCounters option to MetricsHandlerOptions. When set to true, the handler creates counters using Int64Counter (monotonic) instead of Int64UpDownCounter.

The default remains false for backward compatibility, as discussed in the issue thread.

Usage

handler := opentelemetry.NewMetricsHandler(opentelemetry.MetricsHandlerOptions{
    Meter:                meterProvider.Meter("temporal-sdk-go"),
    UseMonotonicCounters: true,
})

Testing

Added TestMonotonicCounterHandler that verifies counters are reported with IsMonotonic: true when the option is enabled. All existing tests continue to pass.

Fixes #2140

@apridosimarmata apridosimarmata requested a review from a team as a code owner May 15, 2026 08:11
@CLAassistant

CLAassistant commented May 15, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Imam Aprido Simarmata seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

…unter type

Adds a UseMonotonicCounters option to MetricsHandlerOptions that switches
Counter() from Int64UpDownCounter to Int64Counter when enabled. This causes
Prometheus to correctly report counters with the _total suffix instead of
treating them as gauges.

The default remains Int64UpDownCounter for backward compatibility.

Fixes temporalio#2140
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenTelemetry incorrect metric type for Counter

2 participants