Spring Micrometer custom common tags not displaying after meterRegistry access from applicationContext

Viewed 208

In my Spring boot Application I am using micrometer where I am trying to add custom common tags as below -

@Configuration
public class MeterConfig {

  private static final String SERVICE_NAME = "serviceName";

  @Bean
  public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
      String hostname = "";
      try {
          hostname = InetAddress.getLocalHost().getHostName().toString();
      } catch (UnknownHostException e) {
          hostname = "unknown";
      }
      List<Tag> tags = new LinkedList<>();
      tags.add(Tag.of("host", hostname));
      tags.add(Tag.of("service", SERVICE_NAME));

      return registry -> registry.config().commonTags(tags);
  }
}

I am accessing MeterRegistry through applicationContext because the class in which I am using Counter is not in spring context so I can not use Autowired annotation there -

ApplicationContext context = AppContext.getInstance().getContext();
MeterRegistry meterRegistry = context.getBean(MeterRegistry.class);

and after that using meterRegistry in Counter, but I cannot see custom common tags in influxdb. Am I missing anything here.

0 Answers
Related