Skip to content

Create the foundational metrics module using OpenTelemetry Metrics API with support for counters, histograms, and gauges #461

Description

@psschwei

Description:
Create the foundational metrics module using OpenTelemetry Metrics API with support for counters, histograms, and gauges.

Detailed Requirements:

  1. Create mellea/telemetry/metrics.py module with:
    • Lazy initialization of MeterProvider (similar to tracing pattern)
    • Environment-based configuration (MELLEA_METRICS_ENABLED)
    • Zero overhead when disabled (no-op instruments)
    • Named meter: mellea.metrics
  2. Define base instrument creation helpers:
    • create_counter(name, description, unit)
    • create_histogram(name, description, unit, boundaries)
    • create_up_down_counter(name, description, unit)
  3. Add dependencies to optional [telemetry] extra:
    • opentelemetry-sdk (already present)
    • Ensure metrics API available

Files to Create:

  • mellea/telemetry/metrics.py

Files to Modify:

  • mellea/telemetry/__init__.py - Export metrics functions
  • pyproject.toml - Verify metrics dependencies in telemetry extra

Environment Variables:

Variable Default Description
MELLEA_METRICS_ENABLED false Enable metrics collection
MELLEA_METRICS_CONSOLE false Print metrics to console (debug)

Acceptance Criteria:

  • MeterProvider initialized on first metric creation
  • Instruments are no-ops when metrics disabled
  • Counter, histogram, up-down-counter creation works
  • No import errors when opentelemetry not installed

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions