Skip to content

feat: Extract account/access key id and region for cross-account support #1081

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 2 commits into
base: main
Choose a base branch
from

Conversation

blairhyy-amazon
Copy link

@blairhyy-amazon blairhyy-amazon commented May 12, 2025

Description of changes:
Changes in ADOT package to support cross-account observability in Java V1 & V2 SDK.

  1. We extract account id and region from remote resource arn.
  2. We pass account access key id and region from span to metric when resource arn is not available.

Related changes in upstream package: mxiamxia/opentelemetry-java-instrumentation#30

Testing Plan:

  1. Unit tests for extracting account id and region from remote resource arn.
  2. Unit tests for extracting access key and region from credential.
  3. Unit test for the scenario when resource arn and credential information are both available.

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

@@ -168,6 +187,9 @@ private Attributes generateDependencyMetricAttributes(SpanData span, Resource re
setEgressOperation(span, builder);
setRemoteServiceAndOperation(span, builder);
setRemoteResourceTypeAndIdentifier(span, builder);
setRemoteResourceAccessKeyAndRegion(span, builder);
setRemoteResourceAccountIdAndRegion(
Copy link
Member

Choose a reason for hiding this comment

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

By reversing the order of these two functions, you won't need to remove AK later.

remoteRegion = domainParts[1];
} catch (Exception e) {
logger.log(
Level.WARNING,
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it should be WARNING logs, it will blow user logs whenever there's a failure in the extraction.

Copy link
Author

Choose a reason for hiding this comment

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

Downgraded to FINEST that has a low level value (300).

queueUrl = queueUrl.replace("https://", "");

String[] parts = queueUrl.split("/");
remoteAccountId = parts[1];
Copy link
Member

Choose a reason for hiding this comment

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

Please check the length before getting anything using hard-coded index to avoid unexpected exceptions.

for (AttributeKey<String> attributeKey : ARN_ATTRIBUTES) {
if (isKeyPresent(span, attributeKey)) {
String arn = span.getAttributes().get(attributeKey);
remoteAccountId = arn.split(":")[4];
Copy link
Member

Choose a reason for hiding this comment

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

Same here for length checking.

}
}

if (!remoteAccountId.equals(UNKNOWN_REMOTE_ACCOUNT_ID)
Copy link
Member

Choose a reason for hiding this comment

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

Why not just set the default values to null or empty string? It seems you are not using UNKNOWN anywhere as assigned values.

@@ -52,6 +52,8 @@ final class AwsSpanProcessingUtil {
static final String UNKNOWN_OPERATION = "UnknownOperation";
static final String UNKNOWN_REMOTE_SERVICE = "UnknownRemoteService";
static final String UNKNOWN_REMOTE_OPERATION = "UnknownRemoteOperation";
static final String UNKNOWN_REMOTE_ACCOUNT_ID = "UnknownRemoteAccountId";
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need it?

@blairhyy-amazon blairhyy-amazon force-pushed the main branch 2 times, most recently from e8f1f43 to 6df41d3 Compare May 30, 2025 22:00
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