|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * observability/otel/otel-collector/otel-collector-connectors.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: REFERENCE |
| 6 | +[id="otel-connectors-count-connector_{context}"] |
| 7 | += Count Connector |
| 8 | + |
| 9 | +[role="_abstract"] |
| 10 | +The Count Connector counts trace spans, trace span events, metrics, metric data points, and log records in exporter pipelines. |
| 11 | + |
| 12 | +:FeatureName: The Count Connector |
| 13 | +include::snippets/technology-preview.adoc[] |
| 14 | + |
| 15 | +The following are the default metric names: |
| 16 | + |
| 17 | +* `trace.span.count` |
| 18 | +* `trace.span.event.count` |
| 19 | +* `metric.count` |
| 20 | +* `metric.datapoint.count` |
| 21 | +* `log.record.count` |
| 22 | +
|
| 23 | +You can also expose custom metric names. |
| 24 | + |
| 25 | +.OpenTelemetry Collector custom resource (CR) with an enabled Count Connector |
| 26 | +[source,yaml] |
| 27 | +---- |
| 28 | +# ... |
| 29 | + config: |
| 30 | + receivers: |
| 31 | + otlp: |
| 32 | + protocols: |
| 33 | + grpc: |
| 34 | + endpoint: 0.0.0.0:4317 |
| 35 | + exporters: |
| 36 | + prometheus: |
| 37 | + endpoint: 0.0.0.0:8889 |
| 38 | + connectors: |
| 39 | + count: {} |
| 40 | + service: |
| 41 | + pipelines: # <1> |
| 42 | + traces/in: |
| 43 | + receivers: [otlp] |
| 44 | + exporters: [count] # <2> |
| 45 | + metrics/out: |
| 46 | + receivers: [count] # <3> |
| 47 | + exporters: [prometheus] |
| 48 | +# ... |
| 49 | +---- |
| 50 | +<1> It is important to correctly configure the Count Connector as an exporter or receiver in the pipeline and to export the generated metrics to the correct exporter. |
| 51 | +<2> The Count Connector is configured to receive spans as an exporter. |
| 52 | +<3> The Count Connector is configured to emit generated metrics as a receiver. |
| 53 | ++ |
| 54 | +[TIP] |
| 55 | +==== |
| 56 | +If the Count Connector is not generating the expected metrics, you can check whether the OpenTelemetry Collector is receiving the expected spans, metrics, and logs, and whether the telemetry data flow through the Count Connector as expected. You can also use the Debug Exporter to inspect the incoming telemetry data. |
| 57 | +==== |
| 58 | + |
| 59 | +The Count Connector can count telemetry data according to defined conditions and expose those data as metrics when configured by using such fields as `spans`, `spanevents`, `metrics`, `datapoints`, or `logs`. See the next example. |
| 60 | + |
| 61 | +.Example OpenTelemetry Collector CR for the Count Connector to count spans by conditions |
| 62 | +[source,yaml] |
| 63 | +---- |
| 64 | +# ... |
| 65 | + config: |
| 66 | + connectors: |
| 67 | + count: |
| 68 | + spans: # <1> |
| 69 | + <custom_metric_name>: # <2> |
| 70 | + description: "<custom_metric_description>" |
| 71 | + conditions: |
| 72 | + - 'attributes["env"] == "dev"' |
| 73 | + - 'name == "devevent"' |
| 74 | +# ... |
| 75 | +---- |
| 76 | +<1> In this example, the exposed metric counts spans with the specified conditions. |
| 77 | +<2> You can specify a custom metric name such as `cluster.prod.event.count`. |
| 78 | ++ |
| 79 | +[TIP] |
| 80 | +==== |
| 81 | +Write conditions correctly and follow the required syntax for attribute matching or telemetry field conditions. Improperly defined conditions are the most likely sources of errors. |
| 82 | +==== |
| 83 | + |
| 84 | +The Count Connector can count telemetry data according to defined attributes when configured by using such fields as `spans`, `spanevents`, `metrics`, `datapoints`, or `logs`. See the next example. The attribute keys are injected into the telemetry data. You must define a value for the `default_value` field for missing attributes. |
| 85 | + |
| 86 | +.Example OpenTelemetry Collector CR for the Count Connector to count logs by attributes |
| 87 | +[source,yaml] |
| 88 | +---- |
| 89 | +# ... |
| 90 | + config: |
| 91 | + connectors: |
| 92 | + count: |
| 93 | + logs: # <1> |
| 94 | + <custom_metric_name>: # <2> |
| 95 | + description: "<custom_metric_description>" |
| 96 | + attributes: |
| 97 | + - key: env |
| 98 | + default_value: unknown # <3> |
| 99 | +# ... |
| 100 | +---- |
| 101 | +<1> Specifies attributes for logs. |
| 102 | +<2> You can specify a custom metric name such as `my.log.count`. |
| 103 | +<3> Defines a default value when the attribute is not set. |
0 commit comments