Se requiere la biblioteca del cliente Go versión 1.48.0 o posterior.
Contenedores
Si utilizas contenedores Docker, tienes tres opciones: utilizar Docker, utilizar la biblioteca de rastreo de Datadog o configurar tu aplicación con variables de entorno DD_GIT_*.
Opción 1: Docker
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}
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)
Opción 2: Biblioteca de rastreo de 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.
Opción 3: Variables de entorno 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.
Serverless
Si utilizas la opción serverless, tienes tres opciones en función de la configuración de tu aplicación serverless.
Opción 1: Herramientas de Datadog
- Datadog CLI tool
- 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. - Datadog Serverless Plugin
- Use the plugin version 5.60.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.
Opción 2: Biblioteca de rastreo de 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.
Opción 3: Variables de entorno 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.
Host
Si utilizas un host, tienes dos opciones.
Opción 1: Biblioteca de rastreo de 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.
Opción 2: Variables de entorno 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.
Se requiere la biblioteca del cliente Python versión 1.12.0 o posterior.
Contenedores
Si utilizas contenedores Docker, tienes tres opciones: utilizar Docker, utilizar la biblioteca de rastreo de Datadog o configurar tu aplicación con variables de entorno DD_GIT_*.
Opción 1: Docker
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}
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)
Opción 2: Herramientas de configuración o archivo de parámetros unificados del proyecto Python
If your application is packaged with setuptools:
- Install the
dd-trace package. - Add
import ddtrace.sourcecode.setuptools_auto as the first import to the setup.py file. - 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:
- 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. - Set the
DD_MAIN_PACKAGE environment variable as the name of the primary Python package.
Opción 3: Variables de entorno 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.
Serverless
Si utilizas la opción serverless, tienes tres opciones en función de la configuración de tu aplicación serverless.
Opción 1: Herramientas de Datadog
- Datadog CLI tool
- 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. - Datadog Serverless Plugin
- Use the plugin version 5.60.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.
Opción 2: Herramientas de configuración o archivo de parámetros unificados del proyecto Python
If your application is packaged with setuptools:
- Install the
dd-trace package. - Add
import ddtrace.sourcecode.setuptools_auto as the first import to the setup.py file. - 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:
- 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. - Set the
DD_MAIN_PACKAGE environment variable as the name of the primary Python package.
Opción 3: Variables de entorno 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.
Host
Si utilizas un host, tienes dos opciones.
Opción 1: Herramientas de configuración o archivo de parámetros unificados del proyecto Python
If your application is packaged with setuptools:
- Install the
dd-trace package. - Add
import ddtrace.sourcecode.setuptools_auto as the first import to the setup.py file. - 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:
- 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. - Set the
DD_MAIN_PACKAGE environment variable as the name of the primary Python package.
Opción 2: Variables de entorno 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.
Se requiere la biblioteca del cliente .NET versión 2.24.1 o posterior.
Como primer paso, asegúrate de que tus archivos .pdb se despliegan junto con tus ensamblados .NET (.dll o .exe) en la misma carpeta.
A continuación, sigue el resto de las instrucciones en función de tu modelo de despliegue específico:
Contenedores
Si utilizas contenedores Docker, tienes tres opciones: utilizar Docker, utilizar la biblioteca de rastreo de Datadog o configurar tu aplicación con variables de entorno DD_GIT_*.
Opción 1: Docker
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}
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)
Opción 2: Microsoft SourceLink
If you are using Microsoft SourceLink, Datadog can extract the git commit SHA and repository URL from your .NET assembly.
- 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:
Opción 3: Variables de entorno 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.
Serverless
Si utilizas la opción serverless, tienes tres opciones en función de la configuración de tu aplicación serverless.
Opción 1: Herramientas de Datadog
- Datadog CLI tool
- 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. - Datadog Serverless Plugin
- Use the plugin version 5.60.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.
Opción 2: Microsoft SourceLink
If you are using Microsoft SourceLink, Datadog can extract the git commit SHA and repository URL from your .NET assembly.
- 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:
Opción 3: Variables de entorno 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.
Host
Si utilizas un host, tienes dos opciones: utilizar Microsoft SourceLink o configurar tu aplicación con variables de entorno DD_GIT_*.
Opción 1: Microsoft SourceLink
If you are using Microsoft SourceLink, Datadog can extract the git commit SHA and repository URL from your .NET assembly.
- 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:
Opción 2: Variables de entorno 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.
Se requiere la biblioteca de cliente de Node.js versión 3.21.0 o posterior.Para aplicaciones de Node.js transpiladas (por ejemplo, TypeScript), asegúrate de generar y publicar mapas de fuentes con la aplicación desplegada, y de ejecutar Node.js con la opción
--enable-source-maps. De lo contrario, los enlaces de código y fragmentos no funcionarán.
Contenedores
Si utilizas contenedores de Docker, tienes varias opciones: utilizar un complemento si tu aplicación está empaquetada, utilizar Docker, o configurar tu aplicación con variables de entorno DD_GIT_*.
Opción 1: Complemento empaquetador
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
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.
Install dd-trace v5.68.0 or later for automatic Git tag injection.
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
Use 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.
+ 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.
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
Use the BannerPlugin 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.
+ 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.
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: '',
};
}
}
Opción 2: Docker
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}
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)
Opción 3: Variables de entorno 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.
Serverless
Si estás utilizando Serverless, tienes varias opciones dependiendo de la configuración de tu aplicación serverless.
Opción 1: Complemento empaquetador
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
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.
Install dd-trace v5.68.0 or later for automatic Git tag injection.
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
Use 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.
+ 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.
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
Use the BannerPlugin 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.
+ 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.
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: '',
};
}
}
Opción 2: Herramientas de Datadog
- Datadog CLI tool
- 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. - Datadog Serverless Plugin
- Use the plugin version 5.60.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.
Opción 3: Variables de entorno 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.
Host
Para entornos basados en host, tienes dos opciones basadas en tu configuración de compilación y despliegue.
Opción 1: Complemento empaquetador
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
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.
Install dd-trace v5.68.0 or later for automatic Git tag injection.
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
Use 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.
+ 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.
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
Use the BannerPlugin 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.
+ 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.
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: '',
};
}
}
Opción 2: Variables de entorno 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.
Se requiere la biblioteca del cliente Ruby versión 1.6.0 o posterior.
Contenedores
Si utilizas contenedores Docker, tienes dos opciones: utilizar Docker o configurar tu aplicación con la variable de entorno DD_TAGS.
Opción 1: Docker
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}"
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)
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.
Serverless
Si utilizas la opción serverless, tienes dos opciones en función de la configuración de tu aplicación serverless.
Opción 1: Herramientas de Datadog
- Datadog CLI tool
- 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. - Datadog Serverless Plugin
- Use the plugin version 5.60.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.
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.
Host
Si utilizas un host, configura tu aplicación con la variable de entorno 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.