Course contentsShow
← Software Engineering
Lesson 1140 of 1,93334. Logging and ObservabilityFree lesson

Metric Naming and Labels

Creating consistent, queryable metric names and using labels for dimensional drill-down without explosion.

Metric Naming and Labels

You'll learn how to name metrics consistently and use labels effectively for powerful drill-down analysis without creating a maintenance nightmare.

The Core Idea

Metric names and labels are like a filing system for your operational data. A metric name identifies what you're measuring (e.g., http_requests_total), while labels (also called tags or dimensions) add who, where, or how context (e.g., method=GET, status=200, endpoint=/api/users). Good naming creates queryable patterns; smart labeling enables dimensional analysis without exploding the number of unique metrics.

Naming Conventions

Use clear, hierarchical names that group related metrics:

  • http_requests_total ✓
  • http_request_duration_seconds ✓
  • RequestCount ✗ (inconsistent)

Common patterns:

  • Prefix by subsystem: http_, db_, cache_
  • Suffix by unit: _total, _seconds, _bytes
  • Use underscores, not camelCase: easier to read in dashboards

Labels: Power and Peril

Labels let you slice one metric many ways:

http_requests_total{method="GET", status="200", endpoint="/users"}
http_requests_total{method="POST", status="500", endpoint="/login"}

Cardinality matters: Each unique label combination creates a new time series. High-cardinality labels (user IDs, timestamps) can explode storage costs. Keep cardinality bounded—labels should represent dimensions you'll actually query, not infinite values.

Think of labels as spreadsheet columns: method with 5 values and status with 10 values = 50 combinations. Add user_id with 1 million values? Now you have a problem.

Key Takeaway:
Name metrics with consistent, hierarchical patterns and use low-cardinality labels for dimensional filtering—high-cardinality values belong in logs, not metric labels.