Docker での Single Step APM インスツルメンテーション
概要
Docker Linux コンテナ上では、APM 用の Single Step Instrumentation (SSI) を使用して Datadog Agent をインストールし、1 ステップで アプリケーションをインスツルメンテーション します。追加の構成は不要です。
エージェントを使用して APM をセットアップする
Install the dd-apm skill in your AI coding agent for guided APM setup.
npx skills add https://github.com/datadog-labs/agent-skills --skill dd-apm --full-depth -y
アプリケーションで APM を有効にする
Docker Linux 環境で Datadog Agent をインストールし SSI を有効にするには、Docker ホスト上で (アプリケーションコンテナ内ではなく) 以下のコマンドを実行します。
ホスト Agent をインストールせずに Docker インスツルメンテーションコンポーネントをインストールする:
DD_APM_INSTRUMENTATION_ENABLED=docker \
DD_NO_AGENT_INSTALL=true \
bash -c "$(curl -L https://install.datadoghq.com/scripts/install_script_agent7.sh)"
Agent コンテナを実行または再デプロイします。<YOUR_DD_API_KEY> をご使用の Datadog API キー に置き換えます:
docker run -d --name dd-agent \
-e DD_API_KEY=<YOUR_DD_API_KEY> \
-e DD_SITE="" \
-e DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true \
-e DD_APM_ENABLED=true \
-e DD_APM_NON_LOCAL_TRAFFIC=true \
-e DD_APM_RECEIVER_SOCKET=/var/run/datadog/apm.socket \
-e DD_DOGSTATSD_SOCKET=/var/run/datadog/dsd.socket \
-v /var/run/datadog:/var/run/datadog \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v /proc/:/host/proc/:ro \
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
-v /var/lib/docker/containers:/var/lib/docker/containers:ro \
registry.datadoghq.com/agent:7
Note: Run only one Datadog Agent per node. If a Datadog Agent container already exists, update its definition (or your Docker Compose file) with these settings and recreate it, rather than starting a second Agent. For rootless Docker, set the correct Docker socket in docker_config.yaml.
Recreate your application containers.
Instrumentation is applied when a container is created, so restarting an existing container with docker stop and docker start does not instrument it. Remove your application containers and run them again.
SSI adds a small amount of startup time to instrumented applications. If this overhead is not acceptable for your use case, contact
Datadog Support.
Generate the command from Datadog
To get a command pre-filled with your API key and site, go to the Install the Datadog Agent on Docker page. In the Customize my agent install command section, go to Additional configuration > Application Observability, and turn on APM Instrumentation. Then copy and run the generated command.
SDK トレーサーのバージョンを設定する
デフォルトでは、Single Step Instrumentation は Datadog SDK の最新メジャーバージョンをインストールし、マイナーアップデートが利用可能になると自動的に適用します。
特定のバージョンに固定するには、コンポーネントのインストールコマンドに、カンマ区切りの language:major ペアを指定した DD_APM_INSTRUMENTATION_LIBRARIES 変数を追加します。利用可能なバージョンは、各言語のソースリポジトリに一覧があります。
Datadog のドロップダウンからバージョンを選択することもできます。Docker への Datadog Agent のインストール ページで、APM Instrumentation をオンにした後、Customize library versions をクリックします。
インストールの検証
Docker デーモンが Datadog ランタイムを使用していることを確認します:
docker system info --format '{{.DefaultRuntime}}'
The output must be dd-shim. If it is runc or anything else, the instrumentation components did not install successfully, and your applications are not instrumented regardless of whether the Agent is healthy. Re-run the installation command, and confirm that the Docker daemon was running when you ran it.
Confirm the Agent container is running:
docker ps --filter name=dd-agent
Agent が正常であり、APM Agent が稼働していることを確認します:
docker exec dd-agent agent status
出力の APM Agent セクションをチェックします。
アプリケーションコンテナが Datadog ランタイムを使用していることを確認します。<CONTAINER_NAME> をアプリケーションコンテナのいずれかの名前に置き換えます:
docker inspect <CONTAINER_NAME> --format '{{.HostConfig.Runtime}}'
After your applications receive traffic, confirm your services appear on the APM Services page. If they don’t appear within a few minutes, follow the SSI troubleshooting guide.
Unified Service Tags (USTs) apply consistent tags across traces, metrics, and logs, making it easier to navigate and correlate your observability data. Learn how to set USTs for Docker services.
Enable SDK-dependent products and features
After SSI loads the Datadog SDK into your applications and enables distributed tracing, you can configure additional products that rely on the SDK:
Note: All variables accept true or false. DD_PROFILING_ENABLED also accepts auto, which profiles only eligible processes and is recommended for SSI.
製品を有効にするには、アプリケーション構成で 環境変数を設定 してください。
シングルステップ APM インスツルメンテーションを Agent から削除する
特定のサービス、ホスト、VM、またはコンテナでトレースデータを収集したくない場合は、以下の手順を実行してください。
特定のサービスのインスツルメンテーションを削除する
特定のサービスの APM インスツルメンテーションを削除してトレース送信を停止する場合は:
DD_INSTRUMENT_SERVICE_WITH_APM 環境変数をサービス起動コマンドに追加します:docker run -e DD_INSTRUMENT_SERVICE_WITH_APM=false <service_start_command>
- サービスを再起動します。
インフラストラクチャー上のすべてのサービスについて APM を削除する
トレースの送信を停止するには、APM をアンインストールしてインフラストラクチャーを再起動してください:
- 次を実行します。
dd-container-install --uninstall
- Docker を再起動します。または、環境に応じたコマンドを使用してください。
トラブルシューティング
SSI で APM を有効にする際に問題が発生した場合は、SSI トラブルシューティングガイド を参照してください。
参考資料