無料提供が始まった Basic OpenTelemetry enrichment を有効にして Lambda のメトリクスを PromQL で取得してみた

無料提供が始まった Basic OpenTelemetry enrichment を有効にして Lambda のメトリクスを PromQL で取得してみた

start-otel-enrichment で、課金対象の resource tag enrichment(取り込みに1GB あたり $0.50)を省いた Basic OpenTelemetry enrichment を有効にして、Lambda の Invocations を PromQL で取得できました。
2026.11.28

はじめに

2026年11月27日、Amazon CloudWatch の Basic OpenTelemetry enrichment がリリースされました。

https://aws.amazon.com/jp/about-aws/whats-new/2026/11/amazon-cloudwatch-opentelemetry-enrichment/

AWS サービスが CloudWatch に送るメトリクスのうち、リソースを識別できるものを、OpenTelemetry のデータポイントに変換する機能です。変換したデータポイントは、PromQL で問い合わせられます。

この記事では、Basic enrichment を有効にして Lambda のメトリクスを PromQL で取得し、系列に付くラベルと従来 API の値を確認します。

検証環境

  • リージョン:東京(ap-northeast-1)
  • 開始時の状態:get-otel-enrichment の Status が Stopped
  • AWS CLI:2.42.5(Docker イメージ amazon/aws-cli)
  • curl:8.18.0(PromQL の HTTP API の呼び出しに --aws-sigv4 を使用)
  • 有効化したレベル:Basic
  • メトリクスの発生源:何もしない Lambda 関数 otel-enrich-verify-fn(Python 3.13)

有効化

有効化には start-otel-enrichment を使います。レベルと有効化の方法は次のページに書かれています。

https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-OTelEnrichment.html

EnableTagEnrichment を省略すると、課金対象の resource tag enrichment が有効になります。Basic だけにするには、--no-enable-tag-enrichment で false を明示します。

aws cloudwatch start-otel-enrichment --no-enable-tag-enrichment
{
    "CreatedAt": "2026-11-28T04:33:36.710000+00:00",
    "UpdatedAt": "2026-11-28T04:33:36.710000+00:00",
    "EnableTagEnrichment": false
}

直後に get-otel-enrichment で状態を確認しました。

aws cloudwatch get-otel-enrichment
{
    "Status": "Running",
    "CreatedAt": "2026-11-28T04:33:36.710000+00:00",
    "UpdatedAt": "2026-11-28T04:33:36.710000+00:00",
    "EnableTagEnrichment": false
}

今回は、有効化の約3分半後に PromQL で値を確認できました。

PromQL の問い合わせ

PromQL の HTTP API のエンドポイントと SigV4 署名は、次の記事で説明しています。

https://dev.classmethod.jp/articles/cloudwatch-otel-metrics-ga-otlp-promql/

API は、curl の --aws-sigv4 を使った次のスクリプトで呼び出しました。promql-query というファイル名で保存し、実行権限を付けています。一時認証情報を、AWS_ACCESS_KEY_ID、AWS_SECRET_ACCESS_KEY、AWS_SESSION_TOKEN の3つの環境変数で渡します。

promql-query
#!/usr/bin/env bash
# CloudWatch の Prometheus 互換 HTTP API を SigV4 署名付きで呼ぶ。
# 使い方: promql-query <operation> [curl の --data-urlencode 引数...]
#   例: promql-query query 'query=Invocations{FunctionName="otel-enrich-verify-fn"}'
# 認証情報は環境変数(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN)から読む。
set -euo pipefail
op="$1"; shift
region="${AWS_REGION:-ap-northeast-1}"
args=()
for kv in "$@"; do args+=(--data-urlencode "$kv"); done
exec curl -sS --fail-with-body -X POST \
  --aws-sigv4 "aws:amz:${region}:monitoring" \
  --user "${AWS_ACCESS_KEY_ID}:${AWS_SECRET_ACCESS_KEY}" \
  -H "x-amz-security-token: ${AWS_SESSION_TOKEN}" \
  "${args[@]}" \
  "https://monitoring.${region}.amazonaws.com/api/v1/${op}"

Lambda の Invocations は、次のどちらの形式でも取得できました。

./promql-query query 'query={"Invocations", FunctionName="otel-enrich-verify-fn"}'
./promql-query query 'query=Invocations{FunctionName="otel-enrich-verify-fn"}'

1つ目の問い合わせの応答は次のとおりです。系列は1本でした。

{
  "status": "success",
  "data": {
    "resultType": "vector",
    "result": [
      {
        "metric": {
          "@aws.account": "123456789012",
          "@aws.region": "ap-northeast-1",
          "@instrumentation.@name": "cloudwatch.aws/lambda",
          "@instrumentation.cloudwatch.solution": "CloudWatchOTelEnrichment",
          "@instrumentation.cloudwatch.source": "aws.lambda",
          "@resource.cloud.account.id": "123456789012",
          "@resource.cloud.provider": "aws",
          "@resource.cloud.region": "ap-northeast-1",
          "@resource.cloud.resource_id": "arn:aws:lambda:ap-northeast-1:123456789012:function:otel-enrich-verify-fn",
          "FunctionName": "otel-enrich-verify-fn",
          "Resource": "otel-enrich-verify-fn",
          "__monotonicity__": "true",
          "__name__": "Invocations",
          "__temporality__": "delta",
          "__type__": "Sum",
          "__unit__": "{count}"
        },
        "value": [1795840731.761, "1"]
      }
    ]
  }
}

系列に付くラベル

系列に付いたラベルは、次の区分に分かれます。

区分 ラベル
元のディメンション FunctionName、Resource
リソース属性 @resource.cloud.resource_id(ARN)、@resource.cloud.provider、@resource.cloud.region、@resource.cloud.account.id
インストルメンテーションスコープ @instrumentation.@name、@instrumentation.cloudwatch.source、@instrumentation.cloudwatch.solution
取り込み先を示すシステムラベル @aws.account、@aws.region
系列の属性 __name__、__type__、__temporality__、__unit__、__monotonicity__

リソースタグのラベル(@aws.tag.*)が付くのは、resource tag enrichment を有効にした場合です。タグを使った絞り込みと集計は、次の記事で検証しています。

https://dev.classmethod.jp/articles/cloudwatch-otel-vended-metric-enrichment-promql/

従来 API との比較

同じ Lambda の Invocations を、従来の get-metric-statistics と、PromQL の範囲セレクタで取得して分ごとに並べました。範囲セレクタを使うと、分ごとの生のサンプルを取得できます。

aws cloudwatch get-metric-statistics --namespace AWS/Lambda --metric-name Invocations --dimensions Name=FunctionName,Value=otel-enrich-verify-fn --start-time 2026-11-28T13:30:00+09:00 --end-time 2026-11-28T13:55:00+09:00 --period 60 --statistics Sum SampleCount --output json
./promql-query query 'query={"Invocations", FunctionName="otel-enrich-verify-fn"}[30m]'

次の表は、取得結果のうち、Lambda 関数を 13:37:05 に1回、13:43:02〜13:43:04 に5回呼び出した分を抜粋したものです。

分(JST) 呼び出し回数 get-metric-statistics の Sum PromQL のサンプル
13:37 1 1 1
13:43 5 5 5

3つの値は、どちらの分でも一致しました。

従来 API には、ディメンションが FunctionName だけのメトリクスと、FunctionName と Resource を持つメトリクスの2つがあります。PromQL で取得できたのは、Resource を持つほうです。

まとめ

OTel メトリクスのネイティブサポートは2026年6月に GA 済みでしたが、AWS サービスのメトリクスを PromQL で使う場合、resource tag enrichment(EnableTagEnrichment が true)を省くことはできず、取り込みに1GB あたり $0.50 の費用がかかりました。

今回のアップデートで、課金対象の resource tag enrichment を省いた Basic enrichment を選べるようになり、AWS サービスのメトリクスを、取り込みの費用なしで PromQL から使えるようになりました。

PromQL は、従来の Classic メトリクスと比べて柔軟にクエリを書くことができ、30 日幅のクエリに対応するなど進化が続いています。

https://dev.classmethod.jp/articles/cloudwatch-promql-30day-query-window/

リソースの増減が少なく、タグを利用する必要性が低い環境で、PromQL を使ったアラームやダッシュボードを整理したい場合は、Basic enrichment を試してみてください。

この記事をシェアする

AWSのお困り事はクラスメソッドへ

関連記事