countconnector

package module
v0.120.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2025 License: Apache-2.0 Imports: 22 Imported by: 7

README

Count Connector

Status
Distributions contrib, k8s
Issues Open issues Closed issues
Code Owners @djaglowski, @jpkrohling

Supported Pipeline Types

Exporter Pipeline Type Receiver Pipeline Type Stability Level
traces metrics alpha
metrics metrics alpha
logs metrics alpha

The count connector can be used to count spans, span events, metrics, data points, and log records.

Configuration

If you are not already familiar with connectors, you may find it helpful to first visit the Connectors README.

Default Configuration

The count connector may be used without any configuration settings. The following table describes the default behavior of the connector.

Exporter Pipeline Type Description Default Metric Names
traces Counts all spans and span events. trace.span.count, trace.span.event.count
metrics Counts all metrics and data points. metric.count, metric.datapoint.count
logs Counts all log records. log.record.count

For example, in the following configuration the connector will count spans and span events from the traces/in pipeline and emit metrics called trace.span.count and trace.span.event.count onto the metrics/out pipeline.

receivers:
  foo:
exporters:
  bar:
connectors:
  count:

service:
  pipelines:
    traces/in:
      receivers: [foo]
      exporters: [count]
    metrics/out:
      receivers: [count]
      exporters: [bar]
Custom Counts

Optionally, emit custom counts by defining metrics under one or more of the following sections:

  • spans
  • spanevents
  • metrics
  • datapoints
  • logs

Optionally, specify a description for the metric.

Note: If any custom metrics are defined for a data type, the default metric will not be emitted.

Conditions

Conditions may be specified for custom metrics. If specified, data that matches any one of the conditions will be counted. i.e. Conditions are ORed together.

receivers:
  foo:
exporters:
  bar:
connectors:
  count:
    spanevents:
      my.prod.event.count:
        description: The number of span events from my prod environment.
        conditions:
          - 'attributes["env"] == "prod"'
          - 'name == "prodevent"'
Attributes

spans, spanevents, datapoints, and logs may be counted according to attributes.

If attributes are specified for custom metrics, a separate count will be generated for each unique set of attribute values. Each count will be emitted as a data point on the same metric.

Optionally, include a default_value for an attribute, to count data that does not contain the attribute. The default_value value can be of type string, integer, or float.

receivers:
  foo:
exporters:
  bar:
connectors:
  count:
    logs:
      my.log.count:
        description: The number of logs from each environment.
        attributes:
          - key: env
            default_value: unspecified_environment
Example Usage

Count spans and span events, only exporting the count metrics.

receivers:
  foo:
exporters:
  bar:
connectors:
  count:
service:
  pipelines:
    traces:
      receivers: [foo]
      exporters: [count]
    metrics:
      receivers: [count]
      exporters: [bar]

Count spans and span events, exporting both the original traces and the count metrics.

receivers:
  foo:
exporters:
  bar/traces_backend:
  bar/metrics_backend:
connectors:
  count:
service:
  pipelines:
    traces:
      receivers: [foo]
      exporters: [bar/traces_backend, count]
    metrics:
      receivers: [count]
      exporters: [bar/metrics_backend]

Count spans, span events, metrics, data points, and log records, exporting count metrics to a separate backend.

receivers:
  foo/traces:
  foo/metrics:
  foo/logs:
exporters:
  bar/all_types:
  bar/counts_only:
connectors:
  count:
service:
  pipelines:
    traces:
      receivers: [foo/traces]
      exporters: [bar/all_types, count]
    metrics:
      receivers: [foo/metrics]
      exporters: [bar/all_types, count]
    logs:
      receivers: [foo/logs]
      exporters: [bar/all_types, count]
    metrics/counts:
      receivers: [count]
      exporters: [bar/counts_only]

Count logs with a severity of ERROR or higher.

receivers:
  foo:
exporters:
  bar:
connectors:
  count:
    logs:
      my.error.log.count:
        description: Error+ logs.
        conditions:
          - `severity_number >= SEVERITY_NUMBER_ERROR`
service:
  pipelines:
    logs:
      receivers: [foo]
      exporters: [count]
    metrics:
      receivers: [count]
      exporters: [bar]

Count logs with a severity of ERROR or higher. Maintain a separate count for each environment.

receivers:
  foo:
exporters:
  bar:
connectors:
  count:
    logs:
      my.error.log.count:
        description: Error+ logs.
        conditions:
          - `severity_number >= SEVERITY_NUMBER_ERROR`
        attributes:
          - key: env
service:
  pipelines:
    logs:
      receivers: [foo]
      exporters: [count]
    metrics:
      receivers: [count]
      exporters: [bar]

Count all spans and span events (default behavior). Count metrics and data points based on the env attribute.

receivers:
  foo/traces:
  foo/metrics:
  foo/logs:
exporters:
  bar/all_types:
  bar/counts_only:
connectors:
  count:
    metrics:
      my.prod.metric.count:
        conditions:
         - `attributes["env"] == "prod"
      my.test.metric.count:
        conditions:
         - `attributes["env"] == "test"
    datapoints:
      my.prod.datapoint.count:
        conditions:
         - `attributes["env"] == "prod"
      my.test.datapoint.count:
        conditions:
         - `attributes["env"] == "test"
service:
  pipelines:
    traces:
      receivers: [foo/traces]
      exporters: [bar/all_types, count]
    metrics:
      receivers: [foo/metrics]
      exporters: [bar/all_types, count]
    metrics/counts:
      receivers: [count]
      exporters: [bar/counts_only]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFactory

func NewFactory() connector.Factory

NewFactory returns a ConnectorFactory.

Types

type AttributeConfig added in v0.74.0

type AttributeConfig struct {
	Key          string `mapstructure:"key"`
	DefaultValue any    `mapstructure:"default_value"`
}

type Config

type Config struct {
	Spans      map[string]MetricInfo `mapstructure:"spans"`
	SpanEvents map[string]MetricInfo `mapstructure:"spanevents"`
	Metrics    map[string]MetricInfo `mapstructure:"metrics"`
	DataPoints map[string]MetricInfo `mapstructure:"datapoints"`
	Logs       map[string]MetricInfo `mapstructure:"logs"`
}

Config for the connector

func (*Config) Unmarshal added in v0.72.0

func (c *Config) Unmarshal(componentParser *confmap.Conf) error

Unmarshal with custom logic to set default values. This is necessary to ensure that default metrics are not configured if the user has specified any custom metrics.

func (*Config) Validate added in v0.72.0

func (c *Config) Validate() error

type MetricInfo

type MetricInfo struct {
	Description string            `mapstructure:"description"`
	Conditions  []string          `mapstructure:"conditions"`
	Attributes  []AttributeConfig `mapstructure:"attributes"`
}

MetricInfo for a data type

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL