This product is not supported for your selected Datadog site. ().
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.
Join the Preview!
Code Coverage is in Preview. This product replaces Test Optimization's code coverage feature, which is being deprecated. Complete the form to request access for the new Code Coverage product.
Code Coverage requires the following GitHub App permissions:
Permission
Access Level
Purpose
Contents
Read
Show source code in the detailed coverage UI.
Pull Requests
Write
Show PR data in coverage UI and write PR comments.
Checks
Write
Create coverage PR Gates.
The following webhooks are required:
Webhook
Purpose
Pull request
Receive PR data updates.
Pull request review
Receive PR data updates.
Pull request review comment
Receive PR data updates.
Push
Receive Git commit metadata.
If everything is configured correctly, a green check mark is displayed in Datadog’s GitHub Integration page:
If you have a Datadog-managed Marketplace App or a custom app with default settings, the required permissions and webhooks are included.
See Data Collected for details on what data is collected from your source code provider.
Data access permissions
If you are using custom roles rather than Datadog-managed roles, be sure to enable the Code Coverage Read permission for the roles that need to view code coverage data.
Navigate to Roles settings, click Edit on the role you need, add the Code Coverage Read permission to the role, and save the changes.
PR Gates
If you wish to gate on PR coverage, configure PR Gates rules in Datadog.
Navigate to PR Gates rule creation and configure a rule to gate on total or patch coverage.
Upload code coverage reports
Update your CI pipeline to upload code coverage report files to Datadog. This involves installing and running the datadog-ci CLI in your CI environment.
See Data Collected for details on what data is collected during code coverage report upload.
Supported coverage report formats
Datadog supports the following coverage data formats—expand for examples:
If installing Node.js in the CI is an issue, standalone binaries are provided with Datadog CI releases. Only linux-x64, linux-arm64, darwin-x64, darwin-arm64 (MacOS) and win-x64 (Windows) are supported. To install, run the following from your terminal:
Datadog automatically aggregates all reports for the same commit on the backend. You don't need to merge coverage reports before uploading them.
To upload your code coverage reports to Datadog, run the following command. Provide a valid Datadog API key (DD_API_KEY), and one or more file paths to either the coverage report files directly or directories containing them:
The command recursively searches the specified directories for supported coverage report files, so specifying the current directory (.) is usually sufficient.
See the datadog-ci documentation for more details on the datadog-ci coverage upload command.
Shortly after the code coverage report upload is finished, Datadog adds a PR comment with code coverage percentage values.
You can also view your coverage data aggregated by pull request in the Code Coverage page in Datadog, with the ability to examine individual files and lines of code.
Troubleshooting
Coverage upload command does not detect your coverage report files
The datadog-ci coverage upload command automatically detects supported coverage report files in the specified directories using heuristics, such as file names and extensions.
If your coverage report files do not match expected patterns, the command might not detect them automatically. In this case, specify the report format and provide the file paths as positional arguments. For example:
Coverage upload fails with “Format could not be detected” error
The datadog-ci coverage upload command automatically detects the format of the coverage report files based on their content and file extension.
If the command fails with the following error:
Invalid coverage report file [...]: format could not be detected
specify the format explicitly using the --format option, like this:
Coverage upload outputs “Could not sync git metadata” error
Git metadata upload is only required if you can’t integrate your CI provider directly with Datadog.
If you are using a source code provider integration, such as Datadog GitHub app or Gitlab integration, you can disable the git metadata upload by passing the --skip-git-metadata-upload=1 flag to the datadog-ci coverage upload command, like this:
Discrepancy between Datadog UI and coverage report values
Datadog automatically merges coverage reports for the same commit.
As a result, the coverage percentage displayed in the Datadog UI may differ from the values in your individual coverage reports, especially if those reports contain overlapping or duplicate source code file entries.
If you use an external tool (such as ReportGenerator) to merge coverage reports before uploading to Datadog,
ensure your merged reports do not contain duplicate source code file entries.
Datadog deduplicates overlapping files across reports, which can result in differences between your original coverage values and the merged values displayed in the Datadog UI.
Further reading
Documentation, liens et articles supplémentaires utiles: