|
77 | 77 | import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isKeyPresent; |
78 | 78 |
|
79 | 79 | import com.amazonaws.arn.Arn; |
80 | | -import com.amazonaws.services.lambda.AWSLambda; |
81 | | -import com.amazonaws.services.lambda.AWSLambdaClientBuilder; |
82 | | -import com.amazonaws.services.lambda.model.GetFunctionRequest; |
83 | | -import com.amazonaws.services.lambda.model.GetFunctionResult; |
84 | 80 | import io.opentelemetry.api.common.AttributeKey; |
85 | 81 | import io.opentelemetry.api.common.Attributes; |
86 | 82 | import io.opentelemetry.api.common.AttributesBuilder; |
@@ -510,46 +506,37 @@ private static void setRemoteResourceTypeAndIdentifier(SpanData span, Attributes |
510 | 506 | } else if (isKeyPresent(span, AWS_LAMBDA_NAME)) { |
511 | 507 | remoteResourceType = Optional.of(NORMALIZED_LAMBDA_SERVICE_NAME + "::Function"); |
512 | 508 | remoteResourceIdentifier = |
513 | | - getLambdaNameFromArbitraryName( |
514 | | - Optional.ofNullable(escapeDelimiters(span.getAttributes().get(AWS_LAMBDA_NAME)))); |
515 | | - cloudformationPrimaryIdentifier = |
516 | | - getLambdaArnFromArbitraryName( |
| 509 | + getLambdaResourceNameFromAribitraryName( |
517 | 510 | Optional.ofNullable(escapeDelimiters(span.getAttributes().get(AWS_LAMBDA_NAME)))); |
518 | 511 | } else if (isKeyPresent(span, AWS_LAMBDA_RESOURCE_ID)) { |
519 | 512 | remoteResourceType = Optional.of(NORMALIZED_LAMBDA_SERVICE_NAME + "::EventSourceMapping"); |
520 | 513 | remoteResourceIdentifier = |
521 | 514 | Optional.ofNullable(escapeDelimiters(span.getAttributes().get(AWS_LAMBDA_RESOURCE_ID))); |
522 | | - cloudformationPrimaryIdentifier = remoteResourceIdentifier; |
523 | 515 | } |
524 | 516 | } else if (isDBSpan(span)) { |
525 | 517 | remoteResourceType = Optional.of(DB_CONNECTION_RESOURCE_TYPE); |
526 | 518 | remoteResourceIdentifier = getDbConnection(span); |
527 | 519 | } |
528 | 520 |
|
| 521 | + if (cloudformationPrimaryIdentifier.isEmpty()) { |
| 522 | + cloudformationPrimaryIdentifier = remoteResourceIdentifier; |
| 523 | + } |
| 524 | + |
529 | 525 | if (remoteResourceType.isPresent() && remoteResourceIdentifier.isPresent()) { |
530 | 526 | builder.put(AWS_REMOTE_RESOURCE_TYPE, remoteResourceType.get()); |
531 | 527 | builder.put(AWS_REMOTE_RESOURCE_IDENTIFIER, remoteResourceIdentifier.get()); |
532 | | - } |
533 | | - if (cloudformationPrimaryIdentifier.isPresent()) { |
534 | 528 | builder.put(AWS_CLOUDFORMATION_PRIMARY_IDENTIFIER, cloudformationPrimaryIdentifier.get()); |
535 | 529 | } |
536 | 530 | } |
537 | 531 |
|
538 | | - private static Optional<String> getLambdaNameFromArbitraryName(Optional<String> arbitraryName) { |
539 | | - AWSLambda lambdaClient = AWSLambdaClientBuilder.defaultClient(); |
540 | | - GetFunctionRequest getFunctionRequest = |
541 | | - new GetFunctionRequest().withFunctionName(arbitraryName.get()); |
542 | | - GetFunctionResult getFunctionResult = lambdaClient.getFunction(getFunctionRequest); |
543 | | - return Optional.of(getFunctionResult.getConfiguration().getFunctionName()); |
544 | | - } |
545 | | - |
546 | 532 | // NOTE: "name" in this case can be either the lambda name or lambda arn |
547 | | - private static Optional<String> getLambdaArnFromArbitraryName(Optional<String> arbitraryName) { |
548 | | - AWSLambda lambdaClient = AWSLambdaClientBuilder.defaultClient(); |
549 | | - GetFunctionRequest getFunctionRequest = |
550 | | - new GetFunctionRequest().withFunctionName(arbitraryName.get()); |
551 | | - GetFunctionResult getFunctionResult = lambdaClient.getFunction(getFunctionRequest); |
552 | | - return Optional.of(getFunctionResult.getConfiguration().getFunctionArn()); |
| 533 | + private static Optional<String> getLambdaResourceNameFromAribitraryName( |
| 534 | + Optional<String> arbitraryName) { |
| 535 | + if (arbitraryName != null && arbitraryName.get().startsWith("arn:aws:lambda:")) { |
| 536 | + Arn resourceArn = Arn.fromString(arbitraryName.get()); |
| 537 | + return Optional.of(resourceArn.getResource().toString().split(":")[1]); |
| 538 | + } |
| 539 | + return arbitraryName; |
553 | 540 | } |
554 | 541 |
|
555 | 542 | private static Optional<String> getSecretsManagerResourceNameFromArn(Optional<String> stringArn) { |
|
0 commit comments