Datadog Source Code Integration
Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel,
n'hésitez pas à nous contacter.
Overview
The source code integration supports:Languages:
- Go
- Java
- JavaScript (doesn't support transpiled JavaScript)
- Python
Git providers:
Self-hosted instances or private URLs are not supported.
Datadog’s source code integration allows you to connect your telemetry with your Git repositories hosted in GitHub, GitLab, or Bitbucket. Once you have enabled the source code integration, you can debug stack traces, slow profiles, and other issues by quickly accessing the relevant lines of your source code.
Setup
Datadog Agent v7.35.0 or later is required.
If you have APM set up already, navigate to Integrations > Link Source Code and configure the source code integration for your backend services.
Tag your telemetry
To link data to a specific commit, tag your telemetry with git.commit.sha
and git.repository_url
tags. Ensure that the git.repository_url
tag does not contain protocols. For example, if your repository URL is https://github.con/example_repo
, the value for the git.repository_url
tag should be github.com/example_repo
.
This approach requires Docker, or containerd >= 1.5.6. It doesn't support containers running on AWS Fargate.
For additional container setups, see the
Other section.
If you are running your app in containers, Datadog can extract source code information directly from your images’ Docker labels. During build time, follow the Open Containers standard to add the git commit SHA and repository URL as Docker labels:
docker build . \
-t my-application \
--label org.opencontainers.image.revision=$(git rev-parse HEAD) \
--label org.opencontainers.image.source=git-provider.example/me/my-repo
If you use Kubernetes, tag your deployed pod with a pod annotation using Datadog’s Tag Autodiscovery:
ad.datadoghq.com/tags: '{"git.commit.sha": "<FULL_GIT_COMMIT_SHA>", "git.repository_url": "git-provider.example/me/my-repo"}'
The git.commit.sha
and git.repository_url
are tagged in your telemetry.
To tag your traces, spans, and profiles with git.commit.sha
and git.repository_url
, configure the tracer with the DD_TAGS
environment variable:
export DD_TAGS="git.commit.sha:<FULL_GIT_COMMIT_SHA>,git.repository_url:git-provider.example/me/my-repo"
./my-application start
Datadog only captures the repository URL, the commit SHA of the current branch, and a list of tracked file paths—Datadog does not ingest or store any user code.
If you are a GitHub SaaS user, install Datadog’s GitHub integration on the GitHub integration tile to link your telemetry with your source code. When specifying permissions on the integration tile, enable Datadog read permissions to Contents.
By setting up the GitHub integration, you can see inline code snippets in Error Tracking. For more information, see Inline Source Code.
To link telemetry to your source code, Datadog collects metadata for every commit SHA from your Git repository 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.
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@github.com:my-org/my-repository.git.
180 tracked file paths will be reported.
✅ Handled in 0.077 seconds.
Usage
Links to Git providers
You can directly access a trace in its source repository on GitHub in Error Tracking.
- Navigate to APM > Error Tracking.
- Click on an issue. The Issue Details panel appears on the right.
- 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.
You can directly access a trace in its source repository on GitHub in the Continuous Profiler.
- Navigate to APM > Profile Search.
- Click on a profile and hover your cursor over a method in the flamegraph. A kebab icon with the More actions label appears on the right.
- Click More actions > View in repo to open the trace in its source code repository.
Inline source code
If you are a GitHub SaaS user, install Datadog’s GitHub integration to directly inline code snippets from your GitHub repository in your stack traces in Error Tracking. When specifying permissions on the integration tile, enable Datadog read permissions to Contents.
- Navigate to APM > Error Tracking.
- Click on an issue. The Issue Details panel appears on the right.
- Click Connect to Preview and Authorize to access the source code snippet containing the error.
- Under Latest Event, click the View Code 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.
To install a GitHub App for your organization, you need to be an organization owner or have admin permissions in a repository. You can also install a GitHub App on your personal GitHub account. For more information, see GitHub Apps & OAuth Apps.
Further Reading
Documentation, liens et articles supplémentaires utiles: