Datadog Source Code Integration
Overview
The source code integration is an integration with Git that enables you to link your telemetry (such as stack traces) with your source code.
Combined with the GitHub Apps integrations, you can see inline code snippets in your errors. For more information, see Inline Source Code.
Integration Name | Stack Trace Links | Issue and PR Previews | Inline Code Snippets |
---|
Source Code | | X | X |
GitHub Apps | X | | X |
Source Code and GitHub Apps | | | |
Configuration
The source code integration supports Go and all JVM languages.
Datadog Agent 7.35.0 or higher is required.
To map telemetry data with your source code:
- Add
git.commit.sha
and git.repository_url
tags to your containers, or directly on your telemetry. - Upload metadata about your git repository by running
datadog-ci git-metadata upload
in your CI pipeline. - Optionally, install a GitHub App to display inline source code snippets.
Tag your telemetry
To link data to a specific commit, tag your telemetry with a git.commit.sha
tag.
This approach requires Docker, or containerd >= 1.5.6. For other 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=https://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": "<REPOSITORY_URL>"}'
The git commit SHA and repository URL are added to your telemetry.
For non-containerized or unsupported environments, manually tag your traces, spans, and profiles with the git commit SHA and repository URL.
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:<GIT_COMMIT_SHA> git.repository_url=<REPOSITORY_URL>"
./my-application start
In order to link your telemetry to your source code, Datadog collects information 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:DataDog/datadog-ci.git.
180 tracked file paths will be reported.
✅ Handled in 0.077 seconds.
Links to Git
Stack traces
In Error Tracking and on APM error spans, you can directly access links to repositories from your stack traces.
- Navigate to APM > Error Tracking.
- Click on an issue. The Issue Details panel appears to the right.
- Under Latest available errors, hover over a frame. The View button appears to the right and directs you to GitHub.
Inline source code
If you are a GitHub SaaS user, install Datadog’s GitHub Apps integration to directly inline code snippets from your GitHub repository in your stack traces.
When specifying your permissions in the integration tile, enable Datadog read permissions to Contents.
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.
- Click on a frame to expand the code snippet containing lines of your source code.
- Click Connect to Preview and Authorize to access the source code snippet containing the error.
Continuous Profiler
In the Continuous Profiler, you can directly access traces in the source repository on GitHub.
- 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 to the right.
- Click More actions > View in repo to open the source code repository.
Further Reading
Additional helpful documentation, links, and articles: