Count Telemetry

🚧

This feature is only available in BindPlane OP Enterprise. Learn more here.

Count Telemetry Processor

The Count Telemetry Processor can count the number of logs, metric datapoints, 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.

Supported Types

MetricsLogsTraces
βœ“βœ“βœ“

Supported Agent Versions

v1.22.0+

Configuration

FieldTypeDefaultDescription
enable_logsboolfalseEnables or disables counting of logs.
log_matchstringtrueA boolean expression used to match which logs to count. By default, all logs are counted.
log_metric_namestringlog.countThe name of the metric created.
log_metric_unitsstring{logs}The unit of the metric created. See Unified Code for Units of Measure for available units.
log_attributesmap{}The mapped attributes of the metric created. Each key is an attribute name. Each value is an expression that extracts data from the log.
enable_metricsboolfalseEnables or disables counting of metric datapoints.
datapoint_matchstringtrueA boolean expression used to match which datapoints to count. By default, all datapoints are counted.
datapoint_metric_namestringdatapoint.countThe name of the metric created.
datapoint_metric_unitsstring{datapoints}The unit of the metric created. See Unified Code for Units of Measure for available units.
datapoint_attributesmap{}The mapped attributes of the metric created. Each key is an attribute name. Each value is an expression that extracts data from the datapoint.
enable_tracesboolfalseEnables or disables counting of trace spans.
span_matchstringtrueA boolean expression used to match which spans to count. By default, all spans are counted.
span_metric_namestringspan.countThe name of the metric created.
span_metric_unitsstring{spans}The unit of the metric created. See Unified Code for Units of Measure for available units.
span_attributesmap{}The mapped attributes of the metric created. Each key is an attribute name. Each value is an expression that extracts data from the span.
intervalint60The interval, in seconds, at which metrics are created. Telemetry counters will reset after each interval.

Expression Language

In order to match or extract values from telemetry, the following keys are reserved and can be used to traverse the data model.

Logs

KeyDescription
bodyUsed to access the body of the log.
attributesUsed to access the attributes of the log.
resourceUsed to access the resource of the log.
severity_enumUsed to access the severity enum of the log.
severity_numberUsed to access the severity number of the log.

Datapoints

KeyDescription
attributesUsed to access the attributes of the datapoint.
resourceUsed to access the resource of the datapoint.
metric_nameUsed to access the name of the metric that contains the datapoint.
datapoint_valueUsed to access the value of Sum and Gauge metrics.

Spans

KeyDescription
attributesUsed to access the attributes of the datapoint.
resourceUsed to access the resource of the datapoint.
trace_status_messageUsed to access the status message of the span.
trace_status_codeUsed to access the status code enum of the span. Values may be "ok", "error", or "unset".
trace_kindUsed to access the kind enum of the span. Values may be "unspecified", "internal", "client", "server", "consumer", or "producer".
span_duration_msUsed to access the duration of the span, in milliseconds.

Syntax

In order to access embedded values, use JSON dot notation. For example, body.example.field can be used to access a field two levels deep on the log body.

However, if a key already possesses a literal dot, users will need to use bracket notation to access that field. For example, when the field service.name exists on the log's resource, users will need to use resource["service.name"] to access this value.

For more information about syntax and available operators, see the Expression Language Definition.


Example Configurations

Count all telemetry

By default, enabling metrics, traces, or logs will count all of their respective telemetry types.

Count all logs

Count all datapoints

Count all spans

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:

{
  "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:

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:

log_attributes:
  status_code: body.status