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

Fix aws-sdk-2.2 library instrumentation crashing app when SQS is not on classpath #8805

Merged

Conversation

Oberon00
Copy link
Member

@Oberon00 Oberon00 commented Jun 26, 2023

This is a regression introduced in my previous merged PR #8775. See especially thread at #8775 (comment). I was only thinking about the javaagent case when doing this, where Muzzle will ensure that everything is safe, but for the library & library-autoconfigure mode we need to be safe against the case that SqsImpl is on the classpath but the actual SDK SQS classes are not.

Adding tests for this also required fixes to how test dependencies are specified, the result is now more aligned with how it's done for the v1 SDK instrumentation.

⚠️ Either this PR (or at least 07f8ed5) or a revert of #8775 should be merged before the next release of the aws-sdk-2.2 library instrumentations, as this is a quite bad bug.

// in the agent
Class.forName(implFullClassName);
return true;
} catch (ClassNotFoundException | LinkageError e) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Main change 1: Catch LinkageError (incl. NoClassDefFoundError)

// Force loading of SqsClient; this ensures that an exception is thrown at this point when the
// SQS library is not present, which will cause SnsAccess to have enabled=false in library mode.
@SuppressWarnings("unused")
String ensureLoadedDummy = SqsClient.class.getName();
Copy link
Member Author

Choose a reason for hiding this comment

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

Main change 2: Ensure that initializing the class fails when the required module is not on the classpath.

Note that for me, this change here was not even required and it seemed to fail already anyways. But from trying to understand https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-5.html#jvms-5.4, I think without this change it would be JVM-implementation defined if we would get an error when initializing the class or only later when actually calling a method that has an unloadable type in its signature/implementation.

api("software.amazon.awssdk:s3:2.2.0")
api("software.amazon.awssdk:sqs:2.2.0")

// compileOnly because we never want to pin the low version implicitly; need to add dependencies
Copy link
Member Author

@Oberon00 Oberon00 Jun 26, 2023

Choose a reason for hiding this comment

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

This was required to allow using the testing module from the testCoreOnly test suite without also dragging in SQS. It required a slew of follow-up changes, but I think the end result is a bit cleaner, and also aligned with what the v1.1 SDK does.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed 👍
Honestly this is the pattern that I prefer myself when it comes to the testing modules -- let the actual instrumentation tests bring the versions they want.

@Oberon00 Oberon00 marked this pull request as ready for review June 26, 2023 14:04
@Oberon00 Oberon00 requested a review from a team June 26, 2023 14:04
api("software.amazon.awssdk:s3:2.2.0")
api("software.amazon.awssdk:sqs:2.2.0")

// compileOnly because we never want to pin the low version implicitly; need to add dependencies
Copy link
Member

Choose a reason for hiding this comment

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

Agreed 👍
Honestly this is the pattern that I prefer myself when it comes to the testing modules -- let the actual instrumentation tests bring the versions they want.

@trask trask merged commit bb4211d into open-telemetry:main Jun 28, 2023
@trask
Copy link
Member

trask commented Jun 28, 2023

thx for catching this!

@Oberon00 Oberon00 deleted the bugfix/aws-sdk-2.2-no-sqs branch June 29, 2023 14:57
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.

4 participants