Browse Source

Add debug logger when registering a metric (#103458)

This commit adds a log message at debug level when a metric is registered. This allows to start elasticsearch with a level changed for the apm package and get a list of metric names.
It should be useful when trying to came up with a new meteric name the command to run
./gradlew run -Dtests.es.logger.org.elasticsearch.telemetry.apm=debug
Przemyslaw Gomulka 1 year ago
parent
commit
52c2011e84

+ 7 - 0
modules/apm/NAMING.md

@@ -64,3 +64,10 @@ Attribute names should follow the same rules. In particular, these rules apply t
 * pluralization (when an attribute represents a measurement)
 
 For **pluralization**, when an attribute represents an entity, the attribute name should be singular (e.g.` es.security.realm_type`, not` es.security.realms_type` or `es.security.realm_types`), unless it represents a collection (e.g.` es.rest.request_headers`)
+
+
+### List of previously registered metric names
+You can inspect all previously registered metrics names with
+`./gradlew run -Dtests.es.logger.org.elasticsearch.telemetry.apm=debug`
+This should help you find out the already registered group that your meteric
+might fit

+ 4 - 0
modules/apm/src/main/java/org/elasticsearch/telemetry/apm/APMMeterRegistry.java

@@ -10,6 +10,8 @@ package org.elasticsearch.telemetry.apm;
 
 import io.opentelemetry.api.metrics.Meter;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
 import org.elasticsearch.common.util.concurrent.ReleasableLock;
 import org.elasticsearch.telemetry.apm.internal.metrics.DoubleAsyncCounterAdapter;
@@ -47,6 +49,7 @@ import java.util.function.Supplier;
  * {@link #setProvider(Meter)} is used to change the provider for all existing meterRegistrar.
  */
 public class APMMeterRegistry implements MeterRegistry {
+    private static final Logger logger = LogManager.getLogger(APMMeterRegistry.class);
     private final Registrar<DoubleCounterAdapter> doubleCounters = new Registrar<>();
     private final Registrar<DoubleAsyncCounterAdapter> doubleAsynchronousCounters = new Registrar<>();
     private final Registrar<DoubleUpDownCounterAdapter> doubleUpDownCounters = new Registrar<>();
@@ -207,6 +210,7 @@ public class APMMeterRegistry implements MeterRegistry {
 
     private <T extends AbstractInstrument<?>> T register(Registrar<T> registrar, T adapter) {
         assert registrars.contains(registrar) : "usage of unknown registrar";
+        logger.debug("Registering an instrument with name: " + adapter.getName());
         return registrar.register(adapter);
     }