Skip to content

Commit

Permalink
Remove Lambda:Function:Name resource type support (#907)
Browse files Browse the repository at this point in the history
*Description of changes:*
Remove `RemoteResourceTargetIdentifier` attribute which will treat
Lambda Function as a regular AWS resource. It may conflict with the
current concept that have Lambda function defined as a service.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
  • Loading branch information
mxiamxia authored Oct 14, 2024
1 parent 77ce771 commit 2ea18a9
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ private AwsAttributeKeys() {}
static final AttributeKey<String> AWS_SECRET_ARN =
AttributeKey.stringKey("aws.secretsmanager.secret.arn");

static final AttributeKey<String> AWS_LAMBDA_NAME =
AttributeKey.stringKey("aws.lambda.function.name");

static final AttributeKey<String> AWS_LAMBDA_ARN =
AttributeKey.stringKey("aws.lambda.function.arn");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_GUARDRAIL_ARN;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_GUARDRAIL_ID;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_KNOWLEDGE_BASE_ID;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_LAMBDA_NAME;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_LAMBDA_RESOURCE_ID;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_LOCAL_OPERATION;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_LOCAL_SERVICE;
Expand Down Expand Up @@ -493,11 +492,6 @@ private static void setRemoteResourceTypeAndIdentifier(SpanData span, Attributes
Optional.ofNullable(escapeDelimiters(span.getAttributes().get(AWS_SECRET_ARN))));
cloudformationPrimaryIdentifier =
Optional.ofNullable(escapeDelimiters(span.getAttributes().get(AWS_SECRET_ARN)));
} else if (isKeyPresent(span, AWS_LAMBDA_NAME)) {
remoteResourceType = Optional.of(NORMALIZED_LAMBDA_SERVICE_NAME + "::Function");
remoteResourceIdentifier =
getLambdaResourceNameFromAribitraryName(
Optional.ofNullable(escapeDelimiters(span.getAttributes().get(AWS_LAMBDA_NAME))));
} else if (isKeyPresent(span, AWS_LAMBDA_RESOURCE_ID)) {
remoteResourceType = Optional.of(NORMALIZED_LAMBDA_SERVICE_NAME + "::EventSourceMapping");
remoteResourceIdentifier =
Expand All @@ -519,16 +513,6 @@ private static void setRemoteResourceTypeAndIdentifier(SpanData span, Attributes
}
}

// NOTE: "name" in this case can be either the lambda name or lambda arn
private static Optional<String> getLambdaResourceNameFromAribitraryName(
Optional<String> arbitraryName) {
if (arbitraryName != null && arbitraryName.get().startsWith("arn:aws:lambda:")) {
Arn resourceArn = Arn.fromString(arbitraryName.get());
return Optional.of(resourceArn.getResource().toString().split(":")[1]);
}
return arbitraryName;
}

private static Optional<String> getSecretsManagerResourceNameFromArn(Optional<String> stringArn) {
Arn resourceArn = Arn.fromString(stringArn.get());
return Optional.of(resourceArn.getResource().toString().split(":")[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_DATA_SOURCE_ID;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_GUARDRAIL_ID;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_KNOWLEDGE_BASE_ID;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_LAMBDA_NAME;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_LAMBDA_RESOURCE_ID;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_LOCAL_OPERATION;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_LOCAL_SERVICE;
Expand Down Expand Up @@ -802,11 +801,6 @@ public void testSdkClientSpanWithRemoteResourceAttributes() {
validateRemoteResourceAttributes("AWS::SecretsManager::Secret", "secretName");
mockAttribute(AWS_SECRET_ARN, null);

// Validate behaviour of AWS_LAMBDA_NAME, then remove it.
mockAttribute(AWS_LAMBDA_NAME, "arn:aws:lambda:us-east-1:123456789012:function:functionName");
validateRemoteResourceAttributes("AWS::Lambda::Function", "functionName");
mockAttribute(AWS_LAMBDA_NAME, null);

// Validate behaviour of AWS_LAMBDA_RESOURCE_ID
mockAttribute(AWS_LAMBDA_RESOURCE_ID, "eventSourceId");
validateRemoteResourceAttributes("AWS::Lambda::EventSourceMapping", "eventSourceId");
Expand Down

0 comments on commit 2ea18a9

Please sign in to comment.