Skip to content

Conversation

@lukeina2z
Copy link
Contributor

The X-Ray SDK Core previously relied on AWS SDK v1 solely to support AWS Remote Sampling. However, the SDK does not use the SDK’s client to call the sampling service directly. Instead, it composes REST requests manually and sends them through an AWS proxy. The only part of AWS SDK v1 being used was the data model types for serialization into JSON.

This change removes the AWS SDK v1 dependency by reimplementing the necessary data types internally, eliminating the need to rely on the external SDK.

Test Plan:
Unit tests: Pass
E2E tests with X-Ray Daemon: Pass
E2E tests with CloudWatch Agent: Pass

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

@lukeina2z lukeina2z requested a review from a team as a code owner July 30, 2025 15:07
Comment on lines 133 to 140
snapshot = SamplingStatisticsDocument.newBuilder()
.setClientId(CentralizedSamplingStrategy.getClientID())
.setBorrowCount(snapshot.getBorrowCount())
.setRequestCount(snapshot.getRequestCount())
.setRuleName(snapshot.getRuleName())
.setSampledCount(snapshot.getSampledCount())
.setTimestamp(snapshot.getTimestamp())
.build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Confused as to why the properties being read and set from the same snapshot instance?

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the motivation for this change?

Copy link
Contributor Author

@lukeina2z lukeina2z Jul 31, 2025

Choose a reason for hiding this comment

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

In AWS SDK V2, a key change is immutability. The one returned from rule.snapshot(date) is read-only. We need create a copy of that, and override snapshot. Let me rename it.

Comment on lines 56 to 59
@Deprecated
public RulePoller(CentralizedManifest manifest, AWSXRay unused, Clock clock) {
public RulePoller(CentralizedManifest manifest, Object unused, Clock clock) {
this(new UnsignedXrayClient(), manifest, clock);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

non-blocking: Can this constructor be removed entirely since it is deprecated?

Copy link
Contributor Author

@lukeina2z lukeina2z Jul 31, 2025

Choose a reason for hiding this comment

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

Deleted.

logger.info("Polling sampling rules.");
GetSamplingRulesRequest req = new GetSamplingRulesRequest();
GetSamplingRulesResult records = client.getSamplingRules(req);
GetSamplingRulesRequest req = GetSamplingRulesRequest.create(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Passing in a null is generally not a good practice. What does the GetSamplingRulesRequest.create method expects and why are we unable to provide that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the definition of create() method: the parameter is @nullable

public static GetSamplingRulesRequest create(@Nullable String nextToken) {
    return new AutoValue_GetSamplingRulesRequest(nextToken);
}

Comment on lines 51 to 54
@Deprecated
public TargetPoller(CentralizedManifest manifest, AWSXRay unused, Clock clock) {
public TargetPoller(CentralizedManifest manifest, Object unused, Clock clock) {
this(new UnsignedXrayClient(), manifest, clock);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as above. See if this can be removed.

Copy link
Contributor Author

@lukeina2z lukeina2z Jul 31, 2025

Choose a reason for hiding this comment

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

Method deleted.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: Is this and the other new data model classes based off of existing classes in AWS SDK or somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have similar models in otel-contrib.

.withCredentials(ANONYMOUS_CREDENTIALS) // This will entirely skip signing too
.build();

public static Object newClient() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can even be fully removed?

Copy link
Contributor Author

@lukeina2z lukeina2z Jul 31, 2025

Choose a reason for hiding this comment

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

File deleted.

build.gradle.kts Outdated
// 1. Google AutoValue does not generate @Nullable or @NonNull annotations on methods like equals() and hashCode().
// 2. The existing codebase does not consistently perform null checks, in line with the behavior of the X-Ray SDK:
// https://docs.aws.amazon.com/xray/latest/api/API_SamplingTargetDocument.html
skipCheckerFramework = skipCheckerFramework || project.name == "aws-xray-recorder-sdk-core"
Copy link
Contributor

Choose a reason for hiding this comment

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

This conflicts with the condition above where we skip null checker on all projects except the aws-xray-recorder-sdk-core. And now we are disabling on this project itself. What's even the point of having this checker now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I will remove it.

The X-Ray SDK Core previously relied on AWS SDK v1 solely to support AWS Remote Sampling. However, the SDK does not use the SDK’s client to call the sampling service directly. Instead, it composes REST requests manually and sends them through an AWS proxy. The only part of AWS SDK v1 being used was the data model types for serialization into JSON.

This change removes the AWS SDK v1 dependency by reimplementing the necessary data types internally, eliminating the need to rely on the external SDK.

Test Plan:
Unit tests: Pass
E2E tests with X-Ray Daemon: Pass
E2E tests with CloudWatch Agent: Pass
@lukeina2z lukeina2z merged commit c7391e5 into aws:master Jul 31, 2025
6 checks passed
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