![]() |
VOOZH | about |
For large monorepos containing multiple projects or components, or where multiple teams collaborate, viewing code coverage data for the entire repository may not provide actionable insights. Code Coverage supports splitting coverage data by services and code owners, allowing you to:
Code Coverage automatically calculates separate coverage metrics for each service and code owner based on the file paths that belong to that service or are owned by that team.
Code Coverage provides two ways to split coverage data in a monorepo:
Automatically split coverage by code owner teams based on the CODEOWNERS file in your repository.
These methods can be used together. Service splitting and code owner splitting work independently—you can have coverage split by both services and code owners simultaneously. For service definitions, Catalog integration takes priority over manual configuration. Coverage is calculated for up to 200 services and code owners per coverage report, with a total limit of 2000 services across your organization.
If you use Catalog, Code Coverage automatically uses the codeLocations attribute from your service definitions to calculate coverage for each service.
When you define services in Catalog with codeLocations pointing to your repository, Code Coverage automatically:
No additional configuration is needed in your repository.
service.datadog.yml
apiVersion:v3kind:servicemetadata:name:checkout-servicedatadog:codeLocations:- repositoryURL:https://github.com/my-org/my-monorepo.gitpaths:- services/checkout/**- shared/payment/**- shared/cart/**See the Service Definition documentation for complete details on the service definition format and available options.
Code Coverage can automatically split coverage data based on the CODEOWNERS file in your repository. Code owner splitting works independently from service splitting—coverage can be split by both services and code owners simultaneously.
When a CODEOWNERS file is present, Code Coverage:
This happens automatically without requiring any configuration file.
CODEOWNERS file must exist in your repository (typically at .github/CODEOWNERS, docs/CODEOWNERS, or CODEOWNERS in the root)To manually define services, add a services section to the code-coverage.datadog.yml file in your repository. See Configuration for file format details, configuration options, pattern syntax, and examples.
After services or code owners are configured, coverage data becomes available filtered by service or code owner for any coverage reports uploaded after the configuration changes.
On the Branch overview, Pull Request details, and Commit details pages in Code Coverage UI, use the Code Owner or Service selector dropdown at the top to:
You can configure PR Gates to enforce coverage thresholds for specific services or code owners.
You can also define service- or code owner-scoped gates directly in your code-coverage.datadog.yml file using the services and codeowners fields:
code-coverage.datadog.yml
schema-version:v1gates:- type:patch_coverage_percentageconfig:threshold:90services:- "*"- type:patch_coverage_percentageconfig:threshold:95codeowners:- "@DataDog/backend-team"- "@DataDog/api-*"Gates defined in the YAML file and in the Datadog UI are both evaluated when a pull request is opened or updated. See PR Gates configuration instructions for the complete YAML syntax and additional examples.
Enforce high coverage for backend services:
80%backend-*Require all new code in frontend to be tested:
100%admin-dashboard, frontend-*Enforce coverage for specific team’s code:
90%@team/platformYou can create multiple gates for the same repository, each applying to different services or code owners. This allows you to enforce different coverage standards for different parts of your monorepo or for different teams.
When using Catalog integration, changes to service definitions in Catalog may take up to 10 minutes to synchronize with Code Coverage. After creating or updating service definitions in Catalog:
codeLocations with the correct repositoryURL.codeLocations match the actual file structure.Catalog is queried when processing coverage reports, so changes only take effect for newly uploaded reports.
If manually configured services don’t appear in the UI:
code-coverage.datadog.yml file is at the repository root.The configuration file is read when processing coverage reports, so changes only take effect for newly uploaded reports.
Check that:
If paths in coverage reports are relative to a subdirectory, use the --base-path option when uploading:
datadog-ci coverage upload --base-path=src .Code Coverage has the following limits:
If you exceed these limits, coverage is not calculated for services or code owners beyond the limit.
To stay within limits:
Confirm that:
CODEOWNERS file exists in the standard location (.github/CODEOWNERS, docs/CODEOWNERS, or CODEOWNERS in the root)CODEOWNERS file was added or updatedAdditional helpful documentation, links, and articles:
| |