Skip to content

Integrate OpenTelemetry Metrics API #1446

@drmingdrmer

Description

@drmingdrmer

Context

Following @ariesdevil's suggestion in #1445, we should standardize metrics collection using OpenTelemetry instead of custom histogram implementations.

Proposal

Integrate the OpenTelemetry Metrics API to replace custom metric collection with industry-standard observability.

Technical Approach

  • Depend on opentelemetry-api crate only (not the SDK)
  • Replace custom histogram with OTEL Histogram instrument
  • Use OTEL semantic conventions for metric naming
  • Let applications configure SDK and exporters

Benefits

  1. Industry standard: Compatible with existing OTEL infrastructure (Prometheus, Jaeger, etc.)
  2. Zero runtime overhead for libraries: API is lightweight; SDK dependency stays in applications
  3. Flexibility: Applications choose exporters (OTLP, Prometheus, StatsD, etc.)
  4. Better instrumentation: Standardized metric names and attributes

Migration Strategy

  1. Add opentelemetry-api as dependency
  2. Replace custom histogram in feat: add histogram-based statistics for Apply batch sizes #1445 with OTEL Histogram
  3. Define metric instruments (histograms, counters, gauges) for existing metrics
  4. Update examples to show SDK configuration
  5. Add feature flag for OTEL support (optional migration path)

Implementation Notes

Since OTEL separates API from SDK:

  • openraft (library): Depends on opentelemetry-api only
  • Applications: Add opentelemetry-sdk and choose exporters
  • No-op by default: If app doesn't configure SDK, metrics collection has minimal overhead

Related: #1445

Metadata

Metadata

Assignees

No one assigned

    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