Last9 Last9

Feb 24th, ‘25 / 8 min read

OpenTelemetry Metrics Aggregation: A Detailed Guide

Learn how OpenTelemetry handles metric aggregation, from delta and cumulative temporality to organizing and analyzing performance data.

OpenTelemetry Metrics Aggregation: A Detailed Guide

When you're running distributed systems at scale, understanding how your services perform in real-time is critical. That's where OpenTelemetry comes in. While most developers focus on traces and logs, metrics aggregation is equally important in giving you the bigger picture.

In this guide, we'll break down OpenTelemetry metrics aggregation, why it matters, and how you can get started with it.

Understanding OpenTelemetry Metrics Aggregation

OpenTelemetry is an open-source observability framework for collecting, processing, and exporting telemetry data. Metrics aggregation in OpenTelemetry refers to the process of combining multiple metric data points into meaningful statistics that help you analyze system performance.

Aggregation helps reduce storage requirements, improve query performance, and generate insights without drowning in raw data. Instead of looking at every individual data point, you get a summarized view of what’s happening in your system.

For example, imagine you're tracking API response times. If you log every response time separately, querying that data later becomes cumbersome. Instead, aggregating response times using histograms or averages can help identify performance trends efficiently.

💡
For a deeper understanding of how OpenTelemetry compares to other monitoring solutions, check out our detailed comparison with OpenMetrics here.

Metrics Data Model

The OpenTelemetry metrics data model defines the structure for how metrics are collected, organized, and analyzed. It is designed to facilitate efficient observability, allowing users to monitor system performance over time.

The model is based on several key components, which work together to capture and store meaningful metric data.

Key Components of the Metrics Data Model

  • Metric: Represents a specific measurement, such as the number of requests or the latency of an operation. It is identified by a unique name and can be associated with various labels (dimensions or tags) that provide additional context, like the service name or region.
  • Data Streams: A data stream is a sequence of data points representing a metric’s value over time. Each data point is timestamped and includes the metric’s value along with its labels. Data streams help track changes in the metric, enabling insights into its behavior.
  • Time Series: A time series is essentially a collection of data points that represent how a metric changes over a period. These data points are indexed by time and organized according to metric names and labels. Time series are crucial for identifying trends, analyzing patterns, and comparing metric data across different time intervals.
  • Events: Events are discrete occurrences or changes that are tied to specific points in time. They provide additional context to the metric data, such as marking when an error occurred, when a system started, or when a configuration was updated. Events enrich the understanding of the metric data, helping to correlate system behavior with observed performance metrics.

How It All Fits Together

The OpenTelemetry data model integrates metrics, data streams, time series, and events to offer a comprehensive framework for observability.

  • Metrics are collected through instruments, and these metrics are organized into time series based on timestamps and labels.
  • Data streams capture the evolution of each metric over time.
  • Events complement this structure by adding contextual information, enabling users to correlate specific actions with metric changes.

This model provides a powerful foundation for analyzing system performance and troubleshooting issues.

Why Metrics Aggregation is Essential for Scalable Systems

When you collect metrics, you typically get a firehose of data—latencies, request counts, error rates, and resource usage. If you store and analyze every single metric without aggregation, you’ll run into performance and cost issues.

Key Benefits of Aggregation:

  • Reduced Data Volume – Aggregating metrics lowers the storage and processing overhead by summarizing data points.
  • Faster Query Performance – Pre-aggregated data means dashboards and alerts work efficiently without processing large raw datasets.
  • Improved Observability – Summarized data helps detect trends, anomalies, and patterns faster.
  • Lower Operational Cost – Less raw data means reduced storage and compute expenses, optimizing infrastructure costs.

Consider a scenario where you monitor CPU usage across hundreds of containers. Instead of storing every single CPU sample, aggregating data by percentile distributions (e.g., p50, p95, p99) provides a clearer view of performance trends without unnecessary data bloat.

💡
To learn more about collecting host metrics with OpenTelemetry, read our guide on hosting metrics here.

Types of Metric Aggregations in OpenTelemetry and Their Use Cases

OpenTelemetry supports different types of aggregations to help developers extract insights from raw metrics. Understanding which type to use can significantly impact observability and system efficiency.

1. Sum Aggregation

  • Computes the total sum of all recorded values over time.
  • Used for tracking cumulative metrics like total requests, error counts, or total bytes transmitted.
  • Example: If a service handles 1000 requests in an hour, the sum aggregation will report "1000" instead of storing each individual request count separately.

2. Count Aggregation

  • Tracks the number of occurrences of a particular event.
  • Useful for monitoring event-based occurrences like HTTP requests or login attempts.
  • Example: Counting the number of successful logins within a specified time window can help detect usage patterns.

3. Last Value Aggregation

  • Retains only the most recent recorded value.
  • Ideal for tracking system state metrics such as current memory usage or CPU load.
  • Example: Monitoring "current active user sessions" on a website, where only the latest value is relevant.

4. Histogram Aggregation

  • Groups metric values into buckets to analyze distribution and percentiles.
  • Commonly used for latency and performance analysis.
  • Example: Storing API response times in histogram buckets (e.g., 0-100ms, 100-500ms, 500ms+) helps analyze performance trends.
💡
For a comprehensive overview of OpenTelemetry metrics and how to use them, check out our detailed guide here.

Step-by-Step Guide to Setting Up Metrics Aggregation in OpenTelemetry

Step 1: Install OpenTelemetry SDK

Depending on your programming language, install the OpenTelemetry SDK. For example, in Python:

pip install opentelemetry-sdk

For Go:

go get go.opentelemetry.io/otel

Step 2: Configure the Meter Provider

A Meter Provider is responsible for metric collection. Here’s how to set it up in Python:

from opentelemetry import metrics
from opentelemetry.sdk.metrics import MeterProvider

metrics.set_meter_provider(MeterProvider())
meter = metrics.get_meter_provider().get_meter("my_application")

Step 3: Define and Record Metrics with Aggregation

Create and update your metrics efficiently to ensure proper aggregation:

counter = meter.create_counter(
    "requests.count",
    description="Total number of requests received by the service",
)

counter.add(1, {"endpoint": "/home", "status": "200"})

Step 4: Export Aggregated Metrics to an Observability Backend

Use an OpenTelemetry exporter (such as Prometheus or OTLP) to ship metrics to your observability backend:

from opentelemetry.sdk.metrics.export import ConsoleMetricExporter, PeriodicExportingMetricReader

exporter = ConsoleMetricExporter()
meter_provider = MeterProvider(
    metric_readers=[PeriodicExportingMetricReader(exporter)]
)
metrics.set_meter_provider(meter_provider)

How to Instrument Metrics and Capture Measurements in OpenTelemetry

To effectively capture and analyze metrics, OpenTelemetry provides various instruments that emit measurements. Choosing the right instrument ensures meaningful and efficient metric collection.

1. Counter

  • A monotonic instrument that only increases over time.
  • Best suited for counting events such as requests, errors, or processed messages.

Example: Tracking the total number of HTTP requests received:

request_counter = meter.create_counter("http_requests_total", "Counts the total number of HTTP requests")
request_counter.add(1, {"endpoint": "/login", "status": "200"})

2. Gauge

  • Captures an instantaneous value that can increase or decrease.
  • Used for system state metrics like memory usage, CPU load, or active users.

Example: Reporting current memory usage:

memory_gauge = meter.create_observable_gauge("memory_usage", "Tracks current memory usage in MB")
memory_gauge.observe(lambda: get_memory_usage(), {})
💡
To learn how to convert OpenTelemetry traces into metrics using SpanConnector, read our full guide here.

3. Histogram

  • Records the distribution of values, useful for latency or performance measurements.
  • Aggregates data into percentiles (e.g., p50, p95, p99) to provide more insights than simple averages.

Example: Measuring response time distribution:

response_time_histogram = meter.create_histogram("http_response_time", "Tracks response times in milliseconds")
response_time_histogram.record(250, {"endpoint": "/home"})

4. UpDownCounter

  • A counter that can increase or decrease, is ideal for tracking values that fluctuate over time.

Example: Monitoring the number of active user sessions:

active_users = meter.create_up_down_counter("active_sessions", "Tracks the number of active user sessions")
active_users.add(1)  # User logs in
active_users.add(-1)  # User logs out

Understanding and applying the right instrument ensures efficient telemetry data collection, ultimately enhancing observability and performance monitoring.

Metric Mapping and Temporality

In OpenTelemetry, metrics are the primary way to measure and observe the performance of applications. The mapping of instrument kinds to metric types is a crucial aspect of the OpenTelemetry framework, as it defines how different types of measurements are captured and reported.

Instrument Kinds to Metric Types

OpenTelemetry defines several types of instruments, each mapping to a specific metric type. The most common types of instruments include:

  1. Counter: Tracks monotonically increasing values, such as the number of requests or errors. A counter is typically used when you want to count occurrences, such as HTTP requests, in a system.
  2. Measure: Measures quantities that can change over time, such as the duration of an operation or the amount of memory used. Unlike counters, measures are not necessarily monotonically increasing and can represent any value that changes.
  3. UpDownCounter: Similar to the counter but allows both increments and decrements. It is used to track values that can go both up and down, like the number of active users in a system.
  4. Histogram: Captures a distribution of values over time. This type of instrument is used to gather data on the frequency of events within different value ranges, such as response times or system latencies.

Aggregation Temporality

Temporality refers to the concept of how metric data is aggregated and reported over time. OpenTelemetry supports two main types of aggregation temporality:

  1. Delta Temporality: This method records the change in the metric value since the last measurement. Delta temporality is used for metrics like counters and up-down counters, where you care about the difference in values over time rather than the absolute value.
  2. Cumulative Temporality: In this approach, the metric value reflects the total value over time. For instance, a cumulative counter would report the total count since the application started. Cumulative temporality is typically used with metrics that measure ongoing quantities.

The choice between delta and cumulative temporality impacts how data is recorded and aggregated in observability tools, as well as how it can be queried and interpreted.

💡
For insights on Prometheus' native support for OpenTelemetry metrics, explore our detailed article here.

Best Practices for Effective Metrics Usage

To make the most out of OpenTelemetry metrics, follow these best practices:

  • Apply Consistent Labels (Tags): Labels should be meaningful and limited in cardinality to prevent performance degradation. For example, avoid using highly unique identifiers like request IDs as labels.
  • Establish Clear Naming Conventions: Use standardized and descriptive metric names. A good practice is to follow the <service>.<metric>.<unit> format, such as api.requests.count.
  • Optimize the Telemetry Pipeline: Reduce the frequency of metric collection for less critical data points, use batch exports, and filter unnecessary metrics before sending them to observability backends.
  • Use Histograms Over Averages: Percentiles (p50, p95, p99) provide more actionable insights than simple averages, which can be misleading.
  • Use Aggregation Effectively: Choose the right aggregation type based on the use case—sum for cumulative metrics, count for event occurrences, and histograms for latency analysis.

How to Choose the Right Observability Backend for Aggregated Metrics

Once aggregated, metrics need to be stored and visualized. Here are some common observability tools:

  • Last9 – A scalable and cost-effective observability platform optimized for large-scale data.
  • Prometheus – Popular for real-time monitoring but requires careful tuning for high-cardinality data.
  • Grafana – Works well with Prometheus, providing powerful visualization capabilities.
  • Datadog – Full-featured monitoring with built-in OpenTelemetry support.
  • New Relic – A comprehensive APM solution with OpenTelemetry integrations.
💡
To learn how to filter metrics by labels in OpenTelemetry Collector, check out our guide here.

Conclusion:

Metrics aggregation in OpenTelemetry helps make telemetry data more actionable. Whether you’re monitoring microservices or a large-scale distributed system, OpenTelemetry provides the tools you need to get started with efficient metric aggregation.

💡
And if you'd like to continue the conversation, our Discord community is open. We have a dedicated channel where you can share and discuss your specific use case with other developers.

Contents


Newsletter

Stay updated on the latest from Last9.

Authors
Anjali Udasi

Anjali Udasi

Helping to make the tech a little less intimidating. I love breaking down complex concepts into easy-to-understand terms.