概要

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.

The PHP client library version 1.2.0 or later is required.

If you are using Docker containers, you have two options: using Docker or configuring your application with DD_GIT_* environment variables.

Option 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)
    
Option 2: DD_GIT_* Environment Variables

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.

Host

If you are using a host, configure your application with DD_GIT_* environment variables.

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.

Build inside a Docker container

If your build process is executed in CI within a Docker container, perform the following steps to ensure that the build can access Git information:

  1. Add the following text to your .dockerignore file. This ensures that the build process is able to access a subset of the .git folder, enabling it to determine the git commit hash and repository URL.

    !.git/HEAD
    !.git/config
    !.git/refs
    
  2. Add the following line of code to your Dockerfile. Ensure that it is placed before the actual build is ran.

    COPY .git ./.git
    

Configure telemetry tagging

For unsupported languages, use the git.commit.sha and git.repository_url tags to link data to a specific commit. Ensure that the git.repository_url tag does not contain protocols. For example, if your repository URL is https://github.com/example/repo, the value for the git.repository_url tag should be github.com/example/repo.

Synchronize your repository metadata

To link your telemetry with source code, your repository metadata must be synchronized to Datadog. Datadog doesn’t store the actual content of files in your repository, only the Git commit and tree objects.

Git providers

The source code integration supports the following Git providers:

ProviderContext Links SupportCode Snippets Support
GitHub SaaS (github.com)YesYes
GitHub Enterprise ServerYesYes
GitLab SaaS (gitlab.com)YesYes
GitLab self-managedYesNo
BitbucketYesNo
Azure DevOps ServicesYesNo
Azure DevOps ServerYesNo

Install Datadog’s GitHub integration on the GitHub integration tile to allow Datadog to synchronize your repository metadata automatically. When specifying permissions on the integration tile, select at least Read permissions for Contents.

Setting up the GitHub integration also allows you to see inline code snippets in Error Tracking, Continuous Profiler, Serverless Monitoring, CI Visibility, and Application Security Monitoring.

Repositories from self-managed GitLab instances are not supported out-of-the-box by the source code integration. To enable this feature, contact Support.

To link telemetry with your source code, upload your repository metadata with the datadog-ci git-metadata upload command.

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

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

If you are using gitlab.com, this also allows you to see inline code snippets in Error Tracking, Continuous Profiler, Serverless Monitoring, CI Visibility, and Application Security Monitoring.

Validation

To ensure the data is being collected, run datadog-ci git-metadata upload in your CI pipeline.

You can expect to see the following output:

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.
Repositories on self-hosted instances or private URLs are not supported out-of-the-box by the source code integration. To enable this feature, contact Support.

To link telemetry with your source code, upload your repository metadata with the datadog-ci git-metadata upload command.

When you run datadog-ci git-metadata upload within a Git repository, Datadog receives the repository URL, the commit SHA of the current branch, and a list of tracked file paths.

Run this command for every commit that you need to be synchronized with Datadog.

Validation

To ensure the data is being collected, run datadog-ci git-metadata upload in your CI pipeline.

You can expect to see the following output:

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.

Usage

You can see links from stack frames to their source repository in Error Tracking.

  1. Navigate to APM > Error Tracking.
  2. Click on an issue. The Issue Details panel appears on the right.
  3. Under Latest Event, click the View button on the right of a frame or select View file, View Git blame, or View commit to be redirected to your source code management tool.
A view repository button with three options (view file, view blame, and view commit) available on the right side of an error stack trace in Error Tracking, along with inline code snippets in the stack trace

If you’re using the GitHub integration, or if you’re hosting your repositories on the GitLab SaaS instance (gitlab.com), click Connect to preview on stack frames. You can see inline code snippets directly in the stack trace.

You can see a source code preview for profile frames in the Continuous Profiler.

  1. Navigate to APM > Profile Search.
  2. Hover your cursor over a method in the flame graph.
  3. If needed, press Opt or Alt to enable the preview.
Source code preview in the Continuous Profiler

You can also see links from profile frames to their source repository. This is supported for profiles broken down by line, method, or file.

  1. Navigate to APM > Profile Search.
  2. Hover your cursor over a method in the flame graph. A kebab icon with the More actions label appears on the right.
  3. Click More actions > View in repo to open the trace in its source code repository.
Link to GitHub from the Continuous Profiler

You can see links from errors in your Lambda functions’ associated stack traces to their source repository in Serverless Monitoring.

  1. Navigate to Infrastructure > Serverless and click on the AWS tab.
  2. Click on a Lambda function and click the Open Trace button for an invocation with an associated stack trace.
  3. Click View Code to open the error in its source code repository.

If you’re using the GitHub integration, click Connect to preview on error frames. You can see inline code snippets directly in the Lambda function’s stack trace.

You can see links from failed test runs to their source repository in Test Visibility.

  1. Navigate to Software Delivery > Test Visibility > Test Runs and select a failed test run.
  2. Click the View on GitHub button to open the test in its source code repository.
Link to GitHub from the CI Visibility Explorer

For more information, see Enhancing Developer Workflows with Datadog.

You can see links from failed Static Analysis and Software Composition Analysis scans to their source repository in Code Analysis.

  1. Navigate to Software Delivery > Code Analysis and select a repository.
  2. In the Code Vulnerabilities or Code Quality view, click on a code vulnerability or violation. In the Details section, click the View Code button to open the flagged code in its source code repository.
Link to GitHub from the Code Analysis Code Vulnerabilities view

For more information, see the Code Analysis documentation.

You can see links from errors in your security signals’ associated stack traces to their source repository in Application Security Monitoring.

  1. Navigate to Security > Application Security and select a security signal.
  2. Scroll down to the Traces section on the Related Signals tab and click on an associated stack trace.
  3. Click View Code to open the error in its source code repository.

If you’re using the GitHub integration, click Connect to preview on error frames. You can see inline code snippets directly in the security signal’s stack trace.

Link to GitHub from Application Security Monitoring

Further Reading

PREVIEWING: evan.li/clarify-agentless