---
title: Service Mapping for Source Code Integration
description: Tag your APM telemetry with Git information to link services to source code.
breadcrumbs: Docs > Source Code Integration > Service Mapping for Source Code Integration
---

# Service Mapping for Source Code Integration

## Overview{% #overview %}

Datadog Agent v7.35.0 or later is required.

If you have [APM](https://docs.datadoghq.com/tracing/) set up already, navigate to [**Integrations** > **Link Source Code**](https://app.datadoghq.com/source-code/setup/apm) and configure the source code integration for your backend services.

Your telemetry must be tagged with Git information that ties the running application version with a particular repository and commit.

For supported languages, Datadog recommends embedding Git information in the deployed artifacts, which is then extracted by the [Datadog Tracing Libraries](https://docs.datadoghq.com/tracing/trace_collection/dd_libraries/) automatically.

For other languages and configurations, you can configure telemetry tagging yourself.

## Embed Git information in your build artifacts{% #embed-git-information-in-your-build-artifacts %}

You can embed the repository URL and commit hash in your build artifact. The [Datadog Tracing Libraries](https://docs.datadoghq.com/tracing/trace_collection/dd_libraries/) use this information to automatically add the right tags to your APM service telemetry.

Select one of the following languages that supports embedding git information:

{% tab title="Go" %}

{% alert level="info" %}
The Go client library version 1.48.0 or later is required.
{% /alert %}

### Containers{% #containers %}

If you are using Docker containers, you have three options: using Docker, using the Datadog tracing library, or configuring your application with `DD_GIT_*` environment variables.

#### Option 1: Docker{% #option-1-docker %}

You can embed git information in your Docker image using either build arguments with environment variables, or image labels.

###### Using build arguments and environment variables{% #using-build-arguments-and-environment-variables %}

1. Add the following lines to your application's Dockerfile:

   ```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}
   ```

1. Add the following arguments to your Docker build command:

   ```shell
   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)
   ```

###### Using image labels{% #using-image-labels %}

This approach requires Docker, or containerd >= 1.5.6. It doesn't support containers running on AWS Fargate.

Datadog can extract source code information directly from your images' Docker labels. During build time, follow the [Open Containers standard](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys) to add the git commit SHA and repository URL as Docker labels:

```shell
docker build . \
  -t my-application \
  --label org.opencontainers.image.revision=$(git rev-parse HEAD) \
  --label org.opencontainers.image.source=$(git config --get remote.origin.url)
```

#### Option 2: Datadog tracing library{% #option-2-datadog-tracing-library %}

Go embeds version control information in binaries since [version 1.18](https://tip.golang.org/doc/go1.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.

#### Option 3: `DD_GIT_*` environment variables{% #option-3-dd_git_-environment-variables %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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.

### Serverless{% #serverless %}

If you are using Serverless, you have three options depending on your serverless application's setup.

#### Option 1: Datadog tooling{% #option-1-datadog-tooling %}

{% dl %}

{% dt %}
[Datadog CLI tool](https://www.npmjs.com/package/@datadog/datadog-ci)
{% /dt %}

{% dd %}
Use the `datadog-ci` client version 2.10.0 or later. You must run the CLI tool in the same directory as the code repository.
{% /dd %}

{% dt %}
[Datadog Serverless Plugin](https://docs.datadoghq.com/serverless/libraries_integrations/plugin/)
{% /dt %}

{% dd %}
Use the plugin version 5.60.0 or later.
{% /dd %}

{% dt %}
[Datadog CDK Construct](https://github.com/DataDog/datadog-cdk-constructs)
{% /dt %}

{% dd %}
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.
{% /dd %}

{% /dl %}

#### Option 2: Datadog tracing library{% #option-2-datadog-tracing-library-1 %}

Go embeds version control information in binaries since [version 1.18](https://tip.golang.org/doc/go1.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.

#### Option 3: `DD_GIT_*` environment variables{% #option-3-dd_git_-environment-variables-1 %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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{% #host %}

If you are using a host, you have two options.

#### Option 1: Datadog tracing library{% #option-1-datadog-tracing-library %}

Go embeds version control information in binaries since [version 1.18](https://tip.golang.org/doc/go1.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.

#### Option 2: `DD_GIT_*` environment variables{% #option-2-dd_git_-environment-variables %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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.
{% /tab %}

{% tab title="Python" %}

{% alert level="info" %}
The Python client library version 1.12.0 or later is required.
{% /alert %}

### Containers{% #containers %}

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

#### Option 1: Docker{% #option-1-docker %}

You can embed git information in your Docker image using either build arguments with environment variables, or image labels.

###### Using build arguments and environment variables{% #using-build-arguments-and-environment-variables %}

1. Add the following lines to your application's Dockerfile:

   ```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}
   ```

1. Add the following arguments to your Docker build command:

   ```shell
   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)
   ```

###### Using image labels{% #using-image-labels %}

This approach requires Docker, or containerd >= 1.5.6. It doesn't support containers running on AWS Fargate.

Datadog can extract source code information directly from your images' Docker labels. During build time, follow the [Open Containers standard](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys) to add the git commit SHA and repository URL as Docker labels:

```shell
docker build . \
  -t my-application \
  --label org.opencontainers.image.revision=$(git rev-parse HEAD) \
  --label org.opencontainers.image.source=$(git config --get remote.origin.url)
```

#### Option 2: Setuptools or unified Python project settings file{% #option-2-setuptools-or-unified-python-project-settings-file %}

If your application is packaged with setuptools:

1. Install the [`dd-trace` package](https://github.com/DataDog/dd-trace-py).
1. Add `import ddtrace.sourcecode.setuptools_auto` as the first import to the `setup.py` file.
1. 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](https://github.com/DataDog/hatch-datadog-build-metadata#readme).
1. Set the `DD_MAIN_PACKAGE` environment variable as the name of the primary Python package.

#### Option 3: `DD_GIT_*` environment variables{% #option-3-dd_git_-environment-variables %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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.

### Serverless{% #serverless %}

If you are using Serverless, you have three options depending on your serverless application's setup.

#### Option 1: Datadog tooling{% #option-1-datadog-tooling %}

{% dl %}

{% dt %}
[Datadog CLI tool](https://github.com/DataDog/hatch-datadog-build-metadata#readme)
{% /dt %}

{% dd %}
Use the `datadog-ci` client version 2.10.0 or later. You must run the CLI tool in the same directory as the code repository.
{% /dd %}

{% dt %}
[Datadog Serverless Plugin](https://docs.datadoghq.com/serverless/libraries_integrations/plugin/)
{% /dt %}

{% dd %}
Use the plugin version 5.60.0 or later.
{% /dd %}

{% dt %}
[Datadog CDK Construct](https://github.com/DataDog/datadog-cdk-constructs)
{% /dt %}

{% dd %}
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.
{% /dd %}

{% /dl %}

#### Option 2: Setuptools or unified Python project settings file{% #option-2-setuptools-or-unified-python-project-settings-file-1 %}

If your application is packaged with setuptools:

1. Install the [`dd-trace` package](https://github.com/DataDog/dd-trace-py).
1. Add `import ddtrace.sourcecode.setuptools_auto` as the first import to the `setup.py` file.
1. 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](https://github.com/DataDog/hatch-datadog-build-metadata#readme).
1. Set the `DD_MAIN_PACKAGE` environment variable as the name of the primary Python package.

#### Option 3: `DD_GIT_*` environment variables{% #option-3-dd_git_-environment-variables-1 %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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{% #host %}

If you are using a host, you have two options.

#### Option 1: Setuptools or unified Python project settings file{% #option-1-setuptools-or-unified-python-project-settings-file %}

If your application is packaged with setuptools:

1. Install the [`dd-trace` package](https://github.com/DataDog/dd-trace-py).
1. Add `import ddtrace.sourcecode.setuptools_auto` as the first import to the `setup.py` file.
1. 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](https://github.com/DataDog/hatch-datadog-build-metadata#readme).
1. Set the `DD_MAIN_PACKAGE` environment variable as the name of the primary Python package.

#### Option 2: `DD_GIT_*` environment variables{% #option-2-dd_git_-environment-variables %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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.
{% /tab %}

{% tab title=".NET" %}

{% alert level="info" %}
The .NET client library version 2.24.1 or later is required.
{% /alert %}

As a first step, ensure that your `.pdb` files are deployed alongside your .NET assemblies (`.dll` or `.exe`) in the same folder. Then, follow the rest of the instructions based on your specific deployment model:

### Containers{% #containers %}

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

#### Option 1: Docker{% #option-1-docker %}

You can embed git information in your Docker image using either build arguments with environment variables, or image labels.

###### Using build arguments and environment variables{% #using-build-arguments-and-environment-variables %}

1. Add the following lines to your application's Dockerfile:

   ```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}
   ```

1. Add the following arguments to your Docker build command:

   ```shell
   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)
   ```

###### Using image labels{% #using-image-labels %}

This approach requires Docker, or containerd >= 1.5.6. It doesn't support containers running on AWS Fargate.

Datadog can extract source code information directly from your images' Docker labels. During build time, follow the [Open Containers standard](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys) to add the git commit SHA and repository URL as Docker labels:

```shell
docker build . \
  -t my-application \
  --label org.opencontainers.image.revision=$(git rev-parse HEAD) \
  --label org.opencontainers.image.source=$(git config --get remote.origin.url)
```

#### Option 2: Microsoft SourceLink{% #option-2-microsoft-sourcelink %}

If you are using [Microsoft SourceLink](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys), 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:
| Provider            | Microsoft SourceLink                                                                                                    |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| GitHub              | [Microsoft.SourceLink.GitHub](https://www.nuget.org/packages/Microsoft.SourceLink.GitHub)                               |
| Bitbucket           | [Microsoft.SourceLink.Bitbucket.Git](https://www.nuget.org/packages/Microsoft.SourceLink.Bitbucket.Git)                 |
| GitLab              | [Microsoft.SourceLink.GitLab](https://www.nuget.org/packages/Microsoft.SourceLink.GitLab)                               |
| Azure DevOps        | [Microsoft.SourceLink.AzureRepos.Git](https://www.nuget.org/packages/Microsoft.SourceLink.AzureRepos.Git)               |
| Azure DevOps Server | [Microsoft.SourceLink.AzureDevOpsServer.Git](https://www.nuget.org/packages/Microsoft.SourceLink.AzureDevOpsServer.Git) |

#### Option 3: `DD_GIT_*` environment variables{% #option-3-dd_git_-environment-variables %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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.

### Serverless{% #serverless %}

If you are using Serverless, you have three options depending on your serverless application's setup.

#### Option 1: Datadog tooling{% #option-1-datadog-tooling %}

{% dl %}

{% dt %}
[Datadog CLI tool](https://www.nuget.org/packages/Microsoft.SourceLink.GitHub)
{% /dt %}

{% dd %}
Use the `datadog-ci` client version 2.10.0 or later. You must run the CLI tool in the same directory as the code repository.
{% /dd %}

{% dt %}
[Datadog Serverless Plugin](https://www.nuget.org/packages/Microsoft.SourceLink.Bitbucket.Git)
{% /dt %}

{% dd %}
Use the plugin version 5.60.0 or later.
{% /dd %}

{% dt %}
[Datadog CDK Construct](https://www.nuget.org/packages/Microsoft.SourceLink.GitLab)
{% /dt %}

{% dd %}
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.
{% /dd %}

{% /dl %}

#### Option 2: Microsoft SourceLink{% #option-2-microsoft-sourcelink-1 %}

If you are using [Microsoft SourceLink](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys), 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:
| Provider            | Microsoft SourceLink                                                                                                    |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| GitHub              | [Microsoft.SourceLink.GitHub](https://www.nuget.org/packages/Microsoft.SourceLink.GitHub)                               |
| Bitbucket           | [Microsoft.SourceLink.Bitbucket.Git](https://www.nuget.org/packages/Microsoft.SourceLink.Bitbucket.Git)                 |
| GitLab              | [Microsoft.SourceLink.GitLab](https://www.nuget.org/packages/Microsoft.SourceLink.GitLab)                               |
| Azure DevOps        | [Microsoft.SourceLink.AzureRepos.Git](https://www.nuget.org/packages/Microsoft.SourceLink.AzureRepos.Git)               |
| Azure DevOps Server | [Microsoft.SourceLink.AzureDevOpsServer.Git](https://www.nuget.org/packages/Microsoft.SourceLink.AzureDevOpsServer.Git) |

#### Option 3: `DD_GIT_*` environment variables{% #option-3-dd_git_-environment-variables-1 %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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{% #host %}

If you are using a host, you have two options: using Microsoft SourceLink or configuring your application with `DD_GIT_*` environment variables.

#### Option 1: Microsoft SourceLink{% #option-1-microsoft-sourcelink %}

If you are using [Microsoft SourceLink](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys), 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:
| Provider            | Microsoft SourceLink                                                                                                    |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| GitHub              | [Microsoft.SourceLink.GitHub](https://www.nuget.org/packages/Microsoft.SourceLink.GitHub)                               |
| Bitbucket           | [Microsoft.SourceLink.Bitbucket.Git](https://www.nuget.org/packages/Microsoft.SourceLink.Bitbucket.Git)                 |
| GitLab              | [Microsoft.SourceLink.GitLab](https://www.nuget.org/packages/Microsoft.SourceLink.GitLab)                               |
| Azure DevOps        | [Microsoft.SourceLink.AzureRepos.Git](https://www.nuget.org/packages/Microsoft.SourceLink.AzureRepos.Git)               |
| Azure DevOps Server | [Microsoft.SourceLink.AzureDevOpsServer.Git](https://www.nuget.org/packages/Microsoft.SourceLink.AzureDevOpsServer.Git) |

#### Option 2: `DD_GIT_*` environment variables{% #option-2-dd_git_-environment-variables %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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.
{% /tab %}

{% tab title="Node.js" %}

{% alert level="info" %}
The Node.js client library version 3.21.0 or later is required.For transpiled Node.js applications (for example, TypeScript), make sure to generate and publish source maps with the deployed application, and to run Node.js with the [`--enable-source-maps`](https://nodejs.org/docs/latest/api/cli.html#--enable-source-maps) flag. Otherwise, code links and snippets will not work.
{% /alert %}

### Containers{% #containers %}

If you are using Docker containers, you have three options: using a bundler plugin, using Docker, or configuring your application with `DD_GIT_*` environment variables.

#### Option 1: Bundler plugin{% #option-1-bundler-plugin %}

If you're bundling your application from a Git directory, you can use plugins to inject Git metadata into the runtime bundle.

###### Bundling with esbuild{% #bundling-with-esbuild %}

Use the `dd-trace/esbuild` plugin to automatically inject `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` in your runtime bundle. See the plugin [documentation](https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/nodejs/#bundling-with-esbuild). Install `dd-trace` **v5.68.0 or later** for automatic Git tag injection.

```diff
const esbuild = require('esbuild');
+ const ddPlugin = require('dd-trace/esbuild');

esbuild.build({
  entryPoints: ['index.js'],
  bundle: true,
  platform: 'node',
  target: ['node20'],
  format: 'cjs',
  outfile: 'dist/bundle.js',
  packages: 'external',
  external: ['dd-trace', 'express']
+  plugins: [ddPlugin],
}).catch((e) => {
  console.error(e);
  process.exit(1);
});
```

###### Bundling with Rollup{% #bundling-with-rollup %}

Use [rollup-plugin-inject-process-env](https://www.npmjs.com/package/rollup-plugin-inject-process-env) to inject `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` in your runtime bundle. Run the bundle step inside a Git repository so the script can read `.git/` information.

```diff
+ const injectProcessEnv = require('rollup-plugin-inject-process-env');

+ const { DD_GIT_REPOSITORY_URL, DD_GIT_COMMIT_SHA } = getGitInfo();

module.exports = {
  input: 'index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'cjs'
  },
  external: [
    'express',
    'dd-trace'
  ],
  plugins: [
    nodeResolve(),
    commonjs()
+    injectProcessEnv({
+       DD_GIT_REPOSITORY_URL,
+       DD_GIT_COMMIT_SHA
+    })
  ]
};
```

The `getGitInfo()` function executes git commands to return `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` variables. It needs to be executed in the git repository.

```js
const { execSync } = require('child_process');

function getGitInfo() {
  try {
    const commitSha = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();
    const repositoryUrl = execSync('git config --get remote.origin.url', { encoding: 'utf8' }).trim();

    console.log('Build-time Git metadata:', {
      commitSha,
      repositoryUrl,
    });

    return {
      DD_GIT_REPOSITORY_URL: repositoryUrl,
      DD_GIT_COMMIT_SHA: commitSha,
    };
  } catch (error) {
    console.warn('Could not get Git metadata at build time:', error.message);
    return {
      DD_GIT_REPOSITORY_URL: '',
      DD_GIT_COMMIT_SHA: '',
    };
  }
}
```

###### Bundling with webpack{% #bundling-with-webpack %}

Use the [BannerPlugin](https://webpack.js.org/plugins/banner-plugin/) to inject `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` in your runtime bundle. Run the bundle step inside a Git repository so the script can read `.git/` information.

```diff
+ const webpack = require('webpack');

+ const { DD_GIT_REPOSITORY_URL, DD_GIT_COMMIT_SHA } = getGitInfo();

module.exports = {
	target: 'node',
	entry: './index.js',
	mode: 'production',
	output: {
		path: path.resolve(__dirname, 'dist'),
		filename: 'bundle.js',
		libraryTarget: 'commonjs2'
	},
	externals: [
		'express',
		'dd-trace'
	],
	plugins: [
+		new webpack.BannerPlugin({
+			raw: true,
+			entryOnly: true,
+			banner:
+        `process.env.DD_GIT_REPOSITORY_URL=${JSON.stringify(DD_GIT_REPOSITORY_URL)};` +
+				 `process.env.DD_GIT_COMMIT_SHA=${JSON.stringify(DD_GIT_COMMIT_SHA)};`,
+		}),
	]
};
```

The `getGitInfo()` function executes git commands to return `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` variables. It needs to be executed in the git repository.

```js
const { execSync } = require('child_process');

function getGitInfo() {
  try {
    const commitSha = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();
    const repositoryUrl = execSync('git config --get remote.origin.url', { encoding: 'utf8' }).trim();

    console.log('Build-time Git metadata:', {
      commitSha,
      repositoryUrl,
    });

    return {
      DD_GIT_REPOSITORY_URL: repositoryUrl,
      DD_GIT_COMMIT_SHA: commitSha,
    };
  } catch (error) {
    console.warn('Could not get Git metadata at build time:', error.message);
    return {
      DD_GIT_REPOSITORY_URL: '',
      DD_GIT_COMMIT_SHA: '',
    };
  }
}
```

#### Option 2: Docker{% #option-2-docker %}

You can embed git information in your Docker image using either build arguments with environment variables, or image labels.

###### Using build arguments and environment variables{% #using-build-arguments-and-environment-variables %}

1. Add the following lines to your application's Dockerfile:

   ```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}
   ```

1. Add the following arguments to your Docker build command:

   ```shell
   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)
   ```

###### Using image labels{% #using-image-labels %}

This approach requires Docker, or containerd >= 1.5.6. It doesn't support containers running on AWS Fargate.

Datadog can extract source code information directly from your images' Docker labels. During build time, follow the [Open Containers standard](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys) to add the git commit SHA and repository URL as Docker labels:

```shell
docker build . \
  -t my-application \
  --label org.opencontainers.image.revision=$(git rev-parse HEAD) \
  --label org.opencontainers.image.source=$(git config --get remote.origin.url)
```

#### Option 3: `DD_GIT_*` environment variables{% #option-3-dd_git_-environment-variables %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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.

### Serverless{% #serverless %}

If you are using Serverless, you have several options depending on your serverless application's setup.

#### Option 1: Bundler plugin{% #option-1-bundler-plugin-1 %}

If you're bundling your application from a Git directory, you can use plugins to inject Git metadata into the runtime bundle.

###### Bundling with esbuild{% #bundling-with-esbuild-1 %}

Use the `dd-trace/esbuild` plugin to automatically inject `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` in your runtime bundle. See the plugin [documentation](https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/nodejs/#bundling-with-esbuild). Install `dd-trace` **v5.68.0 or later** for automatic Git tag injection.

```diff
const esbuild = require('esbuild');
+ const ddPlugin = require('dd-trace/esbuild');

esbuild.build({
  entryPoints: ['index.js'],
  bundle: true,
  platform: 'node',
  target: ['node20'],
  format: 'cjs',
  outfile: 'dist/bundle.js',
  packages: 'external',
  external: ['dd-trace', 'express']
+  plugins: [ddPlugin],
}).catch((e) => {
  console.error(e);
  process.exit(1);
});
```

###### Bundling with Rollup{% #bundling-with-rollup-1 %}

Use [rollup-plugin-inject-process-env](https://www.npmjs.com/package/rollup-plugin-inject-process-env) to inject `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` in your runtime bundle. Run the bundle step inside a Git repository so the script can read `.git/` information.

```diff
+ const injectProcessEnv = require('rollup-plugin-inject-process-env');

+ const { DD_GIT_REPOSITORY_URL, DD_GIT_COMMIT_SHA } = getGitInfo();

module.exports = {
  input: 'index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'cjs'
  },
  external: [
    'express',
    'dd-trace'
  ],
  plugins: [
    nodeResolve(),
    commonjs()
+    injectProcessEnv({
+       DD_GIT_REPOSITORY_URL,
+       DD_GIT_COMMIT_SHA
+    })
  ]
};
```

The `getGitInfo()` function executes git commands to return `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` variables. It needs to be executed in the git repository.

```js
const { execSync } = require('child_process');

function getGitInfo() {
  try {
    const commitSha = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();
    const repositoryUrl = execSync('git config --get remote.origin.url', { encoding: 'utf8' }).trim();

    console.log('Build-time Git metadata:', {
      commitSha,
      repositoryUrl,
    });

    return {
      DD_GIT_REPOSITORY_URL: repositoryUrl,
      DD_GIT_COMMIT_SHA: commitSha,
    };
  } catch (error) {
    console.warn('Could not get Git metadata at build time:', error.message);
    return {
      DD_GIT_REPOSITORY_URL: '',
      DD_GIT_COMMIT_SHA: '',
    };
  }
}
```

###### Bundling with webpack{% #bundling-with-webpack-1 %}

Use the [BannerPlugin](https://webpack.js.org/plugins/banner-plugin/) to inject `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` in your runtime bundle. Run the bundle step inside a Git repository so the script can read `.git/` information.

```diff
+ const webpack = require('webpack');

+ const { DD_GIT_REPOSITORY_URL, DD_GIT_COMMIT_SHA } = getGitInfo();

module.exports = {
	target: 'node',
	entry: './index.js',
	mode: 'production',
	output: {
		path: path.resolve(__dirname, 'dist'),
		filename: 'bundle.js',
		libraryTarget: 'commonjs2'
	},
	externals: [
		'express',
		'dd-trace'
	],
	plugins: [
+		new webpack.BannerPlugin({
+			raw: true,
+			entryOnly: true,
+			banner:
+        `process.env.DD_GIT_REPOSITORY_URL=${JSON.stringify(DD_GIT_REPOSITORY_URL)};` +
+				 `process.env.DD_GIT_COMMIT_SHA=${JSON.stringify(DD_GIT_COMMIT_SHA)};`,
+		}),
	]
};
```

The `getGitInfo()` function executes git commands to return `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` variables. It needs to be executed in the git repository.

```js
const { execSync } = require('child_process');

function getGitInfo() {
  try {
    const commitSha = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();
    const repositoryUrl = execSync('git config --get remote.origin.url', { encoding: 'utf8' }).trim();

    console.log('Build-time Git metadata:', {
      commitSha,
      repositoryUrl,
    });

    return {
      DD_GIT_REPOSITORY_URL: repositoryUrl,
      DD_GIT_COMMIT_SHA: commitSha,
    };
  } catch (error) {
    console.warn('Could not get Git metadata at build time:', error.message);
    return {
      DD_GIT_REPOSITORY_URL: '',
      DD_GIT_COMMIT_SHA: '',
    };
  }
}
```

#### Option 2: Datadog tooling{% #option-2-datadog-tooling %}

{% dl %}

{% dt %}
[Datadog CLI tool](https://www.npmjs.com/package/@datadog/datadog-ci)
{% /dt %}

{% dd %}
Use the `datadog-ci` client version 2.10.0 or later. You must run the CLI tool in the same directory as the code repository.
{% /dd %}

{% dt %}
[Datadog Serverless Plugin](https://docs.datadoghq.com/serverless/libraries_integrations/plugin/)
{% /dt %}

{% dd %}
Use the plugin version 5.60.0 or later.
{% /dd %}

{% dt %}
[Datadog CDK Construct](https://github.com/DataDog/datadog-cdk-constructs)
{% /dt %}

{% dd %}
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.
{% /dd %}

{% /dl %}

#### Option 3: `DD_GIT_*` environment variables{% #option-3-dd_git_-environment-variables-1 %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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{% #host %}

For host-based environments, you have two options based on your build and deploy configuration.

#### Option 1: Bundler plugin{% #option-1-bundler-plugin-2 %}

If you're bundling your application from a Git directory, you can use plugins to inject Git metadata into the runtime bundle.

###### Bundling with esbuild{% #bundling-with-esbuild-2 %}

Use the `dd-trace/esbuild` plugin to automatically inject `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` in your runtime bundle. See the plugin [documentation](https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/nodejs/#bundling-with-esbuild). Install `dd-trace` **v5.68.0 or later** for automatic Git tag injection.

```diff
const esbuild = require('esbuild');
+ const ddPlugin = require('dd-trace/esbuild');

esbuild.build({
  entryPoints: ['index.js'],
  bundle: true,
  platform: 'node',
  target: ['node20'],
  format: 'cjs',
  outfile: 'dist/bundle.js',
  packages: 'external',
  external: ['dd-trace', 'express']
+  plugins: [ddPlugin],
}).catch((e) => {
  console.error(e);
  process.exit(1);
});
```

###### Bundling with Rollup{% #bundling-with-rollup-2 %}

Use [rollup-plugin-inject-process-env](https://www.npmjs.com/package/rollup-plugin-inject-process-env) to inject `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` in your runtime bundle. Run the bundle step inside a Git repository so the script can read `.git/` information.

```diff
+ const injectProcessEnv = require('rollup-plugin-inject-process-env');

+ const { DD_GIT_REPOSITORY_URL, DD_GIT_COMMIT_SHA } = getGitInfo();

module.exports = {
  input: 'index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'cjs'
  },
  external: [
    'express',
    'dd-trace'
  ],
  plugins: [
    nodeResolve(),
    commonjs()
+    injectProcessEnv({
+       DD_GIT_REPOSITORY_URL,
+       DD_GIT_COMMIT_SHA
+    })
  ]
};
```

The `getGitInfo()` function executes git commands to return `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` variables. It needs to be executed in the git repository.

```js
const { execSync } = require('child_process');

function getGitInfo() {
  try {
    const commitSha = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();
    const repositoryUrl = execSync('git config --get remote.origin.url', { encoding: 'utf8' }).trim();

    console.log('Build-time Git metadata:', {
      commitSha,
      repositoryUrl,
    });

    return {
      DD_GIT_REPOSITORY_URL: repositoryUrl,
      DD_GIT_COMMIT_SHA: commitSha,
    };
  } catch (error) {
    console.warn('Could not get Git metadata at build time:', error.message);
    return {
      DD_GIT_REPOSITORY_URL: '',
      DD_GIT_COMMIT_SHA: '',
    };
  }
}
```

###### Bundling with webpack{% #bundling-with-webpack-2 %}

Use the [BannerPlugin](https://webpack.js.org/plugins/banner-plugin/) to inject `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` in your runtime bundle. Run the bundle step inside a Git repository so the script can read `.git/` information.

```diff
+ const webpack = require('webpack');

+ const { DD_GIT_REPOSITORY_URL, DD_GIT_COMMIT_SHA } = getGitInfo();

module.exports = {
	target: 'node',
	entry: './index.js',
	mode: 'production',
	output: {
		path: path.resolve(__dirname, 'dist'),
		filename: 'bundle.js',
		libraryTarget: 'commonjs2'
	},
	externals: [
		'express',
		'dd-trace'
	],
	plugins: [
+		new webpack.BannerPlugin({
+			raw: true,
+			entryOnly: true,
+			banner:
+        `process.env.DD_GIT_REPOSITORY_URL=${JSON.stringify(DD_GIT_REPOSITORY_URL)};` +
+				 `process.env.DD_GIT_COMMIT_SHA=${JSON.stringify(DD_GIT_COMMIT_SHA)};`,
+		}),
	]
};
```

The `getGitInfo()` function executes git commands to return `DD_GIT_REPOSITORY_URL` and `DD_GIT_COMMIT_SHA` variables. It needs to be executed in the git repository.

```js
const { execSync } = require('child_process');

function getGitInfo() {
  try {
    const commitSha = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();
    const repositoryUrl = execSync('git config --get remote.origin.url', { encoding: 'utf8' }).trim();

    console.log('Build-time Git metadata:', {
      commitSha,
      repositoryUrl,
    });

    return {
      DD_GIT_REPOSITORY_URL: repositoryUrl,
      DD_GIT_COMMIT_SHA: commitSha,
    };
  } catch (error) {
    console.warn('Could not get Git metadata at build time:', error.message);
    return {
      DD_GIT_REPOSITORY_URL: '',
      DD_GIT_COMMIT_SHA: '',
    };
  }
}
```

#### Option 2: `DD_GIT_*` environment variables{% #option-2-dd_git_-environment-variables %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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.
{% /tab %}

{% tab title="Ruby" %}

{% alert level="info" %}
The Ruby client library version 1.6.0 or later is required.
{% /alert %}

### Containers{% #containers %}

If you are using Docker containers, you have two options: using Docker or configuring your application with the `DD_TAGS` environment variable.

#### Option 1: Docker{% #option-1-docker %}

You can embed git information in your Docker image using either build arguments with environment variables, or image labels.

###### Using build arguments and environment variables{% #using-build-arguments-and-environment-variables %}

1. Add the following lines to your application's Dockerfile:

   ```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}"
   ```

1. Add the following arguments to your Docker build command:

   ```shell
   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)
   ```

###### Using image labels{% #using-image-labels %}

This approach requires Docker, or containerd >= 1.5.6. It doesn't support containers running on AWS Fargate.

Datadog can extract source code information directly from your images' Docker labels. During build time, follow the [Open Containers standard](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys) to add the git commit SHA and repository URL as Docker labels:

```shell
docker build . \
  -t my-application \
  --label org.opencontainers.image.revision=$(git rev-parse HEAD) \
  --label org.opencontainers.image.source=$(git config --get remote.origin.url)
```

#### Option 2: `DD_TAGS` environment variable{% #option-2-dd_tags-environment-variable %}

Configure your application with the `DD_TAGS` environment variable:

```ruby
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.

### Serverless{% #serverless %}

If you are using Serverless, you have two options depending on your serverless application's setup.

#### Option 1: Datadog tooling{% #option-1-datadog-tooling %}

{% dl %}

{% dt %}
[Datadog CLI tool](https://www.npmjs.com/package/@datadog/datadog-ci)
{% /dt %}

{% dd %}
Use the `datadog-ci` client version 2.10.0 or later. You must run the CLI tool in the same directory as the code repository.
{% /dd %}

{% dt %}
[Datadog Serverless Plugin](https://docs.datadoghq.com/serverless/libraries_integrations/plugin/)
{% /dt %}

{% dd %}
Use the plugin version 5.60.0 or later.
{% /dd %}

{% dt %}
[Datadog CDK Construct](https://github.com/DataDog/datadog-cdk-constructs)
{% /dt %}

{% dd %}
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.
{% /dd %}

{% /dl %}

#### Option 2: `DD_TAGS` environment variable{% #option-2-dd_tags-environment-variable-1 %}

Configure your application with the `DD_TAGS` environment variable:

```ruby
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.

### Host{% #host %}

If you are using a host, configure your application with the `DD_TAGS` environment variable.

Configure your application with the `DD_TAGS` environment variable:

```ruby
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.
{% /tab %}

{% tab title="Java" %}

{% alert level="info" %}
The Java client library version 1.48.0 or later is required for embedded git properties. Version 1.12.0 or later is required for other options.
{% /alert %}

### Containers{% #containers %}

If you are using Docker containers, you have three options: embedding git properties in your build artifact, using Docker, or configuring your application with `DD_GIT_*` environment variables.

#### Option 1: Embedded git properties (recommended){% #option-1-embedded-git-properties-recommended %}

If you use Spring Boot, add a build plugin to embed git information in your JAR. The Datadog Java tracer reads the `git.properties` file that Spring Boot Actuator generates at startup.

**Maven**

Add the following plugin to your `pom.xml`:

```xml
<plugin>
    <groupId>io.github.git-commit-id</groupId>
    <artifactId>git-commit-id-maven-plugin</artifactId>
    <version>9.0.2</version>
    <executions>
        <execution>
            <id>get-the-git-infos</id>
            <goals>
                <goal>revision</goal>
            </goals>
            <phase>initialize</phase>
        </execution>
    </executions>
    <configuration>
        <generateGitPropertiesFile>true</generateGitPropertiesFile>
        <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
        <commitIdGenerationMode>full</commitIdGenerationMode>
    </configuration>
</plugin>
```

**Gradle**

Add the following to your `build.gradle.kts`:

```kotlin
plugins {
    id("org.springframework.boot") version "2.5.7" // required
    // ...
    id("com.gorylenko.gradle-git-properties") version "2.5.7"
}
```

{% alert level="warning" %}
Both plugins require access to the `.git` folder at build time.
{% /alert %}

#### Option 2: Docker{% #option-2-docker %}

You can embed git information in your Docker image using either build arguments with environment variables, or image labels.

###### Using build arguments and environment variables{% #using-build-arguments-and-environment-variables %}

1. Add the following lines to your application's Dockerfile:

   ```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}
   ```

1. Add the following arguments to your Docker build command:

   ```shell
   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)
   ```

###### Using image labels{% #using-image-labels %}

This approach requires Docker, or containerd >= 1.5.6. It doesn't support containers running on AWS Fargate.

Datadog can extract source code information directly from your images' Docker labels. During build time, follow the [Open Containers standard](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys) to add the git commit SHA and repository URL as Docker labels:

```shell
docker build . \
  -t my-application \
  --label org.opencontainers.image.revision=$(git rev-parse HEAD) \
  --label org.opencontainers.image.source=$(git config --get remote.origin.url)
```

#### Option 3: `DD_GIT_*` environment variables{% #option-3-dd_git_-environment-variables %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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.

### Serverless{% #serverless %}

If you are using Serverless, you have three options depending on your serverless application's setup.

#### Option 1: Embedded git properties (recommended){% #option-1-embedded-git-properties-recommended-1 %}

If you use Spring Boot, add a build plugin to embed git information in your JAR. The Datadog Java tracer reads the `git.properties` file that Spring Boot Actuator generates at startup.

**Maven**

Add the following plugin to your `pom.xml`:

```xml
<plugin>
    <groupId>io.github.git-commit-id</groupId>
    <artifactId>git-commit-id-maven-plugin</artifactId>
    <version>9.0.2</version>
    <executions>
        <execution>
            <id>get-the-git-infos</id>
            <goals>
                <goal>revision</goal>
            </goals>
            <phase>initialize</phase>
        </execution>
    </executions>
    <configuration>
        <generateGitPropertiesFile>true</generateGitPropertiesFile>
        <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
        <commitIdGenerationMode>full</commitIdGenerationMode>
    </configuration>
</plugin>
```

**Gradle**

Add the following to your `build.gradle.kts`:

```kotlin
plugins {
    id("org.springframework.boot") version "2.5.7" // required
    // ...
    id("com.gorylenko.gradle-git-properties") version "2.5.7"
}
```

{% alert level="warning" %}
Both plugins require access to the `.git` folder at build time.
{% /alert %}

#### Option 2: Datadog tooling{% #option-2-datadog-tooling %}

{% dl %}

{% dt %}
[Datadog CLI tool](https://www.npmjs.com/package/@datadog/datadog-ci)
{% /dt %}

{% dd %}
Use the `datadog-ci` client version 2.10.0 or later. You must run the CLI tool in the same directory as the code repository.
{% /dd %}

{% dt %}
[Datadog Serverless Plugin](https://docs.datadoghq.com/serverless/libraries_integrations/plugin/)
{% /dt %}

{% dd %}
Use the plugin version 5.60.0 or later.
{% /dd %}

{% dt %}
[Datadog CDK Construct](https://github.com/DataDog/datadog-cdk-constructs)
{% /dt %}

{% dd %}
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.
{% /dd %}

{% /dl %}

#### Option 3: `DD_GIT_*` environment variables{% #option-3-dd_git_-environment-variables-1 %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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{% #host %}

If you are using a host, you have two options.

#### Option 1: Embedded git properties (recommended){% #option-1-embedded-git-properties-recommended-2 %}

If you use Spring Boot, add a build plugin to embed git information in your JAR. The Datadog Java tracer reads the `git.properties` file that Spring Boot Actuator generates at startup.

**Maven**

Add the following plugin to your `pom.xml`:

```xml
<plugin>
    <groupId>io.github.git-commit-id</groupId>
    <artifactId>git-commit-id-maven-plugin</artifactId>
    <version>9.0.2</version>
    <executions>
        <execution>
            <id>get-the-git-infos</id>
            <goals>
                <goal>revision</goal>
            </goals>
            <phase>initialize</phase>
        </execution>
    </executions>
    <configuration>
        <generateGitPropertiesFile>true</generateGitPropertiesFile>
        <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
        <commitIdGenerationMode>full</commitIdGenerationMode>
    </configuration>
</plugin>
```

**Gradle**

Add the following to your `build.gradle.kts`:

```kotlin
plugins {
    id("org.springframework.boot") version "2.5.7" // required
    // ...
    id("com.gorylenko.gradle-git-properties") version "2.5.7"
}
```

{% alert level="warning" %}
Both plugins require access to the `.git` folder at build time.
{% /alert %}

#### Option 2: `DD_GIT_*` environment variables{% #option-2-dd_git_-environment-variables %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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.
{% /tab %}

{% tab title="PHP" %}

{% alert level="info" %}
PHP client library version 1.13.0 or later is required, or 1.2.0 or later if using tracing only without profiling.
{% /alert %}

### Containers{% #containers %}

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

#### Option 1: Docker{% #option-1-docker %}

You can embed git information in your Docker image using either build arguments with environment variables, or image labels.

###### Using build arguments and environment variables{% #using-build-arguments-and-environment-variables %}

1. Add the following lines to your application's Dockerfile:

   ```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}
   ```

1. Add the following arguments to your Docker build command:

   ```shell
   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)
   ```

###### Using image labels{% #using-image-labels %}

This approach requires Docker, or containerd >= 1.5.6. It doesn't support containers running on AWS Fargate.

Datadog can extract source code information directly from your images' Docker labels. During build time, follow the [Open Containers standard](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys) to add the git commit SHA and repository URL as Docker labels:

```shell
docker build . \
  -t my-application \
  --label org.opencontainers.image.revision=$(git rev-parse HEAD) \
  --label org.opencontainers.image.source=$(git config --get remote.origin.url)
```

#### Option 2: `DD_GIT_*` environment variables{% #option-2-dd_git_-environment-variables %}

Configure your application with the `DD_GIT_*` environment variables:

```go
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{% #host %}

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

Configure your application with the `DD_GIT_*` environment variables:

```go
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.
{% /tab %}

## Build inside a Docker container{% #build-inside-a-docker-container %}

If your build process is executed in CI within a Docker container, use a [named context](https://docs.docker.com/build/concepts/context/#named-contexts) to make your `.git` folder available at build time:

1. Add your `.git` folder as a named build context:

   ```shell
   docker build [...] --build-context dotgit=<path to your local .git folder>
   ```

1. In your `Dockerfile`, mount the `.git` folder before running your build:

   ```dockerfile
   RUN --mount=from=dotgit,target=<path to where you expect .git to be in your build container> <your build command>
   ```

## Configure telemetry tagging{% #configure-telemetry-tagging %}

For unsupported languages, use the `git.commit.sha` and `git.repository_url` tags to link data to a specific commit.

## Further reading{% #further-reading %}

- [Learn about APM](https://docs.datadoghq.com/tracing/)
- [Learn about Datadog Tracing Libraries](https://docs.datadoghq.com/tracing/trace_collection/dd_libraries/)
