Datadog Source Code Integration

Overview

The source code integration supports:

Languages:
  • Go
  • Java
  • JavaScript (doesn't support transpired JavaScript)
  • Python

Git providers:
  • GitHub
  • GitLab
  • BitBucket

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.

Inline code snippet of a Java RuntimeException with a button to view the code in GitHub

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.

Configure your repositories

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

You can directly access a trace in its source repository on GitHub in Error Tracking.

  1. Navigate to APM > Error Tracking.
  2. Click on an issue. The Issue Details panel appears on the right.
  3. 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.
A view repository button with three options (view file, view blame, and view commit) available on the right side of an error stack trace in Error Tracking

You can directly access a trace in its source repository on GitHub in the Continuous Profiler.

  1. Navigate to APM > Profile Search.
  2. 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.
  3. Click More actions > View in repo to open the trace in its source code repository.
Link to GitHub from the Continuous Profiler

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.

  1. Navigate to APM > Error Tracking.
  2. Click on an issue. The Issue Details panel appears on the right.
  3. Click Connect to Preview and Authorize to access the source code snippet containing the error.
  4. 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.
An inline code snippet in a stack trace

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