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

Library instrumentation should read its version from a file #5692

Merged

Conversation

mateuszrzeszutek
Copy link
Member

@mateuszrzeszutek mateuszrzeszutek commented Mar 25, 2022

Resolves #2761. As discussed on the last SIG meeting, each instrumentation gets its separate version file.

try {
List<URL> urls =
list(
new ResourceLoaderProxy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand correctly that for library instrumentation this class needs to be in the same class loader as the library instrumentation so that it can find the versions file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - which I think should normally happen: library instrumentation triggers Instrumenter load, Instrumenter triggers this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you are using a library instrumentation along with the agent. Then this class will be in boot loader and won't find the library versions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shaded version of this class (provided by the agent) will be in the bootloader; the unshaded version (provided by the application itself) should still see its own versions file (+ all other versions files, since they get resource-injected into all classloaders).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely forgot that this would also get shaded. I still think it is possible to break it by placing instrumentation-api in parent class loader and library instrumentation in child class loader.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that scenario would break this mechanism. I wonder how common it is though, you'd have to deliberately separate the instrumentation-api from the instrumentation.

@anuraaga
Copy link
Contributor

anuraaga commented Mar 28, 2022

Since we expect either bundled javaagent or use of the BOM for aligned versions, can we just have one version instead of per-instrumentation? Can just be tied straight into instrumentation-api.

I guess we want to separate though since it is precisely finding out about such a versionoing issue that we want the files present though.

In general, any approach that involves a single file can cause issues with fat jars, so we would want a unique filename per artifact (basically putting name into the file path instead of in the file contents). Service loader doesn't quite solve the issue with fat jars but is still better supported than arbitrary files so it could be an alternative if needing to stick with a single file path.

@mateuszrzeszutek mateuszrzeszutek force-pushed the instrumentation-versions branch from a401183 to f9045d1 Compare March 30, 2022 11:08
@mateuszrzeszutek mateuszrzeszutek marked this pull request as ready for review March 30, 2022 11:11
@mateuszrzeszutek mateuszrzeszutek requested a review from a team March 30, 2022 11:11
@mateuszrzeszutek mateuszrzeszutek changed the title [idea] Library instrumentation should read its version from a file Library instrumentation should read its version from a file Mar 30, 2022
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jedis-3.0";
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jedis-4.0";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

private static final String INSTRUMENTATION_NAME = "io.opentelemetry.ratpack-1.4";
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.ratpack-1.7";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test now that fails when these are wrong?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there isn't, unfortunately -- I went over all usages of Instrumenter#builder() and fixed them all manually. Currently I don't have any good idea about how to verify this in a smart way that does not require adding assertions to every test.

@@ -80,6 +83,7 @@
* different library versions it's easy to find out which instrumentations produced the telemetry
* data.
*/
// TODO: add a setInstrumentationVersion method to the builder instead
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mateuszrzeszutek mateuszrzeszutek force-pushed the instrumentation-versions branch from 1306341 to ba65f6a Compare April 4, 2022 11:41
@trask trask merged commit 8e722cc into open-telemetry:main Apr 4, 2022
@trask
Copy link
Member

trask commented Apr 4, 2022

❤️

@mateuszrzeszutek mateuszrzeszutek deleted the instrumentation-versions branch April 5, 2022 05:44
RashmiRam pushed a commit to RashmiRam/opentelemetry-auto-instr-java that referenced this pull request May 23, 2022
…emetry#5692)

* Library instrumentation should read its version from a file

* errorprone

* animalsniffer

* code review comments

* add name as task input too

* code review comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Library instrumentation should read its version from a file, not from the jar manifest
4 participants