Open rvesse opened 9 months ago
hi @rvesse! is this feature what you're looking for? https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/runtime-attach
hi @rvesse! is this feature what you're looking for? https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/runtime-attach
No, I don't think that solves the problem for Uber JARs anyway, I get a slightly different error condition but my application still crashes:
[otel.javaagent 2023-10-17 15:34:29:703 +0100] [Attach Listener] INFO io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent - version: 0.20.1-SNAPSHOT ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Personally I really don't want to put the agent into an uber JAR because that's not how agents are supposed to be used. But I'd ideally like some documentation saying Don't do that because X
(or equivalent) in your official documentation so I point to that to justify why we aren't doing that.
No, I don't think that solves the problem for Uber JARs anyway
can you describe a bit more why not? runtime attach module should allows you to embed the agent in an uber jar (e.g. spring boot)
You probably get the UnsupportedOperationException
because you didn't add Can-Retransform-Classes: true
manifest attribute, you should also add Can-Redefine-Classes: true
. Packaging the agent into an uberjar like that will take some effort to make it work, I think it would be easier to get it running by packaging the agent as a jar file into your uberjar. In the Launcher-Agent-Class
unpack that jar and use an URLClassLoader
and a bit of reflection to call premain
in OpenTelemetryAgent
. I haven't tried it myself so can't say for sure whether this is all that is needed. If you want to package the agent into the uberjar then you have to be aware that in https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/60b65488cbad7d3c620e74c7a83fa044e77f310f/javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/OpenTelemetryAgent.java#L96 the agent adds the jar it is loaded from to boot class path, this may break your application.
To summarise:
manifest.mf
attributes are set) but likely a very bad idea per @laurit's comment as your entire application ends up on the bootstrap classpath which can lead to all sorts of subtle and interesting class loading problemsNote that I'm quite happy for you guys to close this as Won't Fix or your equivalent.
My main goal in filing this issue was to have some more easily discoverable discussion of this topic to help future engineers who get asked to try and do this and start Googling and don't waste too much time.
@trask we are trying to use the agent with quarkus Uber jar and we end up getting the same exception as stated by @rvesse. Is this the limitation of otel agent with uber jars?
hi @alagusundarams! if Runtime Attach isn't working for you, can you open an issue in https://github.com/open-telemetry/opentelemetry-java-contrib?
Describe the bug
In a similar vein to #8227 I've been experimenting with whether you can package the Otel Agent JAR into an uber JAR and have that work. I'm pretty sure the answer is no this won't work, so it would be nice if this were explicitly stated that this isn't supported somewhere in the documentation
Firstly if you're attempting to package into an uber jar you need to set both the
Premain-Class
andLauncher-Agent-Class
attributes inmanifest.mf
. It'sLauncher-Agent-Class
that actually starts the agent in an uber JAR deployment BUT if you don't havePremain-Class
as well OTel baulks with the following error:Clearly implying that the authors didn't expect this to be supported anyway.
If you do specify the
Premain-Class
attribute to force your way past this error you'll get the following error on startup:Which likely is the same underlying bug raphw/byte-buddy/issues/374 mentioned in the comments thread on #8227
Steps to reproduce
Generate an über JAR with the OTel Java Agent using the toolchain of your choice, e.g. Maven Shade plugin:
Expected behavior
N/A, seems this isn't intended to work/can't work so documentation merely needs to be clearer around this
Actual behavior
Errors thrown as shown earlier in description
Javaagent or library instrumentation version
1.24.0
Environment
JDK: Temurin 17 and OpenJDK 17 OS: Mac OX X Ventura, Linux (5.15.40-linuxkit)
Additional context
No response