WEBINAR Sept 16: Exploring User Journeys with Embrace. Bridge the gap between observability and product analytics for mobile and web applications.

Sign-up

OpenTelemetry Metrics: Types & Examples

This article explores the core types of OpenTelemetry metrics, their data model, and practical examples to help you leverage these tools effectively.

OpenTelemetry metrics are foundational to modern observability, enabling organizations to monitor, analyze, and optimize application performance. As distributed systems and cloud-native architectures become more complex, understanding OpenTelemetry metrics is essential for developers, DevOps teams, and technical leaders seeking actionable insights into system health and user experience. This article explores the core types of OpenTelemetry metrics, their data model, and practical examples to help you leverage these tools effectively.

What are OpenTelemetry Metrics and Why They Matter

OpenTelemetry metrics are quantitative measurements that provide real-time visibility into the behavior and performance of applications. As part of the OpenTelemetry observability framework, these metrics help teams detect anomalies, track resource usage, and make data-driven decisions. Unlike logs or traces, which offer detailed event or transaction-level information, metrics deliver aggregated, time-series data that is ideal for monitoring trends and setting alerts.

The importance of OpenTelemetry metrics lies in their ability to:

  • Detect performance bottlenecks: Identify slowdowns or failures before they impact users.
  • Support capacity planning: Monitor resource consumption to optimize infrastructure.
  • Enable proactive troubleshooting: Surface issues early, reducing mean time to resolution (MTTR).
  • Facilitate compliance and reporting: Provide quantifiable data for audits and service-level objectives (SLOs).

By standardizing how metrics are collected and reported, OpenTelemetry ensures consistency across diverse environments, making it easier to integrate with various backends and visualization tools. For organizations seeking a comprehensive OpenTelemetry integration, Embrace’s OpenTelemetry product suite provides robust support for seamless metric collection and analysis across your mobile applications.

Understanding the OpenTelemetry Metrics Data Model

The OpenTelemetry metrics data model defines how measurements are structured, transmitted, and interpreted. At its core, the model is designed for flexibility and interoperability, supporting a wide range of use cases from simple counters to complex histograms.

Key components of the OpenTelemetry metrics data model include:

  • Instruments: The primary mechanism for recording measurements. Each instrument type (e.g., counter, gauge, histogram) serves a specific purpose.
  • Attributes: Key-value pairs that provide context to each measurement, such as service name, region, or user ID.
  • Aggregation: The process of summarizing raw measurements into meaningful statistics (e.g., sum, average, percentiles).
  • Time Series: Metrics are stored as time series, allowing for trend analysis and historical comparisons.

This model enables high cardinality (many unique attribute combinations) without sacrificing performance, making it suitable for large-scale, distributed systems. By adhering to the OpenTelemetry metrics data model, organizations can ensure their observability data remains portable and vendor-neutral. To get the most out of your observability data, consider exploring modern mobile observability solutions that leverage OpenTelemetry standards for real-time insights and actionable analytics.

Counter Metrics: Tracking Cumulative Values with Examples

Counter metrics are one of the most fundamental types in the OpenTelemetry metrics ecosystem. A counter is a monotonically increasing value, ideal for tracking cumulative quantities such as the number of requests, errors, or bytes sent over time.

How Counters Work

  • Monotonicity: Counters can only increase or reset to zero; they never decrease.
  • Use Cases: Suitable for events that accumulate, such as API calls, processed jobs, or user sign-ups.
  • Aggregation: Typically aggregated as a sum over a given time interval.

Example: HTTP Request Counter

Suppose you want to monitor the total number of HTTP requests handled by your application:

from opentelemetry import metrics

meter = metrics.get_meter(__name__)

request_counter = meter.create_counter(

    name=”http_requests_total”,

    description=”Total number of HTTP requests received”,

    unit=”requests”

)

# Increment the counter for each request

request_counter.add(1, {“method”: “GET”, “endpoint”: “/api/data”})

This counter provides a clear view of traffic patterns and can be broken down by method or endpoint using attributes. For deeper application performance insights, leverage app performance monitoring tools that integrate seamlessly with OpenTelemetry counters.

Gauge Metrics: Monitoring Current State and Values

Gauge metrics represent a snapshot of a value at a specific point in time. Unlike counters, gauges can increase or decrease, making them ideal for tracking metrics that fluctuate, such as memory usage, CPU load, or active user sessions.

How Gauges Work

  • Bidirectional: Gauges can go up or down, reflecting real-time state.
  • Use Cases: Monitor resources or quantities that are not strictly cumulative.
  • Aggregation: Typically reported as the latest value, but can also be averaged or summarized over time.

Example: Memory Usage Gauge

To monitor the current memory usage of your application:

memory_gauge = meter.create_observable_gauge(

    name=”memory_usage_bytes”,

    description=”Current memory usage in bytes”,

    unit=”bytes”

)

def memory_callback(observer):

    memory = get_current_memory_usage()

    observer.observe(memory, {“service”: “web”})

meter.register_callback(memory_callback, [memory_gauge])

This gauge provides up-to-date insights into resource consumption, supporting proactive scaling and troubleshooting. You can enhance your monitoring and alerting capabilities even further with custom dashboards and alerting tailored for OpenTelemetry metrics.

Histogram Metrics: Analyzing Distribution and Latency Patterns

Histogram metrics capture the distribution of values over time, making them essential for analyzing latency, response times, and other performance characteristics that benefit from percentile-based insights.

How Histograms Work

  • Buckets: Values are grouped into configurable buckets, allowing for detailed analysis of distribution.
  • Use Cases: Measure request durations, payload sizes, or any metric where understanding spread and outliers is important.
  • Aggregation: Supports calculation of percentiles (e.g., p95, p99), averages, and counts per bucket.

Example: Request Latency Histogram

To analyze the distribution of HTTP request latencies:

latency_histogram = meter.create_histogram(

    name=”http_request_duration_seconds”,

    description=”Distribution of HTTP request durations”,

    unit=”seconds”

)

# Record latency for each request

latency_histogram.record(duration, {“endpoint”: “/api/data”})

This histogram enables you to identify slow endpoints, track improvements, and set meaningful SLOs based on real user experiences. For organizations focused on maintaining high-quality user experiences, mobile SLO management can help you define, monitor, and achieve your performance objectives using insights from OpenTelemetry histograms.

Take the Next Step in Observability

Ready to unlock the full potential of OpenTelemetry metrics for your applications? Gain deeper insights, improve performance, and ensure a seamless user experience with expert observability solutions. Discover how advanced monitoring can transform your operations—request a personalized demo today.

Frequently Asked Questions
Related Content
The Embrace and OpenTelemtry logos.

Getting started with OpenTelemetry for mobile: Key takeaways

Mobile engineers often hear that OpenTelemetry is the standard — but applying it to mobile is harder than it looks. In our latest Getting Started webinar, we walked through the pitfalls of vanilla OTel and how Embrace helps teams instrument in minutes. Here’s the recap, with clips and resources to help you try it yourself.