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

Add SPI to configure additional bootstrap package prefixes #1380

Merged
merged 3 commits into from
Oct 16, 2020

Conversation

pavolloffay
Copy link
Member

This feature is useful when a large set of custom instrumentations is
using common classes from a custom package.

cc) @trask

Signed-off-by: Pavol Loffay p.loffay@gmail.com

* The instrumentation does not have access to the installer, therefore this utility class is used
* to share package prefixes.
*/
public class BootstrapPackagePrefixesHolder {
Copy link
Member Author

Choose a reason for hiding this comment

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

I could get around without introducing this class. In the AgentInstaller I have set the package prefixes to the config (in the static block) and then used the config in the classloader instrumentation. We could also remove the SPI so vendors would set the packages in the config - I don't like this since it easily opens the config to the consumers.

Copy link
Member

Choose a reason for hiding this comment

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

can this go in javaagent-bootstrap near HelperResources which serves somewhat similar purpose?

Copy link
Member Author

Choose a reason for hiding this comment

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

When the class is in javaagent-bootstrap (and added to helper class names in the classloader instrumentation) the set prefixes set by the AgentInstaller are always null - the agent installer has a different instance as the instrumentation.

Loading the providers from the instrumentation fails at build time on the muzzle size limit.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have moved it to internal package in the same module.

* The instrumentation does not have access to the installer, therefore this utility class is used
* to share package prefixes.
*/
public class BootstrapPackagePrefixesHolder {
Copy link
Member

Choose a reason for hiding this comment

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

can this go in javaagent-bootstrap near HelperResources which serves somewhat similar purpose?

@@ -88,7 +89,7 @@ public ClassLoaderInstrumentation() {
return null;
}
try {
for (String prefix : Constants.BOOTSTRAP_PACKAGE_PREFIXES) {
for (String prefix : BootstrapPackagePrefixesHolder.getBootstrapPrefixes()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is Config not available here? If it is, we can just use a config property instead of a separate SPI?

Copy link
Member

Choose a reason for hiding this comment

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

See @pavolloffay's #1380 (comment)

We could also remove the SPI so vendors would set the packages in the config - I don't like this since it easily opens the config to the consumers.

I think I agree, I think nice to encapsulate vendor extension points in SPI, even if we end up with lots of them(?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for missing the comment! SGTM

return bootstrapPrefixes;
}

public static void setBootstrapPrefixes(String[] prefixes) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you make this class more similar to Config/OpenTelemetrySdkAccess? I.e. volatile static field, internal... setter method name, checking that you can only set the value once.

private static String[] bootstrapPrefixes;

public static String[] getBootstrapPrefixes() {
return bootstrapPrefixes;
Copy link
Member

Choose a reason for hiding this comment

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

If it's supposed to be available in instrumentation-api consider using a List (and Collections.unmodifiableList() wrapper): arrays are mutable and can be easily changed by anybody.

This feature is useful when a large set of custom instrumentations is
using common classes from a custom package.

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
@pavolloffay
Copy link
Member Author

@mateuszrzeszutek I have updated the PR

return BOOSTRAP_PACKAGE_PREFIXES;
}

public static void setBoostrapPackagePrefixes(List<String> prefixes) {
Copy link
Member

Choose a reason for hiding this comment

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

Just a minor comment: how about internalSetBootstrapPackagePrefixes?

@pavolloffay
Copy link
Member Author

@trask @anuraaga could we get this in?

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

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

👍

@trask
Copy link
Member

trask commented Oct 16, 2020

Closing and re-opening to re-trigger the stuck CLA check

@trask trask closed this Oct 16, 2020
@trask trask reopened this Oct 16, 2020
@trask trask merged commit f29763d into open-telemetry:master Oct 16, 2020
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.

None yet

5 participants