コンテンツにスキップ

設定ファイル@OpenTelemetry Collector

はじめに

本サイトにつきまして、以下をご認識のほど宜しくお願いいたします。


01. 共通

タイプ

▼ タイプとは

設定名のこと。

各コンポーネントで、タイプ/<任意の文字列>でテレメトリーの処理方法を設定する。

receivers:
  <タイプ>/foo:
    ...
  <タイプ>/bar:
    ...

processors:
  <タイプ>/foo:
    ...
  <タイプ>/bar:
    ...

exporters:
  <タイプ>/foo:
    ...
  <タイプ>/bar:
    ...

service:
  pipelines:
    metrics:
      receivers:
        - <タイプ>/foo
        - <タイプ>/bar
      processors:
        - <タイプ>/foo
        - <タイプ>/bar
      exporters:
        - <タイプ>/foo
        - <タイプ>/bar
    ...

タイプは、コア機能と拡張機能から選べる。

▼ 同じタイプの複数定義

タイプさえ正しければ問題なく、同じタイプを複数設定できる。

例えば、exportersの宛先が冗長化されている場合、同じタイプ名で複数の宛先を設定することになる。

exporters:
  prometheusremotewrite/1:
    endpoint: <宛先>
  prometheusremotewrite/2:
    endpoint: <宛先>

service:
  pipelines:
    metrics:
      exporters:
        - prometheusremotewrite/1
        - prometheusremotewrite/2


tls

▼ cert_file

SSL証明書やクライアント証明書を設定する。

receivers:
  <タイプ>:
    tls:
      cert_file: server.crt

exporters:
  <タイプ>:
    tls:
      cert_file: client.crt

▼ insecure

TLSを有効化するかどうかを設定する。

receivers:
  <タイプ>:
    tls:
      insecure: true

exporters:
  <タイプ>:
    tls:
      insecure: true

▼ key_file

SSL証明書やクライアント証明書に紐づく秘密鍵を設定する。

receivers:
  <タイプ>:
    tls:
      key_file: server.key

exporters:
  <タイプ>:
    tls:
      key_file: client.key


02. exporters

exportersとは

Exporterを設定する。

OpenTelemetry Collectorは、設定した監視バックエンドにテレメトリーを送信する。


awsxray

▼ awsxrayとは

X-Rayにスパンを送信する。

ただし、OpenTelemetryにはAWS X-Ray exporterが含まれていない。

そのため、AWS製のコンテナイメージ (public.ecr.aws/aws-observability/aws-otel-collector) に差し替えておく必要がある。

▼ index_all_attributes

スパンの属性をAWS X-Rayのアノテーションに変換する。

AWS X-Rayでは、アノテーションでフィルタリングできるが、メタデータではできない。

OpenTelemetryのスパンをAWS X-Rayに送信すると、AWS X-Ray上で属性はメタデータになる。

そこで、属性をフィルタリング可能なアノテーションに変換する

exporters:
  awsxray:
    index_all_attributes: true

▼ no_verify_ssl

X-Rayへの通信でTLSを有効化するか否かを設定する。

exporters:
  awsxray:
    no_verify_ssl: true

▼ region

X-Rayのあるリージョンを設定する。

exporters:
  awsxray:
    region: ap-northeast-1


debug

▼ debugとは

標準エラー出力にテレメトリーを出力する。

▼ verbosity

重要度レベルを設定する。

通常レベルはbasicである。

exporters:
  debug:
    verbosity: basic
2024-03-26T04:41:52.163Z    info    TracesExporter  {"kind": "exporter", "data_type": "traces", "name": "debug", "resource spans": 1, "spans": <転送したスパン数>}

スパンを標準出力により詳細に出力したい場合、detailedとする。

exporters:
  debug:
    verbosity: detailed
# スパン一つ当たりの内容
2024-03-26T04:19:41.450Z    info    ResourceSpans #0
Resource SchemaURL:
Resource attributes:
     -> service.name: Str(foo-service)
ScopeSpans #0
ScopeSpans SchemaURL:
InstrumentationScope "<トレースパッケージ名>"
Span #0
    Trace ID       : *****
    Parent ID      :
    ID             : *****
    Name           : "<スパン名>"
    Kind           : Server
    Start time     : 2024-03-26 04:19:41.041 +0000 UTC
    End time       : 2024-03-26 04:19:41.085 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> http.method: Str(GET)
     -> http.target: Str("<スパン名>")
     -> http.route: Str(/)
     -> http.scheme: Str(http)
     -> http.flavor: Str(1.1)
     -> http.user_agent: Str(curl/7.79.1)
     -> http.request_content_length: Int(0)
     -> http.response_content_length: Int(905)
     -> http.status_code: Int(200)
     -> net.host.name: Str(_)
     -> net.host.port: Int("<ポート番号>")
     -> net.sock.peer.addr: Str(127.0.0.6)
     -> net.sock.peer.port: Int("<ポート番号>")
     -> env: Str("<実行環境名>")
     -> service: Str("<サービス名>")
    {"kind": "exporter", "data_type": "traces", "name": "debug"}


googlecloud

Google Cloudリソース (例:CloudTrace、CloudLogging、CloudMonitoring) にテレメトリーを送信する。

OpenTelemetry Collectorに認証情報を紐づけていたとしても、ここでプロジェクト名を指定する必要がある。

exporters:
  googlecloud:
    project: foo-project
    trace:
      use_insecure: true


logging

これは非推奨である。

代わりに、debugを使用すること。

exporters:
  logging: {}


03. extensions

extensionとは

記入中...


health_check

extensions:
  health_check:
    endpoint: <PodのIPアドレス>:13133


04. processors

processorsとは

Processorを設定する


attribute

テレメトリーに付与する属性を設定する。

可読性が低くなるため、属性はアプリ側で実装した方が良い。

processors:
  attributes:
    actions:
      - key: env
        value: prd
        action: insert
      - key: service
        value: foo
        action: insert


batch

▼ batchとは

テレメトリーファイルを圧縮するバッチ処理を実行し、送信サイズを小さくした上でExporterに渡す。

推奨である。

▼ timeout

processors:
  batch:
    timeout: 8192s

▼ send_batch_size

バッチ当たりの上限サイズを設定する。

0は上限なしを表す。

processors:
  batch:
    send_batch_size: 0


05. receivers

receiversとは

Receiverを設定する。

OpenTelemetryのクライアントは、Receiverを指定し、テレメトリーを送信する。


otlp

▼ otlpとは

OTLP形式でテレメトリーを受信する。

クライアントがHTTPクライアントかgRPCクライアントかによって、エンドポイントを使い分ける。

設定したエンドポイントに応じて、受信サーバーが起動する。

...

2024-03-14T03:06:00.860Z    info    otlpreceiver@v0.93.0/otlp.go:102    Starting GRPC server    {"kind": "receiver", "name": "otlp", "data_type": "traces", "endpoint": "<Pod (自分) のIPアドレス>:4317"}
2024-03-14T03:06:00.860Z    info    otlpreceiver@v0.93.0/otlp.go:152    Starting HTTP server    {"kind": "receiver", "name": "otlp", "data_type": "traces", "endpoint": "<Pod (自分) のIPアドレス>:4318"}

...

▼ http

HTTPで受信する。

テレメトリーごとにエンドポイント (/v1/logs/v1/metrics/v1/traces) が異なる。

receivers:
  otlp:
    protocols:
      http:
        endpoint: <Pod (自分) のIPアドレス>:4318

▼ grpc

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: <Pod (自分) のIPアドレス>:4317


06. service

extensions

使用したい拡張を指定する。

service:
  extensions:
    - health_check


pipelines

使用したい設定 (Receiver、Processor、Exporter) を指定する。

service:
  pipelines:
    traces:
      receivers:
        - otlp
      processors:
        - batch
      exporters:
        - awsxray


telemetry

▼ telemetryとは

OpenTelemetry Collector自体のテレメトリーの作成方法を設定する。

▼ logs

OpenTelemetry Collectorのログの作成方法を設定する。

service:
  telemetry:
    logs:
      # 通常ログの出力
      output_paths:
        - stdout
      # エラーログの出力先
      error_output_paths:
        - stderr
      # ログレベル (debug、info、warn、error)
      level: debug
      # ログに追加するフィールド
      initial_fields:
        service: foo

ログレベルがdebugの場合、例えば以下になる。

2024-03-25T03:22:08.220Z    debug   awsxrayexporter@v0.96.0/awsxray.go:57   TracesExporter  {"kind": "exporter", "data_type": "traces", "name": "awsxray", "type": "awsxray", "name": "awsxray", "#spans": 1}

▼ metrics

OpenTelemetry Collectorのメトリクスの作成方法を設定する。

service:
  telemetry:
    metrics:
      level: detailed
      # メトリクスのエンドポイント
      address: <PodのIPアドレス>:8888