Datadog Source Code Integration
Overview
The source code integration supports:Languages:
- Go
- Java
- JavaScript (doesn't support transpiled JavaScript)
- Python
Git providers:
- GitHub
- GitLab
- BitBucket
- Azure DevOps
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, Bitbucket, or Azure DevOps. 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.
Link active commits
You can link active commits by either tagging your telemetry or embedding git information in the deployed artifact.
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.com/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
Host tab.
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.
Datadog can extract source code information directly from your serverless application according to your Serverless Monitoring for AWS Lambda setup.
APM Serverless Setup | Method Description |
---|
Datadog Serverless Framework Plugin | If you are using the Datadog Serverless Plugin to instrument your serverless application, use a serverless-plugin-datadog version >= 5.18.0 . |
datadog-cdk-constructs | If you are using the Datadog CDK Construct to instrument your serverless application, use a datadog-cdk-constructs version >= 0.8.5 for AWS CDK v1, and datadog-cdk-constructs-v2 version >= 1.4.0 for AWS CDK v2. |
datadog-ci | If you are using the Datadog CLI client to instrument your serverless application, use a datadog-ci version >= 2.4.1 . You must run the CLI tool in the same directory as the code repository. |
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.
You can embed git information such as the repository URL and commit hash in your artifact. The Datadog Tracing Libraries use this information to automatically link the active commit to your APM service.
Select one of the following languages that supports embedding git information:
Go embeds version control information in binaries starting in version 1.18.
Ensure your service meets all the following requirements:
- You are using a version of Go >= 1.18.
- You are using a version of the Datadog Go Tracer >= 1.48.0.
- Your application was built as a module using
go.mod
, and the module path is your code repository’s URL.
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
Additional helpful documentation, links, and articles: