---
title: "otelcol.connector.count | Grafana Alloy documentation"
description: "Learn about otelcol.connector.count"
---

# `otelcol.connector.count`

> **EXPERIMENTAL**: This is an [experimental](/docs/release-life-cycle/) component. Experimental components are subject to frequent breaking changes, and may be removed with no equivalent replacement. To enable and use an experimental component, you must set the `stability.level` [flag](/docs/alloy/latest/reference/cli/run/) to `experimental`.

`otelcol.connector.count` accepts spans, span events, metrics, data points, and log records from other `otelcol` components and generates metrics that count the received telemetry data.

> Note
> 
> `otelcol.connector.count` is a wrapper over the upstream OpenTelemetry Collector Contrib `count` connector. Bug reports or feature requests are redirected to the upstream repository if necessary.

You can specify multiple `otelcol.connector.count` components by giving them different labels.

## Usage

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
otelcol.connector.count "<LABEL>" {
  output {
    metrics = [...]
  }
}
```

## Arguments

The `otelcol.connector.count` component doesn’t support any arguments. You can configure this component with blocks.

## Blocks

You can use the following blocks with `otelcol.connector.count`:

No valid configuration blocks found.

### `spans`

The `spans` block configures a custom metric for counting spans.

You can specify multiple `spans` blocks to define different metrics.

If you don’t define any `spans` blocks, the connector emits a default metric named `trace.span.count`.

Expand table

| Name          | Type           | Description                           | Default                                    | Required |
|---------------|----------------|---------------------------------------|--------------------------------------------|----------|
| `conditions`  | `list(string)` | OTTL expressions for filtering spans. | `[]`                                       | no       |
| `description` | `string`       | Metric description.                   | `""`                                       | no       |
| `name`        | `string`       | Metric name.                          | Uses default name based on telemetry type. | no       |

The `conditions` argument accepts a list of [OTTL](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl) expressions that filter which spans to count. If any condition matches, the connector counts the span. If you don’t specify conditions, the connector counts all spans.

### `spanevents`

The `spanevents` block configures a custom metric for counting span events.

You can specify multiple `spanevents` blocks to define different metrics.

If you don’t define any `spanevents` blocks, the connector emits a default metric named `trace.span.event.count`.

This block shares the same configuration structure as \[`spans`]\[spans]. Refer to the \[`spans`]\[spans] block documentation for the complete list of supported arguments and blocks.

### `metrics`

The `metrics` block configures a custom metric for counting metrics.

You can specify multiple `metrics` blocks to define different metrics.

If you don’t define any `metrics` blocks, the connector emits a default metric named `metric.count`.

This block shares the same configuration structure as \[`spans`]\[spans]. Refer to the \[`spans`]\[spans] block documentation for the complete list of supported arguments and blocks.

### `datapoints`

The `datapoints` block configures a custom metric for counting data points.

You can specify multiple `datapoints` blocks to define different metrics.

If you don’t define any `datapoints` blocks, the connector emits a default metric named `metric.datapoint.count`.

This block shares the same configuration structure as \[`spans`]\[spans]. Refer to the \[`spans`]\[spans] block documentation for the complete list of supported arguments and blocks.

### `logs`

The `logs` block configures a custom metric for counting log records.

You can specify multiple `logs` blocks to define different metrics.

If you don’t define any `logs` blocks, the connector emits a default metric named `log.record.count`.

This block shares the same configuration structure as \[`spans`]\[spans]. Refer to the \[`spans`]\[spans] block documentation for the complete list of supported arguments and blocks.

### `attributes`

The `attributes` block specifies an attribute to use for grouping counted telemetry data.

Each unique combination of attribute values generates a separate data point on the metric.

You can specify multiple `attributes` blocks within `spans`, `spanevents`, `metrics`, `datapoints`, or `logs` blocks to group by multiple attributes.

The following arguments are supported:

Expand table

| Name            | Type     | Description                                   | Default | Required |
|-----------------|----------|-----------------------------------------------|---------|----------|
| `key`           | `string` | Attribute key name.                           |         | yes      |
| `default_value` | `any`    | Default value if the attribute doesn’t exist. |         | no       |

Attribute precedence: span/log/metric attributes &gt; scope attributes &gt; resource attributes.

### `output`

Required

The `output` block configures a set of components to forward resulting telemetry data to.

The following arguments are supported:

Expand table

| Name      | Type                     | Description                           | Default | Required |
|-----------|--------------------------|---------------------------------------|---------|----------|
| `logs`    | `list(otelcol.Consumer)` | List of consumers to send logs to.    | `[]`    | no       |
| `metrics` | `list(otelcol.Consumer)` | List of consumers to send metrics to. | `[]`    | no       |
| `traces`  | `list(otelcol.Consumer)` | List of consumers to send traces to.  | `[]`    | no       |

You must specify the `output` block, but all its arguments are optional. By default, telemetry data is dropped. Configure the `metrics`, `logs`, and `traces` arguments accordingly to send telemetry data to other components.

### `debug_metrics`

The `debug_metrics` block configures the metrics that this component generates to monitor its state.

The following arguments are supported:

Expand table

| Name                               | Type      | Description                                          | Default | Required |
|------------------------------------|-----------|------------------------------------------------------|---------|----------|
| `disable_high_cardinality_metrics` | `boolean` | Whether to disable certain high cardinality metrics. | `true`  | no       |

`disable_high_cardinality_metrics` is the Alloy equivalent to the `telemetry.disableHighCardinalityMetrics` feature gate in the OpenTelemetry Collector. It removes attributes that could cause high cardinality metrics. For example, attributes with IP addresses and port numbers in metrics about HTTP and gRPC connections are removed.

> Note
> 
> If configured, `disable_high_cardinality_metrics` only applies to `otelcol.exporter.*` and `otelcol.receiver.*` components.

## Exported fields

The following fields are exported and can be referenced by other components:

Expand table

| Name    | Type               | Description                                                      |
|---------|--------------------|------------------------------------------------------------------|
| `input` | `otelcol.Consumer` | A value that other components can use to send telemetry data to. |

`input` accepts `otelcol.Consumer` data for traces, metrics, and logs.

he component counts all telemetry received through `input` according to the configured blocks and emits metrics to the components specified in `output`.

## Component health

`otelcol.connector.count` is only reported as unhealthy if given an invalid configuration.

## Debug information

`otelcol.connector.count` doesn’t expose any component-specific debug information.

## Examples

### Default configuration

Use the count connector with minimal configuration to count all telemetry data using default metric names.

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
otelcol.connector.count "default" {
  output {
    metrics = [otelcol.exporter.otlphttp.default.input]
  }
}
```

This configuration generates the following default metrics:

- `trace.span.count` - Count of all spans
- `trace.span.event.count` - Count of all span events
- `metric.count` - Count of all metrics
- `metric.datapoint.count` - Count of all data points
- `log.record.count` - Count of all log records

### Custom metrics with conditions and attributes

Create custom count metrics with filtering conditions and group counts by specific attributes.

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
otelcol.connector.count "default" {
  // Count only HTTP GET spans
  spans {
    name        = "http_get_requests"
    description = "Number of HTTP GET requests"
    conditions  = [
      "attributes[\"http.method\"] == \"GET\"",
    ]
  }

  // Count spans grouped by service and environment
  spans {
    name        = "spans_by_service"
    description = "Spans per service and environment"
    attributes {
      key           = "service.name"
      default_value = "unknown"
    }
    attributes {
      key           = "env"
      default_value = "production"
    }
  }

  // Count error and fatal logs only
  logs {
    name        = "error_logs"
    description = "Error and fatal log records"
    conditions  = [
      "severity_number >= 17",
    ]
  }

  // Count logs by environment
  logs {
    name        = "logs_by_env"
    description = "Log records per environment"
    attributes {
      key = "env"
    }
  }

  output {
    metrics = [otelcol.exporter.otlphttp.default.input]
  }
}
```

### Complete pipeline with Prometheus export

Count spans, logs, and metrics, then export to Prometheus using the delta to cumulative processor.

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
otelcol.receiver.otlp "default" {
  grpc {
    endpoint = "127.0.0.1:4317"
  }

  http {
    endpoint = "127.0.0.1:4318"
  }

  output {
    traces  = [otelcol.connector.count.default.input]
    metrics = [otelcol.connector.count.default.input]
    logs    = [otelcol.connector.count.default.input]
  }
}

otelcol.connector.count "default" {
  spans {
    name        = "traces_total"
    description = "Total number of spans received"
  }

  spans {
    name        = "http_get_spans"
    description = "HTTP GET requests"
    conditions  = [
      "attributes[\"http.method\"] == \"GET\"",
    ]
  }

  spans {
    name        = "spans_by_service"
    description = "Spans grouped by service"
    attributes {
      key           = "service.name"
      default_value = "unknown"
    }
  }

  logs {
    name        = "logs_total"
    description = "Total number of logs received"
  }

  logs {
    name        = "error_logs"
    description = "Error level logs"
    conditions  = [
      "severity_number >= 17",
    ]
  }

  metrics {
    name        = "metrics_total"
    description = "Total number of metrics received"
  }

  output {
    metrics = [otelcol.processor.deltatocumulative.default.input]
  }
}

// Convert delta metrics to cumulative for Prometheus compatibility
otelcol.processor.deltatocumulative "default" {
  output {
    metrics = [otelcol.exporter.prometheus.default.input]
  }
}

otelcol.exporter.prometheus "default" {
  forward_to                       = [prometheus.remote_write.default.receiver]
  add_metric_suffixes              = false
  resource_to_telemetry_conversion = true
}

prometheus.remote_write "default" {
  endpoint {
    url = "http://localhost:9090/api/v1/write"
  }
}
```

## Technical details

`otelcol.connector.count` uses the count connector from OpenTelemetry Collector Contrib.

All generated metrics use the Sum data type with Delta aggregation temporality.

> Note
> 
> Prometheus doesn’t natively support delta metrics. Use [`otelcol.processor.deltatocumulative`](../otelcol.processor.deltatocumulative/) to convert delta metrics to cumulative before sending to Prometheus.

## Compatible components

`otelcol.connector.count` can accept arguments from the following components:

- Components that export [OpenTelemetry `otelcol.Consumer`](../../../compatibility/#opentelemetry-otelcolconsumer-exporters)

`otelcol.connector.count` has exports that can be consumed by the following components:

- Components that consume [OpenTelemetry `otelcol.Consumer`](../../../compatibility/#opentelemetry-otelcolconsumer-consumers)

> Note
> 
> Connecting some components may not be sensible or components may require further configuration to make the connection work correctly. Refer to the linked documentation for more details.
