StatsD Counters as Gauges in the OpenTelemetry Collector

The Collector's StatsD receiver still defaults is_monotonic_counter to false, so counters arrive as gauges. The receiver fix, and the per-environment switch we built when the series count went over quota.

By VVV Ops ·

The OpenTelemetry Collector's StatsD receiver still ships with is_monotonic_counter: false, so every |c counter it receives leaves as a non-monotonic delta sum, which backends store as a gauge or drop. The project added a feature gate to flip the default in collector-contrib v0.160.0 on 2 September 2026, but the gate is alpha and off. A team we worked with hit exactly this when it moved application StatsD into the Collector: request counters arrived as gauges, and the first series count came to about 229k over 7 days, more than the metrics quota allowed.

We fixed the metric types first. The cardinality came second and needed a per-environment switch, because the vendor could only block metrics one at a time. For the general case of trimming Collector spend (filter processor, tail sampling, logs to metrics) see our OpenTelemetry Collector cost control post. This one stays on StatsD.

What the receiver emits by default

The receiver aggregates counters over its aggregation_interval (60s by default) and emits each one as an OTLP Sum with delta temporality. Whether that Sum is marked monotonic depends on one boolean. The receiver README lists is_monotonic_counter with "default value is false, or true if the receiver.statsd.monotonicCounterDefault feature gate is enabled".

A non-monotonic delta sum is awkward for almost every backend. The v0.160.0 changelog entry says the old default produced "non-monotonic delta sums that some exporters (e.g. the Prometheus exporter) convert to gauges." The Collector's own Prometheus exporter goes further. Its accumulator refuses the point outright, with the reason "non-monotonic sum with delta aggregation temporality is not supported", and logs that at debug level, so a default install shows nothing at all (accumulator.go).

The Prometheus compatibility spec explains why the flag matters. A monotonic delta sum "MAY be converted to a cumulative temporality and become a Prometheus Counter". A non-monotonic one has no such path. With the flag off, rate() has nothing to work on and dashboards show per-interval values that look like a gauge, because downstream that is what they are.

The reason the default stayed false for four years is in issue #14956: StatsD counts can in principle be negative, and a negative count belongs in a non-monotonic sum. The receiver README notes that the StatsD spec does not support negative counters and the receiver follows it, so for most fleets the flag is safe. Check your clients before you set it, since the flag is receiver-wide and cannot be set per metric.

Set the flag in config and leave the gate alone

Setting is_monotonic_counter: true in the receiver block is the whole fix for counters, and the changelog says an explicit setting "always takes precedence over the gate." We would not enable an alpha feature gate in production to get the same result. Alpha gates can change or disappear between releases, and the config key is stable and visible in review.

Timers need their own mapping

Timers are a separate setting from counters. The default timer_histogram_mapping in factory.go maps timer, histogram and distribution to the gauge observer, which the README describes as performing no aggregation. After our first change counters were right and timers were still gauges, which is what that default predicts.

# Illustrative receiver block: bucket edges are examples; MY_POD_IP comes from status.podIP in the DaemonSet
receivers:
  statsd:
    endpoint: "${env:MY_POD_IP}:8128"
    aggregation_interval: 60s
    is_monotonic_counter: true
    timer_histogram_mapping:
      - statsd_type: "timing"
        observer_type: "histogram"
        histogram:
          explicit_buckets:
            - matcher_pattern: ".*"
              buckets: [5, 10, 25, 50, 100, 250, 500, 1000, 2500]

Explicit buckets for timing metrics were broken until a fix in v0.157.0 ("Fix explicit bucket histogram mapping for StatsD timing metrics", #49747). On anything older the mapping above does not do what it says. The block lists only timing. If your clients also send |h or |d, add entries for histogram and distribution, because the gauge defaults apply only while you leave the whole key unset. We made the change on one test environment first, upgrading the Collector there with monotonic counters and explicit-bucket histograms before any other environment saw it.

One Collector per node, reached at status.hostIP

The README says the receiver "does not support horizontally scaled collector deployments" and is meant for agent mode. Aggregation happens inside one receiver instance, so two replicas behind a Service would each emit a partial count for the same series. A DaemonSet with a host port gives every pod a Collector on its own node, and the pod finds it through the downward API.

status.hostIP is "the primary IP address of the node to which the Pod is assigned", and it is available as an environment variable (not through a downwardAPI volume).

# Illustrative app pod env: STATSD_HOST and STATSD_PORT stand in for whatever your client reads
env:
  - name: HOST_IP
    valueFrom:
      fieldRef:
        fieldPath: status.hostIP
  - name: STATSD_HOST
    value: "$(HOST_IP)"
  - name: STATSD_PORT
    value: "8128"

Our engineer wrote a script that repointed each app's StatsD client to status.hostIP:8128 and tested it on 3 services. Using a port other than 8125 keeps the new path apart from any StatsD daemon still listening on the default.

The series count arrives before the quota does

The first measurement through the new path was about 229k series over 7 days, over the quota. Monotonic counters do not cause that, but they are what makes the metrics worth keeping, so the two problems land in the same week. We raised the number with aggregation advice and reviewed the team's tagging proposal. In a tagging review we look first for per-request identifiers sent as tags, and for tags that repeat the pod or host when the Collector's resource attributes already carry them.

Count series before you point the whole fleet at the Collector. Run one environment for a week, take the number to whoever owns the quota, and agree which tags to drop before the rollout.

A switch per environment, because blocking works per metric

The quota request was turned down. The observability platform could block a metric by name, but it had no way to block a metric in one environment and keep it in another, so blocking alone would have meant losing the metric everywhere. Our engineer designed a per-environment on/off switch instead.

The switch got its own repository. It holds per-environment StatsD and span switches, a 60-line apply script, schema validation for the switch file, functional tests, workflows for pull requests and for apply, and branch protection on the main branch. A change to what an environment emits is a reviewed pull request, and the apply step is the only thing that touches the clusters.

Two controls keep the apply identity narrow. Its CI role is assumed through OIDC with trust scoped to the environment, so the dev apply job cannot assume the production role. On GitHub Actions, for example, the subject claim "includes the environment name when the job references an environment", in the form repo:ORG-NAME/REPO-NAME:environment:ENVIRONMENT-NAME, which a role trust policy can match. Repositories on immutable subject claims carry the owner and repository IDs in that string too, so read the claim from a real token before you write the condition. Inside the cluster, ValidatingAdmissionPolicies let that identity stamp workloads with the switch setting but not scale them. RBAC alone cannot draw that line, because patch on a Deployment covers spec.replicas too.

# Illustrative: acme-telemetry-switch is a placeholder for the switch's CI user
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: telemetry-switch-no-scale
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
      - apiGroups: ["apps"]
        apiVersions: ["v1"]
        operations: ["UPDATE"]
        resources: ["deployments", "deployments/scale"]
  matchConditions:
    - name: switch-identity-only
      expression: "request.userInfo.username == 'acme-telemetry-switch'"
  validations:
    - expression: "object.spec.replicas == oldObject.spec.replicas"
      message: "the telemetry switch may change telemetry settings, not replica counts"
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
  name: telemetry-switch-no-scale
spec:
  policyName: telemetry-switch-no-scale
  validationActions: ["Deny"]

Both a Deployment and its scale subresource carry spec.replicas, so the one expression covers kubectl scale as well as a patch. Our admission policies playbook covers testing a policy in Audit mode before you bind it with Deny.

The traces half of the switch has one exception built in: with spans switched off, ERROR spans still go through. Turning tracing down in a noisy environment should not hide the failures you would open a trace to look at.

What the upgrade renamed, and the alerts that went quiet

After the Collector upgrade we checked every environment. Some metrics had been renamed, and the dashboards that used them were fixed, with a backup of each taken first. Two alert changes and a cleanup came out of the same pass.

We re-pointed the export-failure alert to the new log phrase "Dropping data", which the current exporter helper writes on a failed export ("Exporting failed. Dropping data.", in queue_sender.go). An alert keyed to log text needs a check after every Collector upgrade, because nothing fails when it stops matching.

Ingress latency alerts moved to the request-duration histogram, gated on at least 20 requests in the window. Without the gate, a quiet environment at night fires on two slow requests.

Unused metrics were blocked one at a time, each after checking that no alert or dashboard read it. That is slower than a bulk rule, and it is the only way to be sure a block does not silence an alert.

Merged with the switch off

The switch was confirmed end to end, and the ERROR-spans change ran on production. The change that points StatsD at the node-local Collector merged with the switch OFF in every cluster, so the code path is live and the metrics flow only where someone turns them on through a reviewed pull request.

We would order it the same way next time. Shipping the code with the data turned off means each environment can be switched on separately and its series count read before the next.

If you are moving StatsD into the OpenTelemetry Collector and the counters look flat or the series count is climbing, tell us what you are running. We would start with the receiver block and a week of series counts from one environment, before anything reaches production.

Tags: statsd counters as gauges, opentelemetry collector statsd receiver, is_monotonic_counter, kubernetes observability, metrics cardinality, kubernetes automation