smallrye / smallrye-metrics

Apache License 2.0
41 stars 36 forks source link

Ambiguous dependencies error when using injection and producers in the same app #107

Open jmartisk opened 5 years ago

jmartisk commented 5 years ago

When an application contains metric injection as well as metric producers, it will encounter an ambiguous dependencies error.

Example:

    @Inject
    @Metric(name = "injected-counter", absolute = true)
    private Counter counter;

... and in a different class:

    @Produces
    @Metric(name = "producerfield-counter", absolute = true, description = "Counter from producer field.")
    Counter counter = new CounterImpl();

(The injection point and the producer field have to be for the same metric type, in this case it is counter) If the application contains just one of these two things, it will work fine.

the error looks like this (this is from Thorntail):

019-04-24 12:53:21,376 ERROR [stderr] (main)     Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type Counter with qualifiers @Default
2019-04-24 12:53:21,376 ERROR [stderr] (main)   at injection point [BackedAnnotatedField] @Inject @Metric private com.example.metrics.InjectResource.counter
2019-04-24 12:53:21,377 ERROR [stderr] (main)   at com.example.metrics.InjectResource.counter(InjectResource.java:0)
2019-04-24 12:53:21,377 ERROR [stderr] (main)   Possible dependencies: 
2019-04-24 12:53:21,377 ERROR [stderr] (main)   - Producer Method [Counter] with qualifiers [@Any @Default] declared as [[UnbackedAnnotatedMethod] @Produces io.smallrye.metrics.MetricProducer.getCounter(InjectionPoint)],
2019-04-24 12:53:21,377 ERROR [stderr] (main)   - Producer Method [Counter] with qualifiers [@Any @Default] declared as [[BackedAnnotatedMethod] @Produces @Metric com.example.metrics.ProducersMethodsResource.counter()],
2019-04-24 12:53:21,377 ERROR [stderr] (main)   - Producer Field [Counter] with qualifiers [@Any @Default] declared as [[BackedAnnotatedField] @Produces @Metric com.example.metrics.ProducersFieldsResource.counter]
2019-04-24 12:53:21,377 ERROR [stderr] (main) "}}
2019-04-24 12:53:21,377 ERROR [stderr] (main)   at org.wildfly.swarm.container.runtime.RuntimeDeployer.deploy(RuntimeDeployer.java:296)
eldarj commented 2 years ago

Any updates on this issue? I'm encountering the same problem