OpenTelemetry のログとサービスの関連付け

Instana (OTEL) OpenTelemetry のログ処理パイプラインは、インフラストラクチャエンティティから派生したサービスとの相関分析をサポートしています。 サービスの定義方法の詳細については、 「サービス」 を参照してください。

ログへのサービス名の割り当て

OpenTelemetry Collectorのデプロイ設定に応じて、ログとサービスを関連付けるために、属 service.name 性を次のように設定できます:

OpenTelemetry Collectorのスタンドアロン展開

OpenTelemetry コレクターをスタンドアロン実行ファイルまたはサービスとして展開し、 Linux のシステムログWindows のイベントログを監視する場合、ログとサービスを関連付けるために、各ログレコードにサービス名を手動で割り当てる必要があります。

以下の例のように、属性を service.name 追加できます:

processors:
  transform/enrich_with_service_name:
    error_mode: ignore
    log_statements:
      - context: log
        statements:
          ## Set a "service.name" resource attribute only if the log record is from a specific file.
          ## Example checking the exact file path.
          - set(attributes["service.name"], "My Service 1") where attributes["log.file.path"] == "/path/to/service-1.log"
          ## Example using a regular expression to match a file path.
          - set(attributes["service.name"], "My Service 2") where IsMatch(attributes["log.file.path"], ".*(service-2-dir-name).*")
          ## Example using a custom-defined environment variable with a regex condition on the file path.
          ## Note: This example assumes that the environment variable MY_OTEL_SERVICE_NAME is contains
          ##       the desired service name. You may use any environment variable for this purpose.
          - set(attributes["service.name"], "${env:MY_OTEL_SERVICE_NAME}") where IsMatch(attributes["log.file.path"], ".*(some-otel-service-name).*")
          ## Example using the log path to set the service name dynamically using a named capture group in the regex
          ## to extract the project name as the "service_name" for multiple services with "projects" in their file path.
          - set(attributes["service.name"], ExtractPatterns(attributes["log.file.path"], ".*/projects/(?P<service_name>[^/]+)")["service_name"]) where IsMatch(attributes["log.file.path"], ".*(projects).*")
[...]
service:
  pipelines:
    logs:
      processors:
        # Add other processors here.
        - transform/enrich_with_service_name
        # Always recommended to batch log records.
        - batch

OpenTelemetry Kubernetes におけるコレクターのデプロイ

OpenTelemetry コレクターを使用して Kubernetes サービスを監視する場合、 Kubernetes のPod構成やメタデータフィールドを抽出するプロセッサを使用することで k8sattributes 、各ログレコードに属性を service.name 追加できます。

「 Helm 」チャートを使用して OpenTelemetry コレクターをインストールすると、ファイル opentelemetry-collector/templates/_config.tpl 内の事前 k8sattributes 設定済みのプロセッサを利用できるようになります。

いずれの場合も、サービス相関を有効にするために、プロセッサの設定 k8sattributes にこの service.name フィールドが含まれていることを確認してください:

processors:
  k8sattributes:
    extract:
      metadata:
        ## Here add any additional metadata you want to extract from the k8s environment.
        ## For the full list of supported attributes: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/k8sattributesprocessor/README.md
        - "service.name"  ## Allows logs to be correlated to specific services by Instana.
        - "k8s.pod.uid"   ## If container.id is unavailable, logs are correlated to a specific Kubernetes pod.
        - "container.id"  ## If this field is available, logs are correlated to specific containers in a Kubernetes pod.
[...]
service:
  pipelines:
    logs:
      processors:
        # Add other processors here.
        - k8sattributes
        # Always recommended to batch log records.
        - batch

Instana UI におけるサービスの相関関係

この service.name 値は、サービスに関するドキュメントで定義されている対応するサービス名と一致している必要があります。 正しく設定されている場合、サービス名は Instana のUI上で、対応するサービスページへのハイパーリンクとして表示されます。

次の例は、相関付けされていないサービス名を示しているため、 Instana のUI上ではプレーンテキストの名前として表示されます:

サービスの相関関係が無効になっています

次の例は、対応する「status-refresh-manager-svc」サービスページにリンクされたサービス名を示しています:

サービスの相関分析が有効になっています

ハイパーリンクをクリックすると、サービスページが開きます:

サービスページ

Instana UI でのログのフィルタリングとグループ化

Instana のUIでは、サービス名を使用してログのフィルタリングやグループ化を行うことができます。

次の例は、サービス名でログをフィルタリングする方法を示しています:

サービスの相関関係の例 - フィルタリング

次の例は、サービス名ごとにログをグループ化する方法を示しています:

サービスの相関関係の例 - グループ化