

# Setting up fleet cost and usage

To show cost and usage on the **Observability** tab, the spans that Amazon Bedrock AgentCore records in each member account must reach the account that owns your organization-scoped registry. Complete the prerequisites, then turn on CloudWatch trusted access and create a centralization rule.

## Prerequisites
<a name="registry-cost-observability-prerequisites"></a>

Before you begin, make sure that you have the following:
+  **An organization-scoped registry with active auto-detection** – The registry must be owned by the management account of your organization or by the delegated administrator for AWS Agent Registry, and its auto-detection status must be `ACTIVE`. The **Observability** tab appears only on this registry, and only when you’re signed in to the account that owns it. For setup, see [Using AWS Agent Registry with AWS Organizations](registry-organizations.md).
+  **AgentCore observability in each member account** – AgentCore records spans in a member account only when the following are set up there:
  + CloudWatch Transaction Search is turned on in each member account and Region where your agents run. For more information, see [Enabling CloudWatch Transaction Search](observability-configure.md#observability-configure-builtin-cw).
  + Tracing is turned on for the AgentCore resources that you want to include, such as runtimes, gateways, and memories. For more information, see [Configure observability](observability-configure.md).
  + To include model inference costs, your agent code is instrumented with the AWS Distro for OpenTelemetry (ADOT), so that each model call records a span with its token usage. For more information, see [Get started with AgentCore Observability](observability-get-started.md).
+  **Cost-stamped spans** – AgentCore adds an estimated cost to the spans that it can price. You don’t need to turn this on.
+  **CloudWatch Logs centralization in your Region** – Your registry’s Region supports CloudWatch Logs centralization. For more information, see [Cross-account cross-Region log centralization](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CloudWatchLogs_Centralization.html) in the *Amazon CloudWatch Logs User Guide*.

## Turn on fleet cost and usage
<a name="registry-cost-observability-setup-steps"></a>

You need the permissions in [Permissions to set up fleet cost and usage](registry-cost-observability-permissions.md#registry-cost-observability-permissions-setup) to complete these steps.

### Step 1: Turn on CloudWatch trusted access
<a name="registry-cost-observability-setup-trusted-access"></a>

CloudWatch can copy logs from the accounts in your organization only after you turn on trusted access for CloudWatch in AWS Organizations. Do this from the management account.

To turn on CloudWatch trusted access in the AWS Agent Registry console, do the following:

1. Open the [AWS Agent Registry console](https://console.aws.amazon.com/agent-registry/home?region=us-east-1#), signed in to the management account.

1. In the navigation pane, choose **Settings**.

1. In the **CloudWatch organization integration** section, choose **Edit**.

1. Select **Enable CloudWatch trusted access**, and then choose **Save**.

Turning on CloudWatch trusted access does the following:
+ Turns on trusted access for CloudWatch (`observabilityadmin.amazonaws.com`) in AWS Organizations.
+ Creates the service-linked role `AWSServiceRoleForObservabilityAdmin` in the management account. Amazon CloudWatch defines the role.

To turn on CloudWatch trusted access with the AWS CLI, run the following commands in the management account:

```bash
aws organizations enable-aws-service-access \
  --service-principal observabilityadmin.amazonaws.com

aws iam create-service-linked-role \
  --aws-service-name observabilityadmin.amazonaws.com
```

Trusted access for CloudWatch applies to your whole organization. All of your organization’s centralization rules depend on it, including rules that AWS Agent Registry doesn’t use, so keep it turned on while you use them.

### Step 2: Create a centralization rule
<a name="registry-cost-observability-setup-rule"></a>

Create the rule in the CloudWatch console or with the CloudWatch Observability Admin API, from the management account or from the delegated administrator for CloudWatch. For instructions on creating the rule, see [Cross-account cross-Region log centralization](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CloudWatchLogs_Centralization.html) in the *Amazon CloudWatch Logs User Guide*.

The **Observability** tab uses a rule only if it meets these conditions:
+  **Source accounts** – The rule’s source is your entire organization.
+  **Source Regions** – The rule includes the Region of your registry. The tab reads spans only from the registry’s Region.
+  **Destination** – The rule’s destination is the account that owns your organization-scoped registry, in the registry’s Region.
+  **Log groups** – The rule copies the log groups that hold AgentCore spans and evaluation results:
  +  `aws/spans`, where CloudWatch Transaction Search writes the spans of AgentCore Gateway, Memory, Runtime, and the tools.
  + The log groups whose names start with `/aws/bedrock-agentcore/runtimes/`. AgentCore Runtime agents can write their own spans, including their model calls, to the agent’s log group there. For more information, see [Span destination for agents hosted in Amazon Bedrock AgentCore runtime](observability-configure.md#observability-configure-unified-traces). Online evaluation results that you send to the agent’s log group are there too.
  + The log groups whose names start with `/aws/bedrock-agentcore/evaluations/`, where AgentCore Evaluations writes the results of online evaluation configurations and batch evaluations.

    If you filter log groups, select all three. For example, use this log group selection criteria:

    ```sql
    LogGroupName = 'aws/spans' OR LogGroupName LIKE '/aws/bedrock-agentcore/runtimes/%' OR LogGroupName LIKE '/aws/bedrock-agentcore/evaluations/%'
    ```

    If you send evaluation results to a log group of your own, add that log group to the rule too.

The rule copies only spans that arrive after you create it. It doesn’t copy spans that are already in the member accounts.

**Tip**  
You can open the CloudWatch console from AWS Agent Registry. On the registry’s **Observability** tab, or in the **CloudWatch organization integration** section of **Settings**, choose **Create rule in CloudWatch** or **Manage rules in CloudWatch**.

### Step 3: Verify the setup
<a name="registry-cost-observability-setup-verify"></a>

To verify the setup, do the following:

1. Open the [AWS Agent Registry console](https://console.aws.amazon.com/agent-registry/home?region=us-east-1#), signed in to the account that owns your organization-scoped registry.

1. Choose **Registries**, choose your registry, and then choose the **Observability** tab.

1. If the setup isn’t complete, the tab shows **Set up CloudWatch organization integration** and the reason, such as trusted access being off or no healthy centralization rule copying spans into the registry’s account. Fix the issue, and then choose **Check again**.

1. When the setup is complete, the tab shows the fleet’s cost and usage. The **Accounts reporting** figure shows how many accounts' spans reached the registry’s account in the last 24 hours, out of the accounts that have an auto-detected agent.

To check a centralization rule’s health, open **Settings** and find the **Centralization rules** table in the **CloudWatch organization integration** section. A new rule shows **Provisioning** until CloudWatch finishes setting it up, and then **Healthy**.