# Surface code coverage metrics from SonarQube in failed Scorecard rules

[CQL captures](/standardize/cql.md#captures) allow you to extract specific values from entity data when a rule fails, making it easier for engineers to understand what went wrong. A typical use of captures is to show key quality metrics, such as code coverage, or detailed data like vulnerabilities in Scorecard rule failure messages. This helps engineers quickly understand why a rule is failing for an entity.

## Capturing code coverage from SonarQube

You can use captures to surface quality metrics such as code coverage from third-party integrations like SonarQube.

1. Decide what data to show in the failure message. In this example, we want to display the code coverage metric reported by SonarQube.
2. While [configuring a Scorecard](/standardize/scorecards/create.md#step-1-configure-the-basic-scorecard-fields), add a rule using a CQL capture. Use a CQL expression to capture the code coverage metric and apply a threshold:\
   &#x20;`captures("code-cov", sonarqube.metric("coverage")) > 50`
3. Customize the rule’s **Failure message** field to include the captured value. This message will appear when the rule fails (i.e., when coverage is 50% or lower):

<pre><code><strong>This entity's code coverage metric from Sonarqube is:
</strong>{{context.evaluation.captures.code-cov}}%
</code></pre>

4. After evaluation, view the Scorecard details. Navigate to the entity that failed the rule. Expand the failure message to view the captured code coverage value.

<div data-full-width="false"><figure><img src="/files/SeFaOchqKG3dYIJJiex4" alt=""><figcaption></figcaption></figure></div>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cortex.io/guides/security/code-coverage-rules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
