このドキュメントでは、既存のエクスポーター(この場合は
googlecloudロギング エクスポーター)を使用する OpenTelemetry Collector ロギング構成を変更して、OTLP エクスポーターと
Telemetry(OTLP)API、telemetry.googleapis.comを使用する方法について説明します。
Telemetry API を有効にする
OTLP エクスポーターは Telemetry API に書き込むため、プロジェクトでその API を有効にする必要があります。次のコマンドを実行して Telemetry API を有効にします。
gcloud services enable telemetry.googleapis.com
置き換えるエクスポーターを見つける
構成ファイルで、ロギングの exporters エントリを見つけます。構成は次のようになります。
exporters:
googlecloud/logging:
googlecloud/logging エクスポーターを置き換えて、googleauthclient 拡張機能を追加します。
exporters:
otlp_grpc/otlp_logs:
auth:
authenticator: googleclientauth
balancer_name: pick_first
endpoint: telemetry.googleapis.com:443
extensions:
googleclientauth: {}
プロセッサを追加する
構成ファイルで、processors エントリを見つけます。構成は次のようになります。
processors:
resourcedetection/_global_0: [...details omitted...]
transform/mylog__source_0: [...details omitted...]
次の各プロセッサの構成をコピーして、構成ファイルに貼り付けます。
プロジェクトに関する情報をキャプチャする
resourceプロセッサ。 Google Cloudresource/gcp_project_id: attributes: - action: insert value: PROJECT_ID key: gcp.project_id計測ソースに関する情報を保持する
transformプロセッサ。transform/otlp_grpc/preserve_instrumentation_source_version: error_mode: ignore log_statements: - context: log statements: - set(attributes["instrumentation_source"], instrumentation_scope.name) where instrumentation_scope.name != "" - set(attributes["instrumentation_version"], instrumentation_scope.version) where instrumentation_scope.version != ""リソース属性に関する情報を保持する
transformプロセッサ。transform/otlp_grpc/preserve_service_resource_attributes: error_mode: ignore log_statements: - context: log statements: - set(attributes["service.name"], resource.attributes["service.name"]) where resource.attributes["service.name"] != nil - set(attributes["service.namespace"], resource.attributes["service.namespace"]) where resource.attributes["service.namespace"] != nil - set(attributes["service.instance.id"], resource.attributes["service.instance.id"]) where resource.attributes["service.instance.id"] != nil
変更後の構成は次のようになります。
processors:
resourcedetection/_global_0: [...details omitted...]
transform/mylog__source_0: [...details omitted...]
resource/gcp_project_id: [...details omitted...]
transform/otlp_grpc/preserve_instrumentation_source_version: [...details omitted...]
transform/otlp_grpc/preserve_service_resource_attributes: [...details omitted...]
ロギング サービスとパイプラインを変更する
構成で、ロギングに使用される service を見つけます。これには、googlecloud/logging エクスポーターを使用する pipeline が含まれます。構成は次のようになります。
service:
pipelines:
logs/logs_my__pipeline_mylog__source:
exporters:
- googlecloud/logging
processors:
- transform/mylog__source_0
- resourcedetection/_global_0
receivers:
- tcplog
この構成に次の変更を加えます。
googleclientauth拡張機能をserviceエントリに追加します。- パイプラインのエクスポーターを
otlp_grpc/otlp_logsに変更します。 - 新しいプロセッサをパイプラインのプロセッサ リストに追加します。
resource/gcp_project_idtransform/otlp_grpc/preserve_instrumentation_source_versiontransform/otlp_grpc/preserve_service_resource_attributes
変更後の構成は次のようになります。
service:
extensions:
- googleclientauth
pipelines:
logs/logs_my__pipeline_mylog__source:
exporters:
- otlp_grpc/otlp_logs
processors:
- transform/mylog__source_0
- resourcedetection/_global_0
- resource/gcp_project_id
- transform/otlp_grpc/preserve_instrumentation_source_version
- transform/otlp_grpc/preserve_service_resource_attributes
receivers:
- tcplog
必要に応じてダッシュボードとアラート ポリシーを移行する
Cloud Logging API の使用状況を追跡するグラフまたはアラート ポリシーがある場合は、Telemetry API の使用状況をモニタリングするように更新します。OTLP エクスポーターは、Cloud Logging API ではなく Telemetry API を使用して、 プロジェクトにログを送信します。 Google Cloud