すべてのプロダクト
Search
ドキュメントセンター

Simple Log Service:KubernetesクラスターにOpenTelemetry自動インストルメンテーションを実装するにはどうすればよいですか?

最終更新日:Mar 14, 2025

このトピックでは、トレースデータをSimple Log Serviceにアップロードするために、KubernetesクラスターにOpenTelemetry自動インストルメンテーションを実装する方法について説明します。

手順

  1. Kubernetesクラスターにログインします。

  2. 次のコマンドを実行してcert-managerをインストールします。

    kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.9.1/cert-manager.yaml
  3. 次のコマンドを実行してOpenTelemetry Operatorをインストールします。

    kubectl apply -f https://github.com/open-telemetry/opentelemetry-operator/releases/latest/download/opentelemetry-operator.yaml

    opentelemetry-operator.yaml構成ファイルは、ghcr.ioのイメージアドレスを指定します。 中国のアドレスにアクセスすると、遅いアクセスまたはエラーが発生する可能性があります。 イメージアクセスを高速化するには、opentelemetry-operator.yaml設定ファイルのアドレスを変更します。 たとえば、Simple Log Serviceが提供するアドレスを使用して画像にアクセスできます。

    h otel-image-mirror-registry.cn-beijing.cr.aliyuncs.comでghcr.ioのイメージアドレスを置き換えます。

    説明

    Simple Log Serviceは、イメージを高速化するために、中国 (北京) および中国 (杭州) リージョンの次のアドレスをサポートしています。d otel-image-mirror-registry.cn-hangzhou.cr.aliyuncs.comをotel-image-mirror-registry.cn-beijing.cr.aliyuncs.comします。

  4. 次のコマンドを実行してOpenTelemetry Collectorをインストールします。

    kubectl apply -f - <<EOF
    apiVersion: opentelemetry.io/v1alpha1
    kind: OpenTelemetryCollector
    metadata:
      name: otel
    spec:
      image: otel/opentelemetry-collector-contrib:latest
      config: |
        receivers:
          otlp:
            protocols:
              grpc:
              http:
        exporters:
          alibabacloud_logservice/logs:
            endpoint: "cn-hangzhou.log.aliyuncs.com"
            project: "demo-project"
            logstore: "store-logs"
            access_key_id: "access-key-id"
            access_key_secret: "access-key-secret"
          alibabacloud_logservice/metrics:
            endpoint: "cn-hangzhou.log.aliyuncs.com"
            project: "demo-project"
            logstore: "store-traces-metrics"
            access_key_id: "access-key-id"
            access_key_secret: "access-key-secret"
          alibabacloud_logservice/traces:
            endpoint: "cn-hangzhou.log.aliyuncs.com"
            project: "demo-project"
            logstore: "store-traces"
            access_key_id: "access-key-id"
            access_key_secret: "access-key-secret"
    
        service:
          pipelines:
            traces:
              receivers: [otlp]
              exporters: [alibabacloud_logservice/traces]
            logs:
              receivers: [otlp]
              exporters: [alibabacloud_logservice/logs]
            metrics:
              receivers: [otlp]
              exporters: [alibabacloud_logservice/metrics]
    EOF

    コマンドのパラメーターについて、次の表に説明します。 ビジネス要件に基づいてパラメーターを変更できます。

    パラメーター

    説明

    エンドポイント

    Simple Log Serviceエンドポイント。 例: cn-hangzhou.log.aliyuncs.com。 詳細については、「エンドポイント」をご参照ください。

    project

    トレースインスタンスを作成するときに指定するプロジェクトの名前。 詳細については、「トレースインスタンスの作成」をご参照ください。

    logstore

    ログストアの名前 トレースインスタンスを作成すると、Simple Log Serviceは、ログデータ、メトリックデータ、およびトレースデータを格納するために、指定されたプロジェクトに3つのログストアを生成します。 ビジネス要件に基づいてLogstore名を指定します。

    • trace_instance_id -logs

    • trace_instance_id -traces-metrics

    • trace_instance_id -トレース

    trace_instance_idは、トレースインスタンスのidを指定します。 ビジネス要件に基づいて、trace_instance_idを置き換えることができます。 詳細については、「トレースインスタンスの作成」をご参照ください。

    access_key_id

    Simple Log Serviceへのアクセスに使用されるAccessKey ID。 詳細は、「AccessKeyペア」をご参照ください。

    access_key_secret

    Simple Log Serviceへのアクセスに使用されるAccessKeyシークレット。 詳細は、「AcessKeyペア」をご参照ください。

  5. 次のコマンドを実行してOpenTelemetry Auto-Instrumentationをインストールします。

    kubectl apply -f - <<EOF
    apiVersion: opentelemetry.io/v1alpha1
    kind: Instrumentation
    metadata:
      name: my-java-instrumentation
    spec:
      exporter:
        endpoint: http://otel-collector:4317
      propagators:
        - tracecontext
        - baggage
        - b3
      java:
        image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:latest
      nodejs:
        image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-nodejs:latest
      python:
        image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-python:latest
        env:
          - name: OTEL_EXPORTER_OTLP_ENDPOINT
            value: http://otel-collector:4318
      dotnet:
        image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-dotnet:latest
        env:
          - name: OTEL_EXPORTER_OTLP_ENDPOINT
            value: http://otel-collector:4318
      apacheHttpd:
        image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-apache-httpd:latest
    EOF
    • Java、Node.js、Pythonなどのさまざまなプログラミング言語のアプリケーション用。NETでは、ビジネス要件に基づいてAuto-Instrumentationを構成します。

    • ghcrのイメージアドレスをSimple Log Serviceが提供するイメージアドレスに置き換えて、中国のアドレスにアクセスすると、遅いアクセスまたはエラーが発生する可能性があります。 たとえば、h otel-image-mirror-registry.cn-beijing.cr.aliyuncs.comのghcr.ioでイメージアドレスを置き換えることで、イメージを高速化できます。

    説明

    Simple Log Serviceは、イメージを高速化するために、中国 (北京) および中国 (杭州) リージョンの次のアドレスをサポートしています。d otel-image-mirror-registry.cn-hangzhou.cr.aliyuncs.comをotel-image-mirror-registry.cn-beijing.cr.aliyuncs.comします。

  6. 自動インストルメンテーションの構成を構成ファイルに追加します。

    ビジネス要件に基づいて、アプリケーションの構成ファイルに構成スクリプトを追加します。 Python、Node.js、Java、および. NETアプリケーションがサポートされています。

    重要

    次のコードでは、my-java-instrumentationは、前の手順でインストールしたAuto-Instrumentationの名前です。 Auto-Instrumentation名は、metadata.nameパラメーターの値です。 ビジネス要件に基づいて名前を変更できます。

    image.png

    • Java

      instrumentation.opentelemetry.io/inject-java: "my-java-instrumentation"
    • Python

      instrumentation.opentelemetry.io/inject-python: "my-java-instrumentation"
    • Node.js

      instrumentation.opentelemetry.io/inject-nodejs: "my-java-instrumentation"
    • dotNET

      instrumentation.opentelemetry.io/inject-dotnet: "my-java-instrumentation"