View a markdown version of this page

可觀測性與 Amazon CloudWatch - Amazon Bedrock AgentCore

可觀測性與 Amazon CloudWatch

AgentCore 付款支援透過 Amazon CloudWatch 的可觀測性,因此您可以監控付款整合並進行疑難排解。

  • Amazon CloudWatch 是 AWS 監控和可觀測性服務。它會從您的 AWS 資源收集和追蹤指標、日誌和追蹤,讓您了解應用程式效能。

  • 已取代的日誌是 AWS 服務代表您直接發佈至 CloudWatch 日誌群組的日誌。與您自行檢測的應用程式日誌不同, 服務會自動產生付費日誌。您可以設定交付位置。

  • 跨度代表請求中的工作單位 (例如,API 呼叫及其下游操作)。使用跨度透過系統追蹤請求的流程,並識別延遲瓶頸或故障。

完成下列設定程序後,任何資料平面 API 呼叫 (例如 CreatePaymentInstrument) 都會在您設定的 CloudWatch 日誌群組中產生日誌和追蹤資料。

先決條件

  • CloudWatch 日誌群組做為交付目的地 (例如 /bedrock-agentcore/payments/my-logs)。如果您沒有,請使用主控台或 CLI 建立一個。

  • PaymentManager 的資源 ARN

建立日誌群組:

範例
Console

開啟 CloudWatch 主控台,前往日誌 > 日誌群組,然後選擇建立日誌群組。輸入類似 的名稱/bedrock-agentcore/payments/my-logs,然後選取您偏好的保留期間。

AWS CLI
aws logs create-log-group --log-group-name /bedrock-agentcore/payments/my-logs

IAM 許可

您的 IAM 使用者或角色必須具有下列許可,才能建立日誌和跨交付資源:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "CloudWatchLogsVendedDelivery", "Effect": "Allow", "Action": [ "logs:CreateDelivery", "logs:CreateLogGroup", "logs:CreateLogStream", "logs:DeleteDelivery", "logs:DeleteDeliveryDestination", "logs:DeleteDeliverySource", "logs:DeleteLogGroup", "logs:DeleteResourcePolicy", "logs:DescribeLogGroups", "logs:DescribeResourcePolicies", "logs:GetDelivery", "logs:GetDeliveryDestination", "logs:GetDeliverySource", "logs:PutDeliveryDestination", "logs:PutDeliverySource", "logs:PutLogEvents", "logs:PutResourcePolicy", "logs:PutRetentionPolicy" ], "Resource": "*" }, { "Sid": "XRayApplicationSignalsCloudTrail", "Effect": "Allow", "Action": [ "xray:GetTraceSegmentDestination", "xray:ListResourcePolicies", "xray:PutResourcePolicy", "xray:PutTelemetryRecords", "xray:PutTraceSegments", "xray:UpdateTraceSegmentDestination", "application-signals:StartDiscovery", "cloudtrail:CreateServiceLinkedChannel" ], "Resource": "*" }, { "Sid": "CreateServiceLinkedRoleForAppSignals", "Effect": "Allow", "Action": "iam:CreateServiceLinkedRole", "Resource": "arn:*:iam::*:role/aws-service-role/application-signals.cloudwatch.amazonaws.com/AWSServiceRoleForCloudWatchApplicationSignals" }, { "Sid": "BedrockAgentCoreVendedLogDelivery", "Effect": "Allow", "Action": "bedrock-agentcore:AllowVendedLogDeliveryForResource", "Resource": "*" } ] }

付費日誌

已取代的日誌會在您設定的日誌群組中顯示為應用程式日誌。這些是由 AgentCore 付款服務為每個資料平面 API 呼叫自動產生。

已取代的跨度

已取代的跨度是個別請求的追蹤記錄。使用它們來視覺化 AWS X-Ray 中的請求流程。每個跨度代表工作單位 (例如 API 呼叫及其下游操作),可讓您識別延遲瓶頸或故障。

範圍名稱

AgentCore 付款會為每個資料平面 API 呼叫發出一個跨度。跨度名稱遵循模式 Bedrock.AgentCore.Payments.<Operation>

範圍名稱 說明

Bedrock.AgentCore.Payments.ProcessPayment

處理付款交易

Bedrock.AgentCore.Payments.CreatePaymentInstrument

建立付款工具

Bedrock.AgentCore.Payments.GetPaymentInstrument

擷取付款工具

Bedrock.AgentCore.Payments.ListPaymentInstruments

列出付款工具

Bedrock.AgentCore.Payments.DeletePaymentInstrument

刪除付款工具

Bedrock.AgentCore.Payments.GetPaymentInstrumentBalance

取得檢測平衡

Bedrock.AgentCore.Payments.CreatePaymentSession

建立付款工作階段

Bedrock.AgentCore.Payments.GetPaymentSession

擷取付款工作階段

Bedrock.AgentCore.Payments.ListPaymentSessions

列出付款工作階段

Bedrock.AgentCore.Payments.DeletePaymentSession

刪除付款工作階段

跨度屬性

每個範圍都包含在 AWS X-Ray 中篩選和分析的下列屬性:

屬性 說明

aws.payments.payment_manager_id

此請求的 Payment Manager ID

aws.payments.payment_connector_id

Payment Connector ID (如適用)

aws.payments.payment_instrument_id

付款工具 ID (如適用)

aws.payments.payment_session_id

付款工作階段 ID (如適用)

aws.payments.spend_amount

付款金額 (僅限 ProcessPayment)

aws.payments.spend_currency

付款貨幣 (僅限 ProcessPayment)

aws.payments.session_remaining_budget

付款後剩餘的工作階段預算 (僅限 ProcessPayment)

aws.payments.total_budget_amount

工作階段總預算 (僅限 ProcessPayment)

aws.payments.merchant

交易的商家地址 (payTo) (僅限 ProcessPayment)

aws.payments.payment_agent_name

如果透過 X-Amzn-Bedrock-AgentCore-Payments-Agent-Name標頭提供,則為客服人員名稱

aws.payments.token_fetch_latency_ms

從 AgentCore Identity 擷取登入資料字符的延遲 (僅限 ProcessPayment)

每個範圍也包含標準 AWS 屬性:

  • aws.region — AWS 區域

  • aws.account.id — 發起人的帳戶 ID

  • aws.resource.arn — PaymentManager ARN

  • aws.request_id — 請求 ID

  • http.response.status_code — HTTP 回應狀態碼

已取代的指標

AgentCore 付款會將下列指標發佈到您的 Amazon CloudWatch 命名空間。使用這些項目來建置儀表板、設定警示和監控付款運作狀態。

指標 單位 說明

OperationSuccess

計數

成功 API 呼叫的數量

OperationFailure

計數

失敗的 API 呼叫數量

OperationLatency

毫秒

每個 API End-to-end延遲

SpendAmount

已處理的付款金額 (僅限 ProcessPayment)

Throttles

計數

限流請求數

UserErrors

計數

用戶端驗證錯誤的數量

ActiveSessions

計數

作用中付款工作階段的數量

PaymentRequestCount

計數

付款請求總計

PaymentSuccessCount

計數

成功的付款交易

PaymentFailureCount

計數

失敗的付款交易

PaymentLatency

毫秒

付款處理延遲

指標維度

會發佈具有下列維度的指標以進行篩選:

  • 操作 — API 操作名稱 (一律存在)

  • PaymentManagerId — Payment Manager ID (可用時)

  • PaymentConnectorId — Payment Connector ID (可用時)

  • AgentName — 代理程式名稱 (透過標頭提供時)

  • 貨幣 — 付款貨幣 (適用於 SpendAmount 指標)

啟用可觀測性

範例
Console

從 Amazon Bedrock AgentCore 主控台的 Payment Manager 詳細資訊頁面:

  1. 導覽至日誌交付和追蹤區段。

  2. 設定將日誌交付至 CloudWatch 日誌群組。

  3. 啟用追蹤以檢視 AWS X-Ray 中的跨度。

Payment Manager 詳細資訊頁面上的可觀測性區段提供即時指標,包括工作階段計數、API 調用、交易成功率和錯誤率。

AWS CLI
# Step 1: Allow vended log delivery for your Payment Manager aws bedrock-agentcore allow-vended-log-delivery-for-resource \ --resource-arn "arn:aws:bedrock-agentcore:us-west-2:123456789012:payment-manager/my-manager" # Step 2: Create a delivery source aws logs put-delivery-source \ --name "payments-logs" \ --resource-arn "arn:aws:bedrock-agentcore:us-west-2:123456789012:payment-manager/my-manager" \ --log-type "APPLICATION_LOGS" # Step 3: Create a delivery destination aws logs put-delivery-destination \ --name "payments-log-destination" \ --delivery-destination-configuration '{"destinationResourceArn": "arn:aws:logs:us-west-2:123456789012:log-group:/bedrock-agentcore/payments/my-logs"}' # Step 4: Create the delivery aws logs create-delivery \ --delivery-source-name "payments-logs" \ --delivery-destination-arn "arn:aws:logs:us-west-2:123456789012:delivery-destination:payments-log-destination"
AWS SDK
import boto3 # Allow vended log delivery for your Payment Manager agentcore_client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") agentcore_client.allow_vended_log_delivery_for_resource( resourceArn="arn:aws:bedrock-agentcore:us-west-2:123456789012:payment-manager/my-manager" ) # Configure CloudWatch Logs delivery logs_client = boto3.client("logs", region_name="us-west-2") # Create delivery source logs_client.put_delivery_source( name="payments-logs", resourceArn="arn:aws:bedrock-agentcore:us-west-2:123456789012:payment-manager/my-manager", logType="APPLICATION_LOGS" ) # Create delivery destination logs_client.put_delivery_destination( name="payments-log-destination", deliveryDestinationConfiguration={ "destinationResourceArn": "arn:aws:logs:us-west-2:123456789012:log-group:/bedrock-agentcore/payments/my-logs" } ) # Create the delivery logs_client.create_delivery( deliverySourceName="payments-logs", deliveryDestinationArn="arn:aws:logs:us-west-2:123456789012:delivery-destination:payments-log-destination" )

如需 AgentCore 可觀測性的詳細資訊,請參閱 AgentCore 可觀測性。如需閘道特定的指標和範圍,請參閱 AgentCore 產生的閘道可觀測性資料