Counters are just that: they count numbers together. You create a counter, pass it a value and it will add it to the existing total. How is this different than a gauge?
The intention from counters in metrics is to track the rate of change. It’s not about the absolute value like a gauge.
You can increase a counter in small increments quickly, or large steps less frequently: +1 every second for 5 seconds, or +5 every 5 seconds. Both will produce the same rate of change.
Metrics counter isn’t continuous like a gauge. It doesn’t keep syncing the value with the dashboard and there is no absolute value sent or stored.
Creating a counter is nearly identical to a gauge:
let openTelemetry = OpenTelemetry.instance
let meter = openTelemetry.meterProvider.meterBuilder(name: "NAME_OF_METRICS_GROUP").build()
var counter = meter.counterBuilder(name: "NAME_OF_THE_COUNTER").build()
counter.add(value: 1.0)
Example of a counter to count search total on OpenTelemetry Dashboard
An easy way to imagine the usage of a counter is counting your typing speed:
OpenTelemetry Metrics will upload the added telemetry every 5 seconds (based on how you configure your exporter).
You start typing, which each letter you add 1 to your counter.
With each telemetry upload a new total is sent to the dashboard.
The slower you type, the smaller those increments are. It doesn’t matter how many characters you entered at the end because what’s measured is your speed so time is a factor.
Note that this counter is only a positive counter. Using it to measure how fast your memory is increasing will be fine if you know that it will move in one direction only, and you are not freeing up any memory in your app… (not a good practice tho :] )
See forum comments
This content was released on Oct 24 2025. The official support period is 6-months
from this date.
In this section, You’ll learn about Counters in OpenTelemetry Metrics
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.