Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalAccessError when using OpenTelemetry extension with custom Resource #22815

Closed
juliuskrah opened this issue Jan 11, 2022 · 10 comments · Fixed by #22828 or #23792
Closed

IllegalAccessError when using OpenTelemetry extension with custom Resource #22815

juliuskrah opened this issue Jan 11, 2022 · 10 comments · Fixed by #22828 or #23792
Assignees
Labels
area/arc Issue related to ARC (dependency injection) area/tracing kind/bug Something isn't working
Milestone

Comments

@juliuskrah
Copy link

Describe the bug

I created a quarkus project with the OpenTelemetry extension and added a custom Resource CDI Producer.

import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_INSTANCE_ID;

import java.util.UUID;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.resources.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@ApplicationScoped
public class ResourceConfiguration {
    private static final Logger log = LoggerFactory.getLogger(ResourceConfiguration.class);
    
    @Produces
    @ApplicationScoped
    public Resource newRelicResource() {
        log.info("Adding custom resources {}", ResourceConfiguration.class.getName());
        return Resource.create(
            Attributes.builder().put(SERVICE_INSTANCE_ID, UUID.randomUUID().toString()).build());
    }
}

Expected behavior

The application should startup when ./mvnw clean quarkus:dev

Actual behavior

An exception is thrown

2022-01-11 16:39:21,512 DEBUG [org.hib.val.int.uti.Version] (Quarkus Main Thread) HV000001: Hibernate Validator 6.2.1.Final
2022-01-11 16:39:22,852 ERROR [io.qua.run.Application] (Quarkus Main Thread) Failed to start application (with profile dev): java.lang.IllegalAccessError: class org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_ClientProxy tried to access method 'void io.opentelemetry.sdk.resources.Resource.<init>()' (org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_ClientProxy is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @cd7f1ae; io.opentelemetry.sdk.resources.Resource is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @76b10754)
        at org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_ClientProxy.<init>(Unknown Source)
        at org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_Bean.proxy(Unknown Source)
        at org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_Bean.get(Unknown Source)
        at org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_Bean.get(Unknown Source)
        at io.quarkus.arc.impl.InstanceImpl.getBeanInstance(InstanceImpl.java:223)
        at io.quarkus.arc.impl.InstanceImpl$InstanceIterator.next(InstanceImpl.java:259)
        at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
        at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.reduce(ReferencePipeline.java:657)
        at io.quarkus.opentelemetry.runtime.tracing.TracerRecorder.setupResources(TracerRecorder.java:117)
        at io.quarkus.deployment.steps.TracerProcessor$setupTracer558615094.deploy_0(Unknown Source)
        at io.quarkus.deployment.steps.TracerProcessor$setupTracer558615094.deploy(Unknown Source)
        at io.quarkus.runner.ApplicationImpl.doStart(Unknown Source)
        at io.quarkus.runtime.Application.start(Application.java:101)
        at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:104)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:67)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:41)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:120)
        at io.quarkus.runner.GeneratedMain.main(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.runner.bootstrap.StartupActionImpl$1.run(StartupActionImpl.java:103)
        at java.base/java.lang.Thread.run(Thread.java:833)


2022-01-11 16:39:22,852 ERROR [io.qua.run.Application] (Quarkus Main Thread) Failed to start application (with profile dev): java.lang.IllegalAccessError: class org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_ClientProxy tried to access method 'void io.opentelemetry.sdk.resources.Resource.<init>()' (org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_ClientProxy is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @cd7f1ae; io.opentelemetry.sdk.resources.Resource is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @76b10754)
        at org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_ClientProxy.<init>(Unknown Source)
        at org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_Bean.proxy(Unknown Source)
        at org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_Bean.get(Unknown Source)
        at org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_Bean.get(Unknown Source)
        at io.quarkus.arc.impl.InstanceImpl.getBeanInstance(InstanceImpl.java:223)
        at io.quarkus.arc.impl.InstanceImpl$InstanceIterator.next(InstanceImpl.java:259)
        at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
        at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.reduce(ReferencePipeline.java:657)
        at io.quarkus.opentelemetry.runtime.tracing.TracerRecorder.setupResources(TracerRecorder.java:117)
        at io.quarkus.deployment.steps.TracerProcessor$setupTracer558615094.deploy_0(Unknown Source)
        at io.quarkus.deployment.steps.TracerProcessor$setupTracer558615094.deploy(Unknown Source)
        at io.quarkus.runner.ApplicationImpl.doStart(Unknown Source)
        at io.quarkus.runtime.Application.start(Application.java:101)
        at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:104)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:67)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:41)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:120)
        at io.quarkus.runner.GeneratedMain.main(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.runner.bootstrap.StartupActionImpl$1.run(StartupActionImpl.java:103)
        at java.base/java.lang.Thread.run(Thread.java:833)


2022-01-11 16:39:22,853 INFO  [io.qua.dep.dev.IsolatedDevModeMain] (main) Attempting to start live reload endpoint to recover from previous Quarkus startup failure
2022-01-11 16:39:22,853 INFO  [io.qua.dep.dev.IsolatedDevModeMain] (main) Attempting to start live reload endpoint to recover from previous Quarkus startup failure
2022-01-11 16:39:22,913 INFO  [org.jbo.threads] (main) JBoss Threads version 3.4.2.Final
2022-01-11 16:39:23,002 ERROR [io.qua.dep.dev.IsolatedDevModeMain] (main) Failed to start quarkus: java.lang.RuntimeException: java.lang.RuntimeException: Failed to start quarkus
        at io.quarkus.dev.appstate.ApplicationStateNotification.waitForApplicationStart(ApplicationStateNotification.java:51)
        at io.quarkus.runner.bootstrap.StartupActionImpl.runMainClass(StartupActionImpl.java:122)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:145)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:456)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:67)
        at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:149)
        at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:105)
        at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:145)
        at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:63)
Caused by: java.lang.RuntimeException: Failed to start quarkus
        at io.quarkus.runner.ApplicationImpl.doStart(Unknown Source)
        at io.quarkus.runtime.Application.start(Application.java:101)
        at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:104)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:67)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:41)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:120)
        at io.quarkus.runner.GeneratedMain.main(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.runner.bootstrap.StartupActionImpl$1.run(StartupActionImpl.java:103)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalAccessError: class org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_ClientProxy tried to access method 'void io.opentelemetry.sdk.resources.Resource.<init>()' (org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_ClientProxy is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @cd7f1ae; io.opentelemetry.sdk.resources.Resource is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @76b10754)
        at org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_ClientProxy.<init>(Unknown Source)
        at org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_Bean.proxy(Unknown Source)
        at org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_Bean.get(Unknown Source)
        at org.acme.otel.ResourceConfiguration_ProducerMethod_newRelicResource_625b8ffec6a326c4440bff06cc0a52e42734afec_Bean.get(Unknown Source)
        at io.quarkus.arc.impl.InstanceImpl.getBeanInstance(InstanceImpl.java:223)
        at io.quarkus.arc.impl.InstanceImpl$InstanceIterator.next(InstanceImpl.java:259)
        at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
        at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.reduce(ReferencePipeline.java:657)
        at io.quarkus.opentelemetry.runtime.tracing.TracerRecorder.setupResources(TracerRecorder.java:117)
        at io.quarkus.deployment.steps.TracerProcessor$setupTracer558615094.deploy_0(Unknown Source)
        at io.quarkus.deployment.steps.TracerProcessor$setupTracer558615094.deploy(Unknown Source)
        ... 13 more

How to Reproduce?

reproducer.zip

Output of uname -a or ver

Linux usename 5.10.60.1-microsoft-standard-WSL2

Output of java -version

openjdk version "17.0.1" 2021-10-19 OpenJDK Runtime Environment (build 17.0.1+12-Ubuntu-120.04) OpenJDK 64-Bit Server VM (build 17.0.1+12-Ubuntu-120.04, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.6.1.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d) Maven home: Java version: 17.0.1, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64 Default locale: en, platform encoding: UTF-8 OS name: "linux", version: "5.10.60.1-microsoft-standard-wsl2", arch: "amd64", family: "unix"

Additional information

No response

@juliuskrah juliuskrah added the kind/bug Something isn't working label Jan 11, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Jan 11, 2022

/cc @radcortez

@geoand
Copy link
Contributor

geoand commented Jan 12, 2022

Interesting case...

This happens because the constructor of io.opentelemetry.sdk.resources.Resource is package private which is problematic for the generated proxy. @mkouba shouldn't this be a build time error?

A workaround is to change @ApplicationScoped to @Singleton on the newRelicResource method.

@geoand geoand added the area/arc Issue related to ARC (dependency injection) label Jan 12, 2022
@juliuskrah
Copy link
Author

juliuskrah commented Jan 12, 2022

@geoand the workaround works. The exception is no longer thrown

@mkouba
Copy link
Contributor

mkouba commented Jan 12, 2022

This happens because the constructor of io.opentelemetry.sdk.resources.Resource is package private which is problematic for the generated proxy. @mkouba shouldn't this be a build time error?

Yes, it's problematic because the io.opentelemetry.sdk.resources.Resource obviously comes from a different package than the ResourceConfiguration producer. I think that we should try to make the constructor protected (if quarkus.arc.transform-unproxyable-classes=true). Let me try to prepare a PR.

@juliuskrah
Copy link
Author

@geoand can the custom resource be replaced with

quarkus.opentelemetry.tracer.resource-attributes=service.instance.id=${quarkus.uuid}

I don't see the traces on new relic because the service.instance.id is still not being sent in the request

@geoand
Copy link
Contributor

geoand commented Jan 12, 2022

That's a question for @radcortez

mkouba added a commit to mkouba/quarkus that referenced this issue Jan 12, 2022
- use the package of the return type/field type
- previously, the package of the declaring class was used
- resolves quarkusio#22815
mkouba added a commit to mkouba/quarkus that referenced this issue Jan 12, 2022
- use the package of the return type/field type
- previously, the package of the declaring class was used
- resolves quarkusio#22815
@radcortez
Copy link
Member

Let me check

mkouba added a commit to mkouba/quarkus that referenced this issue Jan 12, 2022
- use the package of the return type/field type
- previously, the package of the declaring class was used
- resolves quarkusio#22815
@quarkus-bot quarkus-bot bot added this to the 2.7 - main milestone Jan 13, 2022
@gsmet gsmet removed this from the 2.7.0.CR1 milestone Jan 25, 2022
@gsmet gsmet reopened this Jan 25, 2022
@gsmet
Copy link
Member

gsmet commented Jan 25, 2022

The fix needs more work. It won't be included in 2.7.0.Final.

@radcortez radcortez self-assigned this Jan 28, 2022
@radcortez
Copy link
Member

I don't see the traces on new relic because the service.instance.id is still not being sent in the request

Everything looks ok to me. Are you able to check if the OTel data is correct using Jaeger for instance?

@radcortez
Copy link
Member

The fix needs more work. It won't be included in 2.7.0.Final.

What is missing?

aloubyansky pushed a commit to aloubyansky/quarkus that referenced this issue Feb 9, 2022
- use the package of the return type/field type
- previously, the package of the declaring class was used
- resolves quarkusio#22815
aloubyansky pushed a commit to aloubyansky/quarkus that referenced this issue Feb 10, 2022
- use the package of the return type/field type
- previously, the package of the declaring class was used
- resolves quarkusio#22815
mkouba added a commit to mkouba/quarkus that referenced this issue Feb 11, 2022
- use the package of the return type/field type
- previously, the package of the declaring class was used
- resolves quarkusio#22815
aloubyansky pushed a commit to aloubyansky/quarkus that referenced this issue Feb 13, 2022
- use the package of the return type/field type
- previously, the package of the declaring class was used
- resolves quarkusio#22815
aloubyansky pushed a commit to aloubyansky/quarkus that referenced this issue Feb 13, 2022
- use the package of the return type/field type
- previously, the package of the declaring class was used
- resolves quarkusio#22815
aloubyansky pushed a commit to aloubyansky/quarkus that referenced this issue Feb 15, 2022
- use the package of the return type/field type
- previously, the package of the declaring class was used
- resolves quarkusio#22815
aloubyansky pushed a commit to aloubyansky/quarkus that referenced this issue Feb 16, 2022
- use the package of the return type/field type
- previously, the package of the declaring class was used
- resolves quarkusio#22815
mkouba added a commit to mkouba/quarkus that referenced this issue Feb 17, 2022
- use the package of the return type/field type
- and use the produced type to test the app class
- previously, the package of the declaring class was used
- also a proxy class does not reference the bean class directly but performs a
lookup via the bean identifier when instantiated
- resolves quarkusio#22815
mkouba added a commit to mkouba/quarkus that referenced this issue Feb 18, 2022
- use the package of the return type/field type
- and use the produced type to test the app class
- previously, the package of the declaring class was used
- also a proxy class does not reference the bean class directly but performs a
lookup via the bean identifier when instantiated
- resolves quarkusio#22815
mkouba added a commit to mkouba/quarkus that referenced this issue Feb 21, 2022
- use the package of the return type/field type
- and use the produced type to test the app class
- previously, the package of the declaring class was used
- also a proxy class does not reference the bean class directly but performs a
lookup via the bean identifier when instantiated
- resolves quarkusio#22815
@quarkus-bot quarkus-bot bot added this to the 2.8 - main milestone Feb 21, 2022
@gsmet gsmet modified the milestones: 2.8 - main, 2.7.2.Final Feb 21, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Feb 21, 2022
- use the package of the return type/field type
- and use the produced type to test the app class
- previously, the package of the declaring class was used
- also a proxy class does not reference the bean class directly but performs a
lookup via the bean identifier when instantiated
- resolves quarkusio#22815

(cherry picked from commit c0f70cf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) area/tracing kind/bug Something isn't working
Projects
None yet
5 participants