![]() |
VOOZH | about |
Flags in Code Coverage let you organize and filter coverage data by custom categories. Use flags to separate coverage reports by test type (unit, integration, end-to-end), runtime version (JVM 17, JVM 21), or any other criteria relevant to your project.
With flags, you can:
Code Coverage provides two complementary ways to filter coverage data:
For example, the same source file might be covered by both unit tests and integration tests. Monorepo support features cannot distinguish between these because they operate on file paths. Flags allow you to track unit test coverage and integration test coverage separately by tagging each report with a flag indicating the test type or runtime version.
Datadog automatically merges coverage reports for the same commit. When using flags:
When a report is tagged with multiple flags, its coverage data is merged into each flag independently. Consider the following example where three reports are uploaded for the same commit:
| Report | Flags |
|---|---|
| Report A | unit-tests, jvm-11 |
| Report B | unit-tests, jvm-17 |
| Report C | integration-tests, jvm-11 |
The resulting coverage data for each flag is:
| Flag | Contains data from |
|---|---|
unit-tests | Report A + Report B |
integration-tests | Report C |
jvm-11 | Report A + Report C |
jvm-17 | Report B |
| Overall (no flag filter) | Report A + Report B + Report C |
This allows you to answer questions like “What is my unit test coverage?” (unit-tests flag) or “What is my coverage on JVM 11?” (jvm-11 flag) from the same set of uploaded reports.
--flags argument is available in datadog-ci v5.6.0 and later.To add flags to a coverage report, use the --flags option when uploading with the datadog-ci CLI:
datadog-ci coverage upload --flags unit-tests coverage-unit.xmlA single report can have multiple flags, allowing you to slice coverage data in different ways:
datadog-ci coverage upload --flags unit-tests --flags jvm-21 coverage.xmlIn this example, the coverage data is available under both the unit-tests and jvm-21 flags. You can filter by either flag in the UI.
-), underscores (_), periods (.), and colons (:).In the Code Coverage UI, select a repository and use the Flag filter to view coverage data for a specific flag. This filter appears alongside the Code Owner and Service filters.
When you select a flag, the coverage metrics update to show only the data from reports tagged with that flag.
You can configure PR Gates to enforce coverage thresholds for specific flags. This allows you to enforce different coverage requirements for different test types or runtime versions.
You can create flag-specific gates in one of two ways:
flags field in your code-coverage.datadog.yml file. This allows you to manage gates as code alongside your repository.Rules from both sources are evaluated when a pull request is opened or updated. See Configuration for YAML gate syntax and examples.
Enforce high coverage for unit tests:
80%unit-testsRequire all new code in integration tests to be tested:
100%integration-testsEnforce coverage for specific runtime versions:
75%python-3.11, python-3.12You can create multiple gates for the same repository, each applying to different flags. This allows you to enforce different coverage standards for different test types or runtime versions.
Upload unit test and integration test coverage with different flags to track them independently:
# After running unit tests
datadog-ci coverage upload --flags unit-tests unit-coverage.xml
# After running integration tests
datadog-ci coverage upload --flags integration-tests integration-coverage.xmlIf your CI matrix tests against multiple runtime versions, flag each report accordingly:
datadog-ci coverage upload --flags python-3.11 coverage-py311.xml
datadog-ci coverage upload --flags python-3.12 coverage-py312.xmlAdditional helpful documentation, links, and articles:
| |