javaopen-telemetryjavaagentsdistributed-tracingopen-telemetry-java

OpenTelemetry Java Agent extension not loaded


I have created a simple, dummy OpenTelemetry Java Agent extension. It contains only one class and it looks like this:

import com.google.auto.service.AutoService;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;

@AutoService(AutoConfigurationCustomizerProvider.class)
public class DummyAutoConfigurationCustomizerProvider implements AutoConfigurationCustomizerProvider {

    static {
        System.out.println("initialized DummyAutoConfigurationCustomizerProvider");
    }

    @Override
    public void customize(AutoConfigurationCustomizer autoConfigurationCustomizer) {
        System.out.println("customizing DummyAutoConfigurationCustomizerProvider");
    }
}

I have created a shaded JAR of this extension.

I have then run my application with the following Java options:

-javaagent:/opentelemetry-javaagent.jar -Dotel.javaagent.extensions=/lib-all.jar

However, I don't see any sign that my extension is loaded. The only log statement I get is this:

[otel.javaagent 2024-07-30 16:04:35:751 +0200] [main] INFO io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent - version: 2.5.0

What am I missing? Why is my OpenTelemetry Java Agent not loaded?


Solution

  • The @com.google.auto.service.AutoService annotation requires an annotation processor.

    I have removed the @com.google.auto.service.AutoService annotation.

    Then I created the file META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider containing the content following content:

    DummyAutoConfigurationCustomizerProvider
    

    Now it works.