2 Replies Latest reply on May 27, 2019 4:23 AM by rsoika

    Wildfly 16 Microprofile Metrics - can not create Tags at runtime

    rsoika

      I am trying out the Microprofile Metrics API in Wildfly 16.0.0. But I run into problem with a simple counter metric. The following code fails:

       

      ....
          @Inject
          @RegistryType(type=MetricRegistry.Type.APPLICATION)
          MetricRegistry metricRegistry;
        
      ....
      
      Tag myTag=new Tag("type","abc");  // throws Exception ...!!
      Counter myCoutner = metricRegistry.counter("my_coutner", myTag);
      ....

       

      The problem is the line:

       

      org.eclipse.microprofile.metrics.Tag myTag=new Tag("type","abc");

       

      This line causes the following exception:

       

      Caused by: java.lang.NoClassDefFoundError: org/eclipse/microprofile/metrics/Tag
      imixssample-app_1  |     at deployment.imixs-jsf-example-4.2.2.war//org.imixs.workflow.engine.MetricService.buildWorkitemMetric(MetricService.java:225)
      imixssample-app_1  |     at deployment.imixs-jsf-example-4.2.2.war//org.imixs.workflow.engine.MetricService.onProcessingEvent(MetricService.java:136)
      imixssample-app_1  |     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      imixssample-app_1  |     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      imixssample-app_1  |     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      imixssample-app_1  |     at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      imixssample-app_1  |     at org.jboss.weld.core@3.1.0.Final//org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:95)
      imixssample-app_1  |     ... 149 more
      imixssample-app_1  | Caused by: java.lang.ClassNotFoundException: org.eclipse.microprofile.metrics.Tag from [Module "deployment.imixs-jsf-example-4.2.2.war" from Service Module Loader]
      imixssample-app_1  |     at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:255)
      imixssample-app_1  |     at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
      imixssample-app_1  |     at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
      imixssample-app_1  |     at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
      imixssample-app_1  |     ... 156 more

       

       

      When I create the counter without Tags than the metric works fine.

      The method itself is called within an CDI Event - can this be the problem?

       

      Thanks for any help

       

      ===
      Ralph

        • 1. Re: Wildfly 16 Microprofile Metrics - can not create Tags at runtime
          rsoika

          It looks that I have mixed up different versions by using microprofile-metrics-api Version 2.0.0. But this api is different to the org.eclipse.microprofile version 2.2. And so the "Tag" class is not defined which explains the runtime exception.

           

          But: can anybody give me an example how to create a Metadata Object with Tags by Code which I can use to register a reuseable Counter object?

          • 2. Re: Wildfly 16 Microprofile Metrics - can not create Tags at runtime
            rsoika

            I figured out how to create a metric without annotations:

             

            Map<string,string> metaDataMap=new HashMap<string, string="">();
            
            metaDataMap.put("name", "my_metric");
            metaDataMap.put("type", MetricType.COUNTER.toString());
            metaDataMap.put("reusable", "true");
            metaDataMap.put("displayName", "");
            metaDataMap.put("description", "");
            metaDataMap.put("unit", MetricUnits.NONE.toString());
            // create metric 1 with a custom tag value
            Metadata metric_1=new Metadata(metaDataMap);
            metric_1.addTag("type=ABC");
            metricRegistry.counter(metric_1);

             

            So this works fine now for me.