

# Amazon CloudWatch エージェント
<a name="CloudWatch-OTLPCloudWatchAgent"></a>

CloudWatch エージェントは OpenTelemetry Collector 上に構築されているため、これを使用して OpenTelemetry データを受信し、CloudWatch OTLP エンドポイントに送信できます。多くのお客様にとって、これが OpenTelemetry テレメトリを CloudWatch に送信する場合の推奨方法になります。その理由は、単一のエージェントで、キュレーションされたエクスペリエンス (CloudWatch Application Signals や CloudWatch Enhanced Container Insights など) を強化できるためです。

現時点で、エージェントを介して OpenTelemetry データを送信するには、YAML 形式で OpenTelemetry コレクター設定を指定し、それをエージェント独自の設定に追加する必要があります。CloudWatch エージェント設定ファイルでエージェントを起動し、OpenTelemetry YAML ファイルを追加します。

```
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -c file:/tmp/agent.json -s
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a append-config -c file:{{/tmp/otel.yaml}} -s
```

エージェントは起動時に 2 つの設定をマージし、解決された設定をログ記録します。エージェントが自動的に作成するパイプラインとのマージ競合を回避するには、OpenTelemetry YAML 内の各コンポーネントおよびパイプラインの名前にカスタムサフィックスを追加します (例: `otlphttp/cwagent`)。

## サポートされている OpenTelemetry コンポーネント
<a name="CloudWatch-OTLPCloudWatchAgent-Components"></a>

次の OpenTelemetry コンポーネントは、追加した YAML 設定で設定できます。ここに示すコンポーネントタイプ名を YAML のキーとして使用します。


| コンポーネントタイプ | 使用可能なコンポーネント | 
| --- | --- | 
| レシーバー | `otlp`, `prometheus`, `statsd`, `collectd`, `jmx`, `hostmetrics`, `filelog`, `tcplog`, `udplog`, `jaeger`, `zipkin`, `kafka`, `kubeletstats` | 
| Processors | `batch`, `memory_limiter`, `filter`, `attributes`, `resource`, `resourcedetection`, `metricstransform`, `transform`, `cumulativetodelta`, `deltatocumulative`, `deltatorate`, `groupbyattrs`, `groupbytrace`, `k8sattributes`, `metricsgeneration`, `metricstarttime`, `probabilistic_sampler`, `span`, `tail_sampling` | 
| エクスポーター | `otlphttp`, `awsemf`, `awscloudwatchlogs`, `awsxray`, `prometheusremotewrite`, `debug` | 
| 拡張子 | `sigv4auth`, `headers_setter`, `file_storage`, `health_check`, `pprof`, `zpages` | 

CloudWatch エージェントは、テレメトリの AWS 送信先への書き込みのみをサポートします。

## 設定例
<a name="CloudWatch-OTLPCloudWatchAgent-Examples"></a>

次の例では、`otlphttp` エクスポーターと `sigv4auth` 拡張機能を使用して、各シグナルを対応する CloudWatch OTLP エンドポイントに送信します。各コンポーネントおよびパイプラインの名前には `/cwagent` サフィックスを使用し、エージェントが自動的に作成するパイプラインとの競合を回避します。{{Region}} を、お使いの AWS リージョンに置き換えます。

**メトリクス**

```
receivers:
  otlp/cwagent:
    protocols:
      http:
        endpoint: 0.0.0.0:4318
processors:
  batch/cwagent: {}
exporters:
  otlphttp/cwagent:
    metrics_endpoint: https://monitoring.{{region}}.amazonaws.com/v1/metrics
    auth:
      authenticator: sigv4auth/cwagent
extensions:
  sigv4auth/cwagent:
    region: "{{region}}"
    service: "monitoring"
service:
  extensions: [sigv4auth/cwagent]
  pipelines:
    metrics/cwagent:
      receivers: [otlp/cwagent]
      processors: [batch/cwagent]
      exporters: [otlphttp/cwagent]
```

**ログ**

```
receivers:
  otlp/cwagent:
    protocols:
      http:
        endpoint: 0.0.0.0:4318
exporters:
  otlphttp/cwagent:
    logs_endpoint: https://logs.{{region}}.amazonaws.com/v1/logs
    headers:
      x-aws-log-group: {{my-log-group}}
      x-aws-log-stream: default
    auth:
      authenticator: sigv4auth/cwagent
extensions:
  sigv4auth/cwagent:
    region: "{{region}}"
    service: "logs"
service:
  extensions: [sigv4auth/cwagent]
  pipelines:
    logs/cwagent:
      receivers: [otlp/cwagent]
      exporters: [otlphttp/cwagent]
```

**トレース**

```
receivers:
  otlp/cwagent:
    protocols:
      http:
        endpoint: 0.0.0.0:4318
exporters:
  otlphttp/cwagent:
    traces_endpoint: https://xray.{{region}}.amazonaws.com/v1/traces
    auth:
      authenticator: sigv4auth/cwagent
extensions:
  sigv4auth/cwagent:
    region: "{{region}}"
    service: "xray"
service:
  extensions: [sigv4auth/cwagent]
  pipelines:
    traces/cwagent:
      receivers: [otlp/cwagent]
      exporters: [otlphttp/cwagent]
```

**注記**  
トレースを OTLP トレースエンドポイントに送信する前に、トランザクション検索が有効になっていることを確認します。