# Count Telemetry

| Metrics | Logs | Traces | Bindplane Collector |
| ------- | ---- | ------ | ------------------- |
| ✓       | ✓    | ✓      | `v1.27.0\`+         |

### Description

The Count Telemetry Processor can count the number of logs, metric data points, or trace spans matching some filter, and create a metric with that value. Both the name and units of the created metric can be configured. Additionally, fields from matching logs can be preserved as metric attributes.

### Use

Count Telemetry is especially useful as a way to convert your logs to metrics, allowing you to drop logs you don't need while still capturing signal from them.

A frequent use case is to count how many logs you're getting from your web server by http status code. This lets you see if you're getting 500s, without paying to store logs for your 200s. See below for specific configuration examples.

### Configuration

<table><thead><tr><th width="109.9921875">Field</th><th>Description</th></tr></thead><tbody><tr><td>Telemetry Types</td><td>The types of telemetry to apply the processor to.</td></tr><tr><td>Match Expression</td><td><a href="https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl#readme">OTTL</a> expression to find matching logs. Uses the <a href="https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/ottl/contexts/ottllog/README.md">log context</a> for logs, .<a href="https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/ottl/contexts/ottldatapoint/README.md">datapoint context</a> for metrics, and <a href="https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/ottl/contexts/ottlspan/README.md">span context</a> for traces.</td></tr><tr><td>Metric Name</td><td>The name of the metric created.</td></tr><tr><td>Metric Units</td><td>The unit of the metric created. See <a href="https://unitsofmeasure.org/ucum#section-Alphabetic-Index-By-Name">Unified Code for Units of Measure</a> for available units.</td></tr><tr><td>Metric Attributes</td><td>The mapped attributes of the metric created. Each key is an attribute name. Each value is an <a href="https://github.com/antonmedv/expr/blob/master/docs/Language-Definition.md">expression</a> that extracts data from the log.</td></tr></tbody></table>

***

### Example Configurations

#### Count all telemetry

By default, enabling metrics, traces, or logs will count all of their respective telemetry types. Below is an example of what this looks like when we want to count all logs.

<figure><img src="https://1405008107-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgmiOMzBfoNFwmKJFHMcJ%2Fuploads%2Fgit-blob-faa1de4060f105cbe85fcb8cc3aa930420b238d6%2Fintegrations-processors-count-telemetry-image-1.png?alt=media" alt="Bindplane docs - Count Telemetry - image 1"><figcaption></figcaption></figure>

#### Count HTTP Requests by Status (logs)

In this configuration, we want to parse our HTTP server logs to count how many requests were completed, broken down by status code. Our logs are JSON with the following structure:

```json
{
  "level": "warn",
  "host": "10.0.10.0",
  "datetime":"2022-12-07T13:21",
  "method": "POST",
  "request": "/api/create",
  "protocol": "HTTP/1.1",
  "status": 500
}
```

The match expression will exclude all logs without a status code in its body:

```expr
body["status"] != nil
```

We'll name this metric `http.request.count`, then we'll use the status code for the `status_code` metric attribute on the created metric:

```yaml
log_attributes:
  status_code: body["status"]
```

<figure><img src="https://1405008107-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgmiOMzBfoNFwmKJFHMcJ%2Fuploads%2Fgit-blob-3e9e4bc7e8ea69cd581781a39f2ce38c0a26ffb6%2Fintegrations-processors-count-telemetry-image-2.png?alt=media" alt="Bindplane docs - Count Telemetry - image 2"><figcaption></figcaption></figure>


---

# 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.bindplane.com/integrations/processors/count-telemetry.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.
