概要

Datadog のソースコードインテグレーションを使って、テレメトリーを Git リポジトリと連携させ、関連するソースコード行にアクセスしてスタックトレースやスロープロファイルなどの問題をデバッグできます。

Java RuntimeException のインラインコードスニペットと GitHub でコードを見るためのボタン

セットアップ

Datadog Agent v7.35.0 以降が必要です。

APM をすでに設定している場合は、Integrations > Link Source Code に移動し、バックエンドサービスのソースコードインテグレーションを構成してください。

テレメトリーに Git 情報をタグ付け

テレメトリーには、実行中のアプリケーションのバージョンを特定のリポジトリやコミットと結びつける Git 情報をタグ付けする必要があります。

サポートされている言語については、Datadog はデプロイされたアーティファクトに Git 情報を埋め込むことを推奨しています。この情報は Datadog トレーシングライブラリによって自動的に抽出されます。

その他の言語や構成については、自身でテレメトリータギングを構成することができます。

ビルドアーティファクトに Git 情報を埋め込む

リポジトリの URL とコミットハッシュをビルドアーティファクトに埋め込むことができます。Datadog トレーシングライブラリはこの情報を使用して、APM サービスのテレメトリーに適切なタグを自動的に追加します。

git 情報の埋め込みに対応している言語を、次の中から 1 つ選択します。

Go クライアントライブラリのバージョン 1.48.0 以降が必要です。

コンテナ

Docker コンテナを使用している場合、Docker を使用する、Datadog トレーシングライブラリを使用する、または DD_GIT_* 環境変数でアプリケーションを構成するの 3 つのオプションがあります。

オプション 1: Docker
  1. Add the following lines to your application’s Dockerfile:

    ARG DD_GIT_REPOSITORY_URL
    ARG DD_GIT_COMMIT_SHA
    ENV DD_GIT_REPOSITORY_URL=${DD_GIT_REPOSITORY_URL} 
    ENV DD_GIT_COMMIT_SHA=${DD_GIT_COMMIT_SHA}
    
  2. Add the following arguments to your Docker build command:

    docker build . \
     -t my-application \
     --build-arg DD_GIT_REPOSITORY_URL=<git-provider.example/me/my-repo> \
     --build-arg DD_GIT_COMMIT_SHA=$(git rev-parse HEAD)
    
オプション 2: Datadog トレーシングライブラリ

Go embeds version control information in binaries since version 1.18. The Datadog tracing library uses this information to tag your telemetry with the latest commit SHA and repository URL.

Ensure your service meets the following requirements to use this approach:

  • Go version is 1.18 or later.
  • The service is built as a go module and the module path is your code’s repository URL.
オプション 3: DD_GIT_* 環境変数

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

サーバーレス

サーバーレスを使用している場合、サーバーレスアプリケーションのセットアップに応じて 3 つのオプションがあります。

オプション 1: Datadog ツール
Datadog CLI tool
Use the datadog-ci client version 2.4.1 or later. You must run the CLI tool in the same directory as the code repository.
Datadog Serverless Plugin
Use the plugin version 5.18.0 or later.
Datadog CDK Construct
Use the datadog-cdk-constructs version 0.8.5 or later for AWS CDK v1.
Use the datadog-cdk-constructs version 1.4.0 or later for AWS CDK v2.
オプション 2: Datadog トレーシングライブラリ

Go embeds version control information in binaries since version 1.18. The Datadog tracing library uses this information to tag your telemetry with the latest commit SHA and repository URL.

Ensure your service meets the following requirements to use this approach:

  • Go version is 1.18 or later.
  • The service is built as a go module and the module path is your code’s repository URL.
オプション 3: DD_GIT_* 環境変数

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

ホスト

ホストを使用している場合、2 つのオプションがあります。

オプション 1: Datadog トレーシングライブラリ

Go embeds version control information in binaries since version 1.18. The Datadog tracing library uses this information to tag your telemetry with the latest commit SHA and repository URL.

Ensure your service meets the following requirements to use this approach:

  • Go version is 1.18 or later.
  • The service is built as a go module and the module path is your code’s repository URL.
オプション 2: DD_GIT_* 環境変数

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

Python クライアントライブラリのバージョン 1.12.0 以降が必要です。

コンテナ

Docker コンテナを使用している場合、Docker を使用する、Datadog トレーシングライブラリを使用する、または DD_GIT_* 環境変数でアプリケーションを構成するの 3 つのオプションがあります。

オプション 1: Docker
  1. Add the following lines to your application’s Dockerfile:

    ARG DD_GIT_REPOSITORY_URL
    ARG DD_GIT_COMMIT_SHA
    ENV DD_GIT_REPOSITORY_URL=${DD_GIT_REPOSITORY_URL} 
    ENV DD_GIT_COMMIT_SHA=${DD_GIT_COMMIT_SHA}
    
  2. Add the following arguments to your Docker build command:

    docker build . \
     -t my-application \
     --build-arg DD_GIT_REPOSITORY_URL=<git-provider.example/me/my-repo> \
     --build-arg DD_GIT_COMMIT_SHA=$(git rev-parse HEAD)
    
オプション 2: Setuptools または Unified Python プロジェクト設定ファイル

If your application is packaged with setuptools:

  1. Install the dd-trace package.
  2. Add import ddtrace.sourcecode.setuptools_auto as the first import to the setup.py file.
  3. Set the DD_MAIN_PACKAGE environment variable as the name of the primary Python package.

If your application is using a unified Python project settings file:

  1. Install the hatch-datadog-build-metadata plugin and configure it to embed git metadata. If a project already has URLs, reconfigure them as dynamic and move them to another configuration section. For more information, see the plugin source code.
  2. Set the DD_MAIN_PACKAGE environment variable as the name of the primary Python package.
オプション 3: DD_GIT_* 環境変数

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

サーバーレス

サーバーレスを使用している場合、サーバーレスアプリケーションのセットアップに応じて 3 つのオプションがあります。

オプション 1: Datadog ツール
Datadog CLI tool
Use the datadog-ci client version 2.4.1 or later. You must run the CLI tool in the same directory as the code repository.
Datadog Serverless Plugin
Use the plugin version 5.18.0 or later.
Datadog CDK Construct
Use the datadog-cdk-constructs version 0.8.5 or later for AWS CDK v1.
Use the datadog-cdk-constructs version 1.4.0 or later for AWS CDK v2.
オプション 2: Setuptools または Unified Python プロジェクト設定ファイル

If your application is packaged with setuptools:

  1. Install the dd-trace package.
  2. Add import ddtrace.sourcecode.setuptools_auto as the first import to the setup.py file.
  3. Set the DD_MAIN_PACKAGE environment variable as the name of the primary Python package.

If your application is using a unified Python project settings file:

  1. Install the hatch-datadog-build-metadata plugin and configure it to embed git metadata. If a project already has URLs, reconfigure them as dynamic and move them to another configuration section. For more information, see the plugin source code.
  2. Set the DD_MAIN_PACKAGE environment variable as the name of the primary Python package.
オプション 3: DD_GIT_* 環境変数

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

ホスト

ホストを使用している場合、2 つのオプションがあります。

オプション 1: Setuptools または Unified Python プロジェクト設定ファイル

If your application is packaged with setuptools:

  1. Install the dd-trace package.
  2. Add import ddtrace.sourcecode.setuptools_auto as the first import to the setup.py file.
  3. Set the DD_MAIN_PACKAGE environment variable as the name of the primary Python package.

If your application is using a unified Python project settings file:

  1. Install the hatch-datadog-build-metadata plugin and configure it to embed git metadata. If a project already has URLs, reconfigure them as dynamic and move them to another configuration section. For more information, see the plugin source code.
  2. Set the DD_MAIN_PACKAGE environment variable as the name of the primary Python package.
オプション 2: DD_GIT_* 環境変数

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

.NET クライアントライブラリのバージョン 2.24.1 以降が必要です。

コンテナ

Docker コンテナを使用しえいる場合、Docker を使用する、Microsoft SourceLink を使用する、または DD_GIT_* 環境変数でアプリケーションを構成するの 3 つのオプションがあります。

オプション 1: Docker
  1. Add the following lines to your application’s Dockerfile:

    ARG DD_GIT_REPOSITORY_URL
    ARG DD_GIT_COMMIT_SHA
    ENV DD_GIT_REPOSITORY_URL=${DD_GIT_REPOSITORY_URL} 
    ENV DD_GIT_COMMIT_SHA=${DD_GIT_COMMIT_SHA}
    
  2. Add the following arguments to your Docker build command:

    docker build . \
     -t my-application \
     --build-arg DD_GIT_REPOSITORY_URL=<git-provider.example/me/my-repo> \
     --build-arg DD_GIT_COMMIT_SHA=$(git rev-parse HEAD)
    

If you are using Microsoft SourceLink, Datadog can extract the git commit SHA and repository URL from your .NET assembly.

  1. Open your project’s file (.csproj) in an IDE and add a reference to one of the following NuGet packages, depending on where your git repository is hosted:

    ProviderMicrosoft SourceLink
    GitHubMicrosoft.SourceLink.GitHub
    BitbucketMicrosoft.SourceLink.Bitbucket
    GitLabMicrosoft.SourceLink.GitLab
    Azure DevOpsMicrosoft.SourceLink.AzureRepos.Git
    Azure DevOps ServerMicrosoft.SourceLink.AzureDevOpsServer.Git
  2. Ensure that your .pdb files are deployed alongside your .NET assemblies (.dll or .exe) in the same folder.

オプション 3: DD_GIT_* 環境変数

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

サーバーレス

サーバーレスを使用している場合、サーバーレスアプリケーションのセットアップに応じて 3 つのオプションがあります。

オプション 1: Datadog ツール
Datadog CLI tool
Use the datadog-ci client version 2.4.1 or later. You must run the CLI tool in the same directory as the code repository.
Datadog Serverless Plugin
Use the plugin version 5.18.0 or later.
Datadog CDK Construct
Use the datadog-cdk-constructs version 0.8.5 or later for AWS CDK v1.
Use the datadog-cdk-constructs version 1.4.0 or later for AWS CDK v2.

If you are using Microsoft SourceLink, Datadog can extract the git commit SHA and repository URL from your .NET assembly.

  1. Open your project’s file (.csproj) in an IDE and add a reference to one of the following NuGet packages, depending on where your git repository is hosted:

    ProviderMicrosoft SourceLink
    GitHubMicrosoft.SourceLink.GitHub
    BitbucketMicrosoft.SourceLink.Bitbucket
    GitLabMicrosoft.SourceLink.GitLab
    Azure DevOpsMicrosoft.SourceLink.AzureRepos.Git
    Azure DevOps ServerMicrosoft.SourceLink.AzureDevOpsServer.Git
  2. Ensure that your .pdb files are deployed alongside your .NET assemblies (.dll or .exe) in the same folder.

オプション 3: DD_GIT_* 環境変数

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

ホスト

ホストを使用している場合、Microsoft SourceLink を使用するか、DD_GIT_* 環境変数でアプリケーションを構成するかの 2 つのオプションがあります。

If you are using Microsoft SourceLink, Datadog can extract the git commit SHA and repository URL from your .NET assembly.

  1. Open your project’s file (.csproj) in an IDE and add a reference to one of the following NuGet packages, depending on where your git repository is hosted:

    ProviderMicrosoft SourceLink
    GitHubMicrosoft.SourceLink.GitHub
    BitbucketMicrosoft.SourceLink.Bitbucket
    GitLabMicrosoft.SourceLink.GitLab
    Azure DevOpsMicrosoft.SourceLink.AzureRepos.Git
    Azure DevOps ServerMicrosoft.SourceLink.AzureDevOpsServer.Git
  2. Ensure that your .pdb files are deployed alongside your .NET assemblies (.dll or .exe) in the same folder.

オプション 2: DD_GIT_* 環境変数

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

NodeJS クライアントライブラリのバージョン 3.21.0 以降が必要です。

コンテナ

Docker コンテナを使用している場合、Docker を使用する、または DD_GIT_* 環境変数でアプリケーションを構成するの 2 つのオプションがあります。

オプション 1: Docker
  1. Add the following lines to your application’s Dockerfile:

    ARG DD_GIT_REPOSITORY_URL
    ARG DD_GIT_COMMIT_SHA
    ENV DD_GIT_REPOSITORY_URL=${DD_GIT_REPOSITORY_URL} 
    ENV DD_GIT_COMMIT_SHA=${DD_GIT_COMMIT_SHA}
    
  2. Add the following arguments to your Docker build command:

    docker build . \
     -t my-application \
     --build-arg DD_GIT_REPOSITORY_URL=<git-provider.example/me/my-repo> \
     --build-arg DD_GIT_COMMIT_SHA=$(git rev-parse HEAD)
    
オプション 2: DD_GIT_* 環境変数

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

サーバーレス

サーバーレスを使用している場合、サーバーレスアプリケーションのセットアップに応じて 2 つのオプションがあります。

オプション 1: Datadog ツール
Datadog CLI tool
Use the datadog-ci client version 2.4.1 or later. You must run the CLI tool in the same directory as the code repository.
Datadog Serverless Plugin
Use the plugin version 5.18.0 or later.
Datadog CDK Construct
Use the datadog-cdk-constructs version 0.8.5 or later for AWS CDK v1.
Use the datadog-cdk-constructs version 1.4.0 or later for AWS CDK v2.
オプション 2: DD_GIT_* 環境変数

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

ホスト

ホストを使用している場合、DD_GIT_* 環境変数でアプリケーションを構成します。

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

Ruby クライアントライブラリのバージョン 1.6.0 以降が必要です。

コンテナ

Docker コンテナを使用している場合、Docker を使用する、または DD_TAGS 環境変数でアプリケーションを構成するの 2 つのオプションがあります。

オプション 1: Docker
  1. Add the following lines to your application’s Dockerfile:

    ARG DD_GIT_REPOSITORY_URL
    ARG DD_GIT_COMMIT_SHA
    ENV DD_TAGS="git.repository_url:${DD_GIT_REPOSITORY_URL},git.commit.sha:${DD_GIT_COMMIT_SHA}"
    
  2. Add the following arguments to your Docker build command:

    docker build . \
     -t my-application \
     --build-arg DD_GIT_REPOSITORY_URL=<git-provider.example/me/my-repo> \
     --build-arg DD_GIT_COMMIT_SHA=$(git rev-parse HEAD)
    
オプション 2: DD_TAGS 環境変数

Configure your application with the DD_TAGS environment variable:

export DD_TAGS="git.commit.sha:<commitSha>,git.repository_url:<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

サーバーレス

サーバーレスを使用している場合、サーバーレスアプリケーションのセットアップに応じて 2 つのオプションがあります。

オプション 1: Datadog ツール
Datadog CLI tool
Use the datadog-ci client version 2.4.1 or later. You must run the CLI tool in the same directory as the code repository.
Datadog Serverless Plugin
Use the plugin version 5.18.0 or later.
Datadog CDK Construct
Use the datadog-cdk-constructs version 0.8.5 or later for AWS CDK v1.
Use the datadog-cdk-constructs version 1.4.0 or later for AWS CDK v2.
オプション 2: DD_TAGS 環境変数

Configure your application with the DD_TAGS environment variable:

export DD_TAGS="git.commit.sha:<commitSha>,git.repository_url:<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

ホスト

ホストを使用している場合、DD_TAGS 環境変数でアプリケーションを構成します。

Configure your application with the DD_TAGS environment variable:

export DD_TAGS="git.commit.sha:<commitSha>,git.repository_url:<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

Java クライアントライブラリのバージョン 1.12.0 以降が必要です。

Docker コンテナを使用している場合、Docker を使用する、または DD_GIT_* 環境変数でアプリケーションを構成するの 2 つのオプションがあります。

オプション 1: Docker
  1. Add the following lines to your application’s Dockerfile:

    ARG DD_GIT_REPOSITORY_URL
    ARG DD_GIT_COMMIT_SHA
    ENV DD_GIT_REPOSITORY_URL=${DD_GIT_REPOSITORY_URL} 
    ENV DD_GIT_COMMIT_SHA=${DD_GIT_COMMIT_SHA}
    
  2. Add the following arguments to your Docker build command:

    docker build . \
     -t my-application \
     --build-arg DD_GIT_REPOSITORY_URL=<git-provider.example/me/my-repo> \
     --build-arg DD_GIT_COMMIT_SHA=$(git rev-parse HEAD)
    
オプション 2: DD_GIT_* 環境変数

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

サーバーレス

サーバーレスを使用している場合、サーバーレスアプリケーションのセットアップに応じて 2 つのオプションがあります。

オプション 1: Datadog ツール
Datadog CLI tool
Use the datadog-ci client version 2.4.1 or later. You must run the CLI tool in the same directory as the code repository.
Datadog Serverless Plugin
Use the plugin version 5.18.0 or later.
Datadog CDK Construct
Use the datadog-cdk-constructs version 0.8.5 or later for AWS CDK v1.
Use the datadog-cdk-constructs version 1.4.0 or later for AWS CDK v2.
オプション 2: DD_GIT_* 環境変数

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

ホスト

ホストを使用している場合、DD_GIT_* 環境変数でアプリケーションを構成します。

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

PHP クライアントライブラリのバージョン 1.12.0 以降が必要です。

Docker コンテナを使用している場合、Docker を使用する、または DD_GIT_* 環境変数でアプリケーションを構成するの 2 つのオプションがあります。

オプション 1: Docker
  1. Add the following lines to your application’s Dockerfile:

    ARG DD_GIT_REPOSITORY_URL
    ARG DD_GIT_COMMIT_SHA
    ENV DD_GIT_REPOSITORY_URL=${DD_GIT_REPOSITORY_URL} 
    ENV DD_GIT_COMMIT_SHA=${DD_GIT_COMMIT_SHA}
    
  2. Add the following arguments to your Docker build command:

    docker build . \
     -t my-application \
     --build-arg DD_GIT_REPOSITORY_URL=<git-provider.example/me/my-repo> \
     --build-arg DD_GIT_COMMIT_SHA=$(git rev-parse HEAD)
    
オプション 2: DD_GIT_* 環境変数

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

ホスト

ホストを使用している場合、DD_GIT_* 環境変数でアプリケーションを構成します。

Configure your application with the DD_GIT_* environment variables:

export DD_GIT_COMMIT_SHA="<commitSha>"
export DD_GIT_REPOSITORY_URL="<git-provider.example/me/my-repo>"

Replace <commitSha> with the commit SHA used to build your application. You can retrieve this by running git rev-parse HEAD at build time, and it needs to be passed into the runtime environment variables.

Docker コンテナ内でのビルド

ビルドプロセスが Docker コンテナ内の CI で実行される場合は、ビルドが Git 情報にアクセスできるように以下の手順を実行します。

  1. 次のテキストを .dockerignore ファイルに追加します。これにより、ビルドプロセスが .git フォルダのサブセットにアクセスできるようになり、git のコミットハッシュとリポジトリの URL を特定できるようになります。

    !.git/HEAD
    !.git/config
    !.git/refs
    
  2. 以下のコードを Dockerfile に追加してください。実際のビルドが実行される前に配置されていることを確認してください。

    COPY .git ./.git
    

テレメトリータギングの構成

サポートされていない言語の場合、git.commit.sha タグと git.repository_url タグを使用してデータを特定のコミットにリンクします。git.repository_url タグにプロトコルが含まれないことを確認してください。例えば、リポジトリの URL が https://github.com/example/repo の場合、git.repository_url タグの値は github.com/example/repo となります。

リポジトリのメタデータを同期

テレメトリーとソースコードをリンクさせるには、リポジトリのメタデータを Datadog と同期させる必要があります。Datadog はリポジトリ内のファイルの実際の内容は保存せず、Git のコミットオブジェクトとツリーオブジェクトのみを保存します。

Git プロバイダー

ソースコードインテグレーションは、以下の Git プロバイダーをサポートしています。

プロバイダーContext Links SupportCode Snippets Support
GitHub SaaS (github.com)はいはい
GitHub Enterprise Serverはいはい
GitLab SaaS (gitlab.com)はいはい
GitLab self-managedはいいいえ
Bitbucketはいいいえ
Azure DevOps サービスはいいいえ
Azure DevOps Serverはいいいえ

Datadog の GitHub インテグレーションGitHub インテグレーションタイルにインストールして、リポジトリのメタデータを Datadog が自動的に同期できるようにします。インテグレーションタイルで権限を指定する場合、少なくとも ContentsRead 権限を選択してください。

GitHub インテグレーションを設定することで、Error TrackingContinuous ProfilerServerless MonitoringCI VisibilityApplication Security Monitoring でインラインコードスニペットを確認することもできます。

セルフマネージド GitLab インスタンスからのリポジトリは、ソースコードインテグレーションではすぐに使えません。この機能を有効にするには、サポートにお問い合わせください

テレメトリーをソースコードとリンクさせるには、リポジトリのメタデータを datadog-ci git-metadata upload コマンドでアップロードします。

Git リポジトリ内で datadog-ci git-metadata upload を実行すると、Datadog はリポジトリの URL、現在のブランチのコミット SHA、そして追跡したファイルのパスのリストを受け取ります。

このコマンドは、Datadog と同期する必要があるコミットごとに実行します。

gitlab.com を使用している場合、これにより Error TrackingContinuous ProfilerServerless MonitoringCI Visibility、および Application Security Monitoring でインラインコードスニペットを確認することができます。

検証

データが収集されていることを確認するために、CI パイプラインで datadog-ci git-metadata upload を実行します。

以下のような出力が期待できます。

Reporting commit 007f7f466e035b052415134600ea899693e7bb34 from repository git@my-git-server.com:my-org/my-repository.git.
180 tracked file paths will be reported.
✅  Handled in 0.077 seconds.
セルフホストインスタンスまたはプライベート URL 上のリポジトリは、ソースコードインテグレーションではすぐに使えません。この機能を有効にするには、サポートにお問い合わせください

テレメトリーをソースコードとリンクさせるには、リポジトリのメタデータを datadog-ci git-metadata upload コマンドでアップロードします。

Git リポジトリ内で datadog-ci git-metadata upload を実行すると、Datadog はリポジトリの URL、現在のブランチのコミット SHA、そして追跡したファイルのパスのリストを受け取ります。

このコマンドは、Datadog と同期する必要があるコミットごとに実行します。

検証

データが収集されていることを確認するために、CI パイプラインで datadog-ci git-metadata upload を実行します。

以下のような出力が期待できます。

Reporting commit 007f7f466e035b052415134600ea899693e7bb34 from repository git@my-git-server.com:my-org/my-repository.git.
180 tracked file paths will be reported.
✅  Handled in 0.077 seconds.

使用方法

Git プロバイダーへのリンク

エラー追跡でスタックフレームからソースリポジトリへのリンクを見ることができます。

  1. APM > Error Tracking の順に移動します。
  2. 課題をクリックします。右側に Issue Details パネルが表示されます。
  3. Latest Event の下で、フレームの右側にある View ボタンをクリックするか、View fileView Git blameView commit を選択すると、ソースコード管理ツールにリダイレクトされます。
Error Tracking のエラースタックトレースの右側に表示される、3 つのオプション (ファイルの表示、注釈の表示、コミットの表示) を備えたリポジトリの表示ボタンと、スタックトレース内のインラインコードスニペット

GitHub インテグレーションを使用している場合、または GitLab SaaS インスタンス (gitlab.com) でリポジトリをホストしている場合は、スタックフレームの Connect to preview をクリックします。スタックトレースでインラインコードスニペットを直接見ることができます。

Continuous Profiler では、プロファイルフレームのソースコードプレビューを見ることができます。

  1. APM > Profile Search の順に移動します。
  2. フレームグラフのメソッドにカーソルを合わせます。
  3. 必要であれば、Opt または Alt を押してプレビューを有効にします。
Continuous Profiler のソースコードプレビュー

プロファイルフレームからソースリポジトリへのリンクも表示できます。これは、行、メソッド、ファイルごとに分割されたプロファイルでサポートされています。

  1. APM > Profile Search の順に移動します。
  2. フレームグラフのメソッドにカーソルを合わせます。右側に More actions というラベルのついたケバブアイコンが表示されます。
  3. More actions* > View in repo をクリックし、トレースをソースコードリポジトリで開きます。
Continuous Profiler から GitHub へのリンク

Lambda 関数の関連するスタックトレースのエラーからソースリポジトリへのリンクを Serverless Monitoring で確認できます。

  1. Infrastructure > Serverless に移動し、AWS タブをクリックします。
  2. Lambda 関数をクリックし、関連するスタックトレースを持つ呼び出しの Open Trace ボタンをクリックします。
  3. View Code をクリックして、ソースコードリポジトリでエラーを開きます。

GitHub インテグレーションを使用している場合、エラーフレームで Connect to preview をクリックします。Lambda 関数のスタックトレースでインラインコードスニペットを直接見ることができます。

失敗したテスト実行からソースリポジトリへのリンクは、Test Visibility で確認できます。

  1. Software Delivery > Test Visibility > Test Runs に移動し、失敗したテスト実行を選択します。
  2. View on GitHub ボタンをクリックして、テストをソースコードリポジトリで開きます。
CI Visibility Explorer から GitHub へのリンク

詳細は Datadog で開発者のワークフローを強化するを参照してください。

失敗した Static Analysis と Software Composition Analysis のスキャンからソースリポジトリへのリンクは、Code Analysis で確認できます。

  1. Software Delivery > Code Analysis に移動し、リポジトリを選択します。
  2. Code Vulnerabilities または Code Quality ビューで、コードの脆弱性または違反をクリックします。Details セクションで、View Code ボタンをクリックして、フラグが付けられたコードをソースコードリポジトリで開きます。
Code Analysis Code Vulnerabilities ビューから GitHub へのリンク

詳細については、Code Analysis のドキュメントを参照してください。

セキュリティシグナルの関連するスタックトレースのエラーからソースリポジトリへのリンクは、Application Security Monitoring で確認できます。

  1. Security > Application Security に移動し、セキュリティシグナルを選択します。
  2. Related Signals タブの Traces セクションまでスクロールダウンし、関連するスタックトレースをクリックします。
  3. View Code をクリックして、ソースコードリポジトリでエラーを開きます。

GitHub インテグレーションを使用している場合、エラーフレームで Connect to preview をクリックします。インラインコードスニペットをセキュリティシグナルのスタックトレースで直接見ることができます。

Application Security Monitoring から GitHub へのリンク

その他の参考資料