Build visibility for Codex on Amazon Bedrock with OpenTelemetry and Amazon CloudWatch
https://aws.amazon.com/blogs/machine-learning/build-visibility-for-codex-on-amazon-bedrock-with-opentelemetry-and-amazon-cloudwatch/📌 【AWS 技術分享】如何在 Amazon Bedrock 上監控 Codex 使用狀況:結合 OpenTelemetry 與 CloudWatch
TL;DR:透過在開發者工作站部署本地 OTel Collector,可在不干擾推理路徑的情況下,實現 Codex 在 Bedrock 上的全方位使用監控。
當企業從「嘗試 AI 程式碼代理」轉向「全面導入工程團隊」時,管理層關注的焦點會從「這工具好用嗎?」轉向「我們如何掌握採用率、管理消耗量、維持可靠性,並負責任地擴展存取規模?」。
🤔 從實驗轉向規模化:監控的重要性
當 Codex 透過 Amazon Bedrock 使用 OpenAI 模型,並透過 AWS IAM Identity Center 進行驗證時,企業需要一套機制來區分「局部實驗」與「全面採用」。例如:
- 採用率分析:多個團隊同時增加活躍用戶,與少數用戶高消耗,代表完全不同的管理需求。
- 代理工作流(Agentic Workflows):透過觀察 Tool-call 活動,可以判斷代理工作流在團隊中的普及程度。
- 效能診斷:透過請求與持續時間(Duration)指標,協助調查使用者體驗下降的原因。
🧩 不干擾開發流程的架構設計
此方案的核心設計理念是「不增加集中式代理(Proxy)於模型請求路徑中」,確保開發者仍能於本地直接使用 Codex。
其技術流程如下:
- 本地收集:開發者工作站上運行一個僅監聽
127.0.0.1的本地 OTel Collector。 - 資訊增強:Collector 接收來自 Codex 的指標,並根據 IAM Identity Center 的身份資訊,自動注入組織層級的屬性(如:部門、團隊、成本中心)。
- 安全傳輸:Collector 使用 AWS Signature Version 4 (SigV4) 進行身份驗證,將批次處理後的指標發送到局部的 CloudWatch OTLP 端點。
- 原生整合:最終數據直接進入 Amazon CloudWatch,無需額外的 ECS 服務、負載均衡器或 VPC 複雜架構。
📊 關鍵指標與儀表板功能
透過部署 CodexOnBedrock 儀表板,工程主管可以獲得以下維度的視覺化數據:
| 指標類別 | 具體內容 |
|---|---|
| 使用量指標 | 24 小時活躍用戶總數、對話輪次(Conversation turns)、API 請求數、Token 使用量 |
| 維度細分 | 模型、Token 類型、使用者、部門、團隊、成本中心、組織、Session 來源 |
| 操作行為 | codex.turn.tool.call (工具調用活動) |
⚠️ 重要提醒:Token 消耗不等於帳單
請注意,CloudWatch 中的 Token 計數是用於趨勢分析與營運行為觀察,並非正式的結算帳單。由於價格調整、折扣或抵免額,List-price 預估值可能與實際收費不符。若需精確的成本分攤,應使用 AWS Cost and Usage Reports (CUR) 2.0 或 Amazon Bedrock 提供的成本管理報告。
🎯 實務部署建議與注意事項
-
隱私與治理:
- 建議針對高階主管使用「團隊/部門/成本中心」的聚合視圖。
- 針對「個人使用者」的儀表板,應嚴格限制給系統管理、營運、安全或財務人員,並符合員工監控與數據保留政策。
- 設計時應將
log_user_prompt設為false,僅收集營運指標而非原始碼或 Prompt 內容。
-
維護指標基數(Cardinality):
- 避免在維度中使用專案名稱或臨時識別碼,以免產生過多低價值序列。
- 應先定義好組織元數據(Metadata)的標準值、所有權與更新流程。
-
效能與成本控制:
- CloudWatch OTel 指標按每 GB 攝取量計費,PromQL 查詢則按掃描樣本數計費。
- 在大規模推行前,務必審核 CloudWatch 的定價模型。
🔗 來源
- 標題:Build visibility for Codex on Amazon Bedrock with OpenTelemetry and Amazon CloudWatch
- 作者/機構:Claudio Mazzoni @ AWS ML
- 連結:aws.amazon.com/blogs/machine-learning/build-visibility-for-codex-on-amazon-bedrock-with-opentelemetry-and-amazon-cloudwatch/
#AI #AWS #AmazonBedrock #OpenTelemetry #CloudWatch #Codex #MachineLearning #Observability #DevOps #EngineeringManagement
原始資料 AWS ML · 收集於 2026-08-07
摘要原文
As organizations move from experimenting with coding agents to adopting them across engineering teams, the leadership question changes. It is no longer only, “Can this tool help a developer?” It becomes, “How do we understand adoption, manage consumption, maintain reliability, and scale access responsibly?”. Codex can emit OpenTelemetry (OTel) metrics about its activity. When local Codex clients use OpenAI models through Amazon Bedrock and authenticate with AWS IAM Identity Center, you can route those metrics through a local OTel collector to Amazon CloudWatch. The result is an AWS native view of Codex usage that can be organized by user, team, department, organization, or cost center. This approach does not add a centralized proxy to the model-request path. Developers continue to use Codex locally. A collector running on each developer workstation receives metrics on the local host and enriches them with organizational context. It then sends them to the regional CloudWatch OpenTelemetry Protocol (OTLP) endpoint using AWS Signature Version 4 (SigV4). The reference deployment creates a CloudWatch dashboard, not an Amazon Elastic Container Service (Amazon ECS) service, load balancer, virtual private cloud (VPC), or public ingestion endpoint. In this post, we explain how this pattern supports governed adoption, review its architecture, and summarize the implementation in the Codex on AWS guidance repository . Telemetry is most useful when it answers a decision, not simply when it produces another dashboard. The bundled CodexOnBedrock dashboard includes rolling 24-hour totals for active users, conversation turns, API requests, and token usage. It also provides views by model, token type, user, department, team, cost center, organization, and session source. These signals can help technology leaders distinguish broad adoption from isolated experimentation. For example, an increase in active users across several teams suggests a different enablement need than high consumption concentrated among a small group. Tool-call activity can help teams see where agentic workflows are taking hold. Request and duration metrics can support investigation of degraded experiences. The distinction in the last row is important. CloudWatch OTel metrics show usage volume and operational behavior. Token counts can support trend analysis, but they are not a billing ledger. List-price estimates can diverge from actual charges because of pricing changes, discounts, credits, and billing adjustments. For realized spend, use IAM principal cost allocation from AWS Cost and Usage Reports (CUR) 2.0 or the applicable Amazon Bedrock cost-management reports. The architecture uses the same AWS identity for model access and telemetry publishing. A developer signs in through IAM Identity Center and runs Codex with Amazon Bedrock as the model provider. Codex sends metrics to a collector listening only on 127.0.0.1 . The collector adds identity and organizational attributes, batches the metrics, and signs requests to CloudWatch with temporary AWS credentials. Local Codex telemetry flow to Amazon CloudWatch through a local collector that publishes metrics with SigV4 authentication and stays out of the Amazon Bedrock inference path Codex emits metrics such as codex.api_request , codex.api_request.duration_ms , codex.turn.e2e_duration_ms , codex.turn.token_usage , codex.turn.tool.call , codex.thread.started , and codex.conversation.turn.count . The current Codex configuration documentation describes OTel as opt-in and documents separate exporters for logs, metrics, and traces. The local collector adds user.id and user.email as required resource attributes. Optional attributes include department , team.id , cost_center , organization , location , role , and manager . The reference collector copies these attributes onto each metric datapoint as well. This approach gives the dashboard consistent Prometheus Query Language (PromQL) groupings across the local sidecar and other supported ingestion patterns. The complete commands and templates are in the native AWS access quickstart . The following five stages summarize the implementation. The reference runbook begins by enabling OTel enrichment and resource tags for telemetry in the target Region: The current CloudWatch OTel documentation describes native OTLP ingestion and PromQL querying. The start-otel-enrichment operation enables enrichment and PromQL access for supported AWS vended metrics. The start-telemetry-enrichment operation enables resource-tag enrichment. Confirm which account-level settings are already enabled before changing them. Clone the repository, then deploy the dashboard and obtain the collector binary: The AWS CloudFormation stack deploys the CodexOnBedrock dashboard. The collector runs on developer workstations, so this step does not create centralized collector compute or networking infrastructure. Generate the collector configuration from the developer’s authenticated AWS profile: With --auto-lookup , the script can read organizational attributes from the IAM Identity Center identity store. Explicit command-line values can override discovered values. If an optional attribute is unavailable, omit its entire configuration block. Do not send placeholder strings as dimensions. They create low-value series and weaken reporting quality. For a fleet rollout, generate and distribute this configuration through your existing endpoint-management process. Treat organizational metadata as governed data: establish approved values, ownership, and update procedures before using it for executive reporting. Point the Codex metrics exporter to the local collector. Include the full /v1/metrics path because Codex does not append it: The collector forwards metrics to the regional CloudWatch OTLP metrics endpoint , such as https://monitoring.us-west-2.amazonaws.com/v1/metrics . SigV4 is the recommended authentication method for short-term AWS credentials. The publishing identity requires cloudwatch:PutMetricData . No log-group or ECS permissions are required for this metrics path. Retain log_user_prompt = false . This design is intended to measure operational and adoption signals, not collect source code or prompt content. Start the service-specific collector with the generated configuration, run a Codex task, and then open the CodexOnBedrock dashboard in the CloudWatch console. You can also use CloudWatch Query Studio or the repository’s check-otel-pipeline.sh script to confirm that codex.turn.token_usage is arriving. Codex metrics flush periodically and on a clean process exit. The reference runbook documents a 60-second interval and suggests OTEL_METRIC_EXPORT_INTERVAL=1000 as an optional safeguard for error paths that might skip the exit flush. If no metrics appear, also confirm that managed configuration has not set [analytics] enabled = false , because that setting disables the Codex metrics pipeline. The same dimensions that make the dashboard useful can create privacy and governance concerns if they are exposed too broadly. Use aggregated team, department, and cost-center views for executive reporting. Restrict per-user dashboards to approved system, operations, security, or finance roles, and align access with employee-monitoring and data-retention policies. Control metric cardinality as you scale. Standardize attribute names and values, omit fields that do not support a defined decision, and avoid adding project names or ephemeral identifiers without a retention and query plan. CloudWatch OTel metrics use per-gigabyte ingestion pricing, and PromQL queries are priced according to samples scanned. Review the current CloudWatch OTel pricing documentation and Amazon CloudWatch Pricing before a broad rollout. This pattern provides visibility and soft controls. You can use CloudWatch alarms and Amazon Simple Notification Service (Amazon SNS) notifications to alert when a user or team crosses a defined usage threshold.
由 tencent/hy3:free 自動生成