Skip to content

AWS SDK v2.2 SPI Patch Migration #1113

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

anahatAWS
Copy link
Contributor

@anahatAWS anahatAWS commented Jul 8, 2025

Note: This is a continuation of #1111

Description of Changes

This implementation builds on the foundation established in PR #1111, transforming the structural setup into a fully functional SPI-based solution that will replace our current patching approach. This PR does not change the current ADOT functionality because patches have not been removed.

The next/final PR for v2.2 will remove the patches for aws-sdk-2.2 and have unit tests to ensure correct SPI functionality and behaviour. The final PR will also pass all the contract-tests once patches are removed.

Changes include:

  • Migration of patched files into proper package structure:
    NOTE: We are not copying entire files from upstream. Instead, we only migrated the new components that were added by our patches and the methods that use these AWS-specific components. I deliberately removed any code that was untouched by our patches to avoid duplicating upstream instrumentation code. This selective migration ensures we maintain only our AWS-specific additions while letting OTel handle its base functionality.
  • Setup of dependent files directly copied from upstream aws-sdk:
    • MethodHandleFactory - copy-pasted from here
    • FieldMapping - copy-pasted from here
    • AwsJsonProtocolFactoryAccess - copy-pasted from here

These added files:

  • Access and modify span attributes
  • Provide consistent formatting tools for span attributes
  • Can be updated at our convenience if needed

The classes we copied from upstream are just helper utilities that make it easier to inject span attributes during instrumentation. They're not core functionality that needs to stay in sync with upstream changes, rather standalone utilities that support our simpler, independent instrumentation without creating version lock-in. They're independent of OTel's core functionality, so we don't face the same version dependency issues we had with patching. We're just following upstream's structure for consistency.

OTel attribution for copied files

The 3 coped files have the OTel header included in them. This follows section 4 a)-c) in the ADOT LICENSE

Testing

  • Existing functionality verified
  • Contract tests passing
  • Build successful

Related

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@anahatAWS anahatAWS requested a review from a team as a code owner July 8, 2025 18:29
@pxaws
Copy link
Member

pxaws commented Jul 10, 2025

I think the following links are not correct. Could you double check?

===============================
AwsExperimentalAttributes - patch creates new class
AwsSdkRequest - patch on this otel file
AwsSdkRequestType - patch on this otel file
BedrockJsonParser - patch creates new class
FieldMapper - patch on this otel file
Serializer - patch on this otel file
BedrockJsonParserTest - patch creates new class
AbstractAws2ClientTest - patch on this otel file

@anahatAWS
Copy link
Contributor Author

anahatAWS commented Jul 10, 2025

I have updated the links, should be correct now.

// Check if upstream aws sdk instrumentation is enabled
if (!executionAttributes
.toString()
.contains("io.opentelemetry.javaagent.shaded.instrumentation.awssdk")) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you add comment to explain why this attribute is expected for a span created by upstream instrumentation? io.opentelemetry.javaagent.shaded.instrumentation.awssdk looks like a shaded class name. Will the name be stable in future?

Copy link
Member

Choose a reason for hiding this comment

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

Any alternative way to check? It seems not very stable to rely on the shaded class name. It's quite easy for upstream to just use another name without knowing we are relying on the old name. The whole shading things should be transparent to business logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed offline, will check the span attributes for aws-specific attributes that should be set by upstream aws-sdk. Span interface is designed for setting attributes, not reading them (Span API). It would have been more efficient if the api allowed us to search the map, but I think the approach I suggested is a way around it

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.

2 participants