88
99from amazon .opentelemetry .distro ._aws_attribute_keys import (
1010 AWS_AUTH_ACCESS_KEY ,
11- AWS_AUTH_CREDENTIAL_PROVIDER_ARN ,
11+ AWS_AUTH_CREDENTIAL_PROVIDER ,
1212 AWS_AUTH_REGION ,
1313 AWS_BEDROCK_AGENT_ID ,
1414 AWS_BEDROCK_AGENTCORE_BROWSER_ARN ,
@@ -741,7 +741,9 @@ def _handle_browser_attrs(attrs: BoundedAttributes) -> tuple[Optional[str], Opti
741741 if browser_id :
742742 agentcore_cfn_identifier = str (browser_id )
743743 elif browser_arn :
744- agentcore_cfn_identifier = extract_bedrock_agentcore_resource_id_from_arn (str (browser_arn ))
744+ agentcore_cfn_identifier = RegionalResourceArnParser .extract_bedrock_agentcore_resource_id_from_arn (
745+ str (browser_arn )
746+ )
745747
746748 # Uses browser ID as both resource identifier and CFN primary identifier.
747749 # aws.browser.v1 is a managed AWS resource, custom IDs are user-defined resources.
@@ -763,7 +765,9 @@ def _handle_gateway_attrs(attrs: BoundedAttributes) -> tuple[Optional[str], Opti
763765 if gateway_id :
764766 agentcore_cfn_identifier = str (gateway_id )
765767 elif gateway_arn :
766- agentcore_cfn_identifier = extract_bedrock_agentcore_resource_id_from_arn (str (gateway_arn ))
768+ agentcore_cfn_identifier = RegionalResourceArnParser .extract_bedrock_agentcore_resource_id_from_arn (
769+ str (gateway_arn )
770+ )
767771 else :
768772 agentcore_cfn_identifier = str (gateway_target_id )
769773
@@ -778,7 +782,9 @@ def _handle_gateway_attrs(attrs: BoundedAttributes) -> tuple[Optional[str], Opti
778782 if gateway_id :
779783 agentcore_cfn_identifier = str (gateway_id )
780784 elif gateway_arn :
781- agentcore_cfn_identifier = extract_bedrock_agentcore_resource_id_from_arn (str (gateway_arn ))
785+ agentcore_cfn_identifier = RegionalResourceArnParser .extract_bedrock_agentcore_resource_id_from_arn (
786+ str (gateway_arn )
787+ )
782788
783789 # Uses gateway ID as both resource identifier and CFN primary identifier.
784790 # If gateway ID is not available, extract it from the gateway ARN.
@@ -797,7 +803,9 @@ def _handle_runtime_attrs(attrs: BoundedAttributes) -> tuple[Optional[str], Opti
797803 runtime_endpoint_arn = attrs .get (AWS_BEDROCK_AGENTCORE_RUNTIME_ENDPOINT_ARN )
798804
799805 if runtime_endpoint_arn :
800- agentcore_cfn_identifier = extract_bedrock_agentcore_resource_id_from_arn (str (runtime_endpoint_arn ))
806+ agentcore_cfn_identifier = RegionalResourceArnParser .extract_bedrock_agentcore_resource_id_from_arn (
807+ str (runtime_endpoint_arn )
808+ )
801809
802810 # Uses extracted ID as resource identifier and full ARN as CFN primary identifier.
803811 return "RuntimeEndpoint" , agentcore_cfn_identifier , str (runtime_endpoint_arn )
@@ -807,7 +815,9 @@ def _handle_runtime_attrs(attrs: BoundedAttributes) -> tuple[Optional[str], Opti
807815 if runtime_id :
808816 agentcore_cfn_identifier = str (runtime_id )
809817 elif runtime_arn :
810- agentcore_cfn_identifier = extract_bedrock_agentcore_resource_id_from_arn (str (runtime_arn ))
818+ agentcore_cfn_identifier = RegionalResourceArnParser .extract_bedrock_agentcore_resource_id_from_arn (
819+ str (runtime_arn )
820+ )
811821
812822 # Uses runtime ID as both resource identifier and CFN primary identifier.
813823 # If runtime ID is not available, extract it from the runtime ARN.
@@ -829,7 +839,9 @@ def _handle_code_interpreter_attrs(attrs: BoundedAttributes) -> tuple[Optional[s
829839 if code_interpreter_id :
830840 agentcore_cfn_identifier = str (code_interpreter_id )
831841 elif code_interpreter_arn :
832- agentcore_cfn_identifier = extract_bedrock_agentcore_resource_id_from_arn (str (code_interpreter_arn ))
842+ agentcore_cfn_identifier = RegionalResourceArnParser .extract_bedrock_agentcore_resource_id_from_arn (
843+ str (code_interpreter_arn )
844+ )
833845
834846 # Uses code interpreter ID as both resource identifier and CFN primary identifier.
835847 # aws.codeinterpreter.v1 is a managed AWS resource, custom IDs are user-defined resources.
@@ -844,22 +856,33 @@ def _handle_code_interpreter_attrs(attrs: BoundedAttributes) -> tuple[Optional[s
844856def _handle_identity_attrs (attrs : BoundedAttributes ) -> tuple [Optional [str ], Optional [str ], Optional [str ]]:
845857 """
846858 Handler for BedrockAgentCore Identity resources.
847- Returns (resource_type, resource_identifier, cfn_primary_identifier).
848859 """
849- credential_arn = attrs .get (AWS_AUTH_CREDENTIAL_PROVIDER_ARN )
860+ credentials_provider = attrs .get (AWS_AUTH_CREDENTIAL_PROVIDER )
861+ rpc_method = attrs .get (_RPC_METHOD )
850862
851- if credential_arn :
852- credential_arn_str = str (credential_arn )
863+ if credentials_provider and rpc_method :
864+ credentials_provider_str = str (credentials_provider )
865+ rpc_method_str = str (rpc_method ).lower ()
853866 resource_type = None
854- if "apikeycredentialprovider" in credential_arn_str :
867+
868+ # Determine the credential provider type from the RPC method.
869+ # The credential provider can be either an ARN or a name. While ARNs contain
870+ # type information, names do not, so we infer the type from the API operation.
871+ if "apikey" in rpc_method_str :
855872 resource_type = "APIKeyCredentialProvider"
856- elif "oauth2credentialprovider " in credential_arn_str :
873+ elif "oauth2 " in rpc_method_str :
857874 resource_type = "OAuth2CredentialProvider"
858- agentcore_cfn_identifier = extract_bedrock_agentcore_resource_id_from_arn (credential_arn_str )
859875
860- # Uses extracted ID from credential ARN as both resource identifier and CFN primary identifier.
861- # Resource type is determined by credential provider type in the ARN.
862- return resource_type , agentcore_cfn_identifier , agentcore_cfn_identifier
876+ if resource_type :
877+ # CFN identifier is the credentials provider name.
878+ # If the credentials provider is an ARN, we extract the name from the ARN.
879+ agentcore_cfn_identifier = (
880+ RegionalResourceArnParser .extract_bedrock_agentcore_resource_id_from_arn (credentials_provider_str )
881+ or credentials_provider_str
882+ )
883+
884+ # Uses credential name as both resource identifier and CFN primary identifier.
885+ return resource_type , agentcore_cfn_identifier , agentcore_cfn_identifier
863886
864887 return None , None , None
865888
@@ -878,8 +901,9 @@ def _handle_memory_attrs(attrs: BoundedAttributes) -> tuple[Optional[str], Optio
878901 if memory_id :
879902 agentcore_cfn_identifier = str (memory_id )
880903 if memory_arn :
881- agentcore_cfn_identifier = agentcore_cfn_identifier or extract_bedrock_agentcore_resource_id_from_arn (
882- str (memory_arn )
904+ agentcore_cfn_identifier = (
905+ agentcore_cfn_identifier
906+ or RegionalResourceArnParser .extract_bedrock_agentcore_resource_id_from_arn (str (memory_arn ))
883907 )
884908 agentcore_cfn_primary_identifier = str (memory_arn )
885909
@@ -890,14 +914,6 @@ def _handle_memory_attrs(attrs: BoundedAttributes) -> tuple[Optional[str], Optio
890914 return None , None , None
891915
892916
893- def extract_bedrock_agentcore_resource_id_from_arn (arn : str ) -> Optional [str ]:
894- """Extract resource ID from ARN resource part."""
895- resource_part = RegionalResourceArnParser .extract_resource_name_from_arn (arn )
896- if not resource_part :
897- return None
898- return resource_part .split ("/" )[- 1 ] if "/" in resource_part else resource_part
899-
900-
901917def _log_unknown_attribute (attribute_key : str , span : ReadableSpan ) -> None :
902918 message : str = "No valid %s value found for %s span %s"
903919 if _logger .isEnabledFor (DEBUG ):
0 commit comments