OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.15k stars 590 forks source link

Using Open Telemetry in a user extension results in WELD-001408: Unsatisfied dependencies for type Tracer #28566

Closed JDUNNIN closed 1 week ago

JDUNNIN commented 4 months ago

Describe the bug
Raising this as a bug - but equally could be a configuration problem on my part.

I've been following this guide on Enable distributed tracing with MicroProfile Telemetry, specifically the Manual Instrumentation to attempt to add an OTEL span to my user feature. The user feature is added to Liberty as part of a product extension.

Following the guide I added to one of the classes included in our user feature the recommended code (snippet below). This class already has some injection in use today

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;

@RequestScoped
public class MyInjectionClass {

    // Existing injection that is working
    @Inject
    MyOtherInjection myOtherInjection;
    @Inject
    AnotherInjection anotherInjection;

    // New injection causing FFDC
    @Inject
    private Tracer tracer;

....

    public void myMethod() {

       // Attempt to use OTEL classes
       Span newSpan = tracer.spanBuilder("TestSpan").startSpan();
       try (Scope s = newSpan.makeCurrent()) {
             // do something
        } finally {
            newSpan.end();
        }
    }
}

Within a manifest feature file that our user extension includes I added the dependency on:

Subsystem-Content: io.openliberty.mpTelemetry-1.1; type="osgi.subsystem.feature"

Upon starting the server I get this exception:

[5/28/24, 10:41:39:030 UTC] 00000030 com.ibm.ws.logging.internal.impl.IncidentImpl                I FFDC1015I: An FFDC Incident has been created: "org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type Tracer with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject private com.example.MyInjectionClass.tracer
  at com.example.MyInjectionClass.tracer(MyInjectionClass.java:0)
 com.ibm.ws.container.service.state.internal.ApplicationStateManager 56" at ffdc_24.05.28_10.41.38.1.log

The features enabled are:

CWWKF0012I: The server installed the following features: [appSecurity-2.0, audit-1.0, beanValidation-2.0, cdi-2.0, distributedMap-1.0, el-3.0, jaxb-2.2, jaxrs-2.1, jaxrsClient-2.1, jca-1.7, jndi-1.0, json-1.0, jsonb-1.0, jsonp-1.1, jsp-2.3, jwt-1.0, monitor-1.0, mpConfig-2.0, mpHealth-3.1, mpMetrics-3.0, mpOpenAPI-2.0, mpTelemetry-1.1, servlet-4.0, ssl-1.0, transportSecurity-1.0, myproductext:myuserfeature-3.0].

The scenario in which the class above is used would be client calls a JAX-RS API, this API has an @Inject for RequestScoped class MyInjectionClass above and it calls the myMethod() on it, then JAX-RS responds.

Steps to Reproduce

  1. Create a user extension with an RequestScoped class.
  2. Add OTEL @Tracer injection as above and try to use it
  3. Start the server and see FFDC on start up (prior to API invoke)

Expected behavior
Injection of Tracer class without error.

Diagnostic information:

Additional context
Add any other context about the problem here.

JDUNNIN commented 4 months ago

messages.log Attached messages.log but I think all the key info is above. I've redacted and anonymised a lot of this.

I work for IBM and am happy to have a call to discuss this and available via Slack too.

benjamin-confino commented 4 months ago

This issue will be solved under https://github.ibm.com/websphere/WS-CD-Open/issues/32050

benjamin-confino commented 2 months ago

Just noting that this issue led to #28891 being opened

benjamin-confino commented 1 week ago

Code for this issue has been merged (currently betaguarded, see https://github.com/OpenLiberty/open-liberty/issues/28891)