7.2 Create metrics with Sum Connector
10 minutesIn this section, we’ll explore how the Sum Connector can extract values from spans and convert them into metrics.
We’ll specifically use the credit card charges from our base spans and leverage the Sum Connector to retrieve the total charges as a metric.
The connector can be used to collect (sum) attribute values from spans, span events, metrics, data points, and log records. It captures each individual value, transforms it into a metric, and passes it along. However, it’s the backend’s job to use these metrics and their attributes for calculations and further processing.
Exercise
Switch to your Agent terminal window and open the agent.yaml file in your editor.
- Add the Sum Connector
Include the Sum Connector in the connectors section of your configuration and define the metrics counters:
In the example above, we check for the payment.amount attribute in spans. If it has a valid value, the Sum connector generates a metric called user.card-charge and includes the user.name as an attribute. This enables the backend to track and display a user’s total charges over an extended period, such as a billing cycle.
In the pipeline configuration below, the connector exporter is added to the traces section, while the connector receiver is added to the metrics section.
Exercise
- Configure the Count Connector in the pipelines
- Validate the agent configuration using otelbin.io. For reference, the
tracesandmetrics:sections of your pipelines will look like this:
%%{init:{"fontFamily":"monospace"}}%%
graph LR
%% Nodes
REC1(otlp<br>fa:fa-download<br> ):::receiver
REC3(otlp<br>fa:fa-download<br> ):::receiver
PRO1(memory_limiter<br>fa:fa-microchip<br> ):::processor
PRO2(memory_limiter<br>fa:fa-microchip<br> ):::processor
PRO3(resource<br>fa:fa-microchip<br>add_mode):::processor
PRO4(resource<br>fa:fa-microchip<br>add_mode):::processor
PRO5(batch<br>fa:fa-microchip<br> ):::processor
PRO6(batch<br>fa:fa-microchip<br> ):::processor
PRO7(resourcedetection<br>fa:fa-microchip<br> ):::processor
PRO8(resourcedetection<br>fa:fa-microchip<br>):::processor
PROA(attributes<br>fa:fa-microchip<br>redact):::processor
PROB(redaction<br>fa:fa-microchip<br>update):::processor
EXP1(  debug  <br>fa:fa-upload<br> ):::exporter
EXP2(  file  <br>fa:fa-upload<br> ):::exporter
EXP3(  debug  <br>fa:fa-upload<br> ):::exporter
EXP4(  otlphttp  <br>fa:fa-upload<br> ):::exporter
EXP5(  otlphttp  <br>fa:fa-upload<br> ):::exporter
ROUTE1( sum <br>fa:fa-route<br> ):::con-export
ROUTE2( count <br>fa:fa-route<br> ):::con-receive
ROUTE3( sum <br>fa:fa-route<br> ):::con-receive
%% Links
subID1:::sub-traces
subID2:::sub-metrics
subgraph " "
direction LR
subgraph subID1[**Traces**]
direction LR
REC1 --> PRO1
PRO1 --> PROA
PROA --> PROB
PROB --> PRO7
PRO7 --> PRO3
PRO3 --> PRO5
PRO5 --> EXP1
PRO5 --> EXP2
PRO5 --> EXP5
PRO5 --> ROUTE1
end
subgraph subID2[**Metrics**]
direction LR
ROUTE1 --> ROUTE3
ROUTE3 --> PRO2
ROUTE2 --> PRO2
REC3 --> PRO2
PRO2 --> PRO8
PRO8 --> PRO4
PRO4 --> PRO6
PRO6 --> EXP3
PRO6 --> EXP4
end
end
classDef receiver,exporter fill:#8b5cf6,stroke:#333,stroke-width:1px,color:#fff;
classDef processor fill:#6366f1,stroke:#333,stroke-width:1px,color:#fff;
classDef con-receive,con-export fill:#45c175,stroke:#333,stroke-width:1px,color:#fff;
classDef sub-logs stroke:#34d399,stroke-width:1px, color:#34d399,stroke-dasharray: 3 3;
classDef sub-traces stroke:#fbbf24,stroke-width:1px, color:#fbbf24,stroke-dasharray: 3 3;
classDef sub-metrics stroke:#38bdf8,stroke-width:1px, color:#38bdf8,stroke-dasharray: 3 3;