See the comment added for this issue in ElementCountFnDataReceiver.java
The method used to create these metrics relies on the currently in scope metrics container, though we should use the same metrics container every time this code is invoked instead. There is no need to use the current scoped metric container, which only offers the main benefit to user counters, by attaching the PTransform name to the metrics. In this case the metric does not need the currently scoped PTransform name, since the code is labelling the metrics with the pcollection, and similar cases can manually attach the ptransform name (i.e. for execution time metrics).
We can make the static method LabelledMetrics.counter(metricName) obtain a consistent metric container instead of looking for the currently scoped metric container.