# Codecov

{% hint style="info" %}
Cortex connects to many third-party vendors whose system interfaces frequently change. As a result, integration behavior or configuration steps may shift without notice. If you encounter unexpected issues, check with your system administrator or refer to the vendor's documentation for the most current information. Additionally, integration sync times vary and are subject to scheduling overrides and timing variance.
{% endhint %}

[Codecov](https://about.codecov.io/) is a code coverage reporting platform that that monitors how much of your code has been tested and validated. Codecov analytics can be used to drive visibility into your microservice architecture and understand coverage trends over time.

Integrating Cortex with Codecov allows you to:

* View code coverage details for entities directly in Cortex
* Create [Scorecards](#scorecards-and-cql) that track progress and drive alignment on projects involving your Codecov code coverage metrics

## How to configure Codecov with Cortex

### Prerequisites

Before getting started:

* Create a [Codecov access token](https://docs.codecov.io/reference#usagen).

### Configure the integration in Cortex

1. In Cortex, navigate to the [Codecov settings page](https://app.getcortexapp.com/admin/integrations/codecov).
   * Click **Integrations** from the main nav. Search for and select **Codecov**.
2. Click **Add configuration**.
3. Configure the Codecov integration form:
   * **API token**: Enter your Codecov access token.
   * **Host**: If you're using a custom Codecov instance, enter your host URL.
     * Make sure to enter the URL **without** the API path (e.g., `https://codecov.getcortexapp.com`).
4. Click **Save**.

To modify the integration configuration, see [Modifying an existing integration configuration](/ingesting-data-into-cortex/integrations.md#modifying-an-existing-integration-configuration).

## How to connect Cortex entities to Codecov

### Auto discovery of Codecov projects

Cortex will use the GitHub, GitLab, Bitbucket, or Azure DevOps repository as the "best guess" for the corresponding Codecov project, since Codecov projects are connected to repositories. For example, if the GitHub repo associated with your Codecov instance is `my-org/repo`, then the entities in Cortex should also be associated with `my-org/repo`.

You can find the repository for a given entity in its YAML, defined in a block like the one below:

```yaml
x-cortex-git:
  github:
    repository: cortexapps/sample-repo
```

If the Codecov project you want to associate isn't the same as the repository, you can override this in the Cortex entity descriptor.

{% hint style="warning" %}
While Cortex uses the [Cortex tag](/ingesting-data-into-cortex/entities-overview/entities.md#cortex-tag) for discovery with many integrations, the **repository** is used for Codecov projects.
{% endhint %}

### Editing the entity descriptor

```yaml
x-cortex-static-analysis:
  codecov:
    owner: org-name
    repo: my-project
    provider: AZURE_DEVOPS | BITBUCKET | BITBUCKET_SERVER | GITHUB | GITHUB_ENTERPRISE | GITLAB | GITLAB_ENTERPRISE
    flag: flag
```

| Field      | Description                                          | Required |
| ---------- | ---------------------------------------------------- | :------: |
| `owner`    | Name of the Git organization                         |   **✓**  |
| `repo`     | Git repository (without the organization)            |   **✓**  |
| `provider` | One of the Git providers in the sample YAML          |   **✓**  |
| `flag`     | Pulls from isolated and categorized coverage reports |          |

The value for `repo` should be the **full repository** because Codecov maps projects by repo.

**Flags**

Codecov's [flags](https://docs.codecov.com/docs/flags) are used to categorize coverage reports for various features and tests in a given project. Flags allow you to set different statistics for different areas of your code base. For example, if you have a monorepo with multiple unique projects, you can use Codecov flags to evaluate each project with different test coverage metrics.

To pull flags into Cortex, define the `flag` line in the [entity descriptor block](#editing-the-entity-descriptor).

{% hint style="warning" %}
If you choose to configure with flags, discovery will be disabled; you would need to define the `owner`, `repo`, and `provider` lines.
{% endhint %}

## Using the Codecov integration

#### Entity pages

With the Codecov integration, you can find code coverage details on an entity's details page as long as that entity is associated with a repo linked to your Codecov instance.

Click **Code & security** in the entity's sidebar to see the code coverage for that entity.

### Scorecards and CQL

With the Codecov integration, you can create Scorecard rules and write CQL queries based on Codecov code coverage metrics.

See more examples in the [CQL Explorer](https://app.getcortexapp.com/admin/cql-explorer) in Cortex.

<details>

<summary>Code coverage</summary>

Code coverage for an entity's Git repository (out of 100)

**Definition:** `codecov.codeCoverage()`

**Example**

For a Scorecard focused on development maturity, you can set a rule to make sure code coverage for a given entity is at least 95%:

```
codecov.codeCoverage() >= 95
```

Set a threshold that is both challenging and realistic so there's an incentive for developers to improve.

</details>

{% hint style="success" %}
Setting up a rule based on code coverage can serve as a secondary check to confirm an entity is synced with Codecov and reporting frequently.
{% endhint %}

### View integration logs <a href="#still-need-help" id="still-need-help"></a>

## Still need help?[​](https://docs.cortex.io/docs/reference/integrations/aws#still-need-help) <a href="#still-need-help" id="still-need-help"></a>

The following options are available to get assistance from the Cortex Customer Engineering team:

* **Email**: <help@cortex.io>, or open a support ticket in the in app Resource Center
* **Slack**: Users with a connected Slack channel will have a workflow added to their account. From here, you can either @CortexTechnicalSupport or add a `:ticket:` reaction to a question in Slack, and the team will respond directly.

Don’t have a Slack channel? Talk with your Customer Success Manager.


---

# 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/ingesting-data-into-cortex/integrations/codecov.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.
