← Back to Pull requests

[SMT-0003] Propose portable metric descriptions #245

Open
ManjunathAnawal opened this pull request with 185 lines diff across 1 files
View on GitHub
ManjunathAnawal ManjunathAnawal commented on Sep 22, 2026 11:39 UTC
Author

Propose SMT-0003: Portable metric descriptions via MetricDescriptor

Proposal: SMT-0003
Author(s): Manjunath Anawal ([@ManjunathAnawal](https://github.com/ManjunathAnawal))
Status: Draft (pre-review)
Implementation: [apple/swift-metrics#239](https://github.com/apple/swift-metrics/pull/239) (proof of concept, draft PR)

  • Related: #236. Succeeds #237, which proposed the same SMT-0003 slot and was closed without merging; this proposal reuses the number with maintainer agreement.
  • Motivation:

    Swift Metrics currently passes only a label and dimensions to backends, so there
    is no portable way to express a Prometheus/OpenMetrics HELP line or an OTLP
    instrument description. Relates to #236. Reuses the SMT-0003 slot from #237,
    which was closed without merging.

    Modifications:

    Added the proposal document at
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md — see that
    file for the full Summary, Design, Compatibility, and Alternatives sections.

    A proof-of-concept implementation is linked as draft PR #239.

    Result:

    Reviewers can discuss the design here before it goes to public review on
    forums.swift.org.

    Diff: 185 lines (+185 / -0) across 1 files Reviewer: kukushechkin Review duration: 28717m
    All Vouch review confidence checks passed
    Residual risk 0.04 = Change Risk (0.34) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.34 · 185 lines diff across 1 files
    0.34
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.89 · 5 substantive comment(s)
    0.89
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    89%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.313
    Real PR Conversation Timeline
    16 items
    kukushechkin kukushechkin commented on code on Sep 24, 2026 12:39 UTC
    Code Review
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md:1
    @@ -0,0 +1,108 @@
    +# SMT-0003: Portable metric descriptions via `MetricDescriptor`
    +
    +* Proposal: SMT-0003
    +* Author(s): Manjunath Anawal ([@ManjunathAnawal](https://github.com/ManjunathAnawal))
    +* Status: **Draft** (pre-review)
    +* Implementation: [apple/swift-metrics#239](https://github.com/apple/swift-metrics/pull/239) (proof of concept, draft PR)
    +* Related: #236. Succeeds #237, which proposed the same `SMT-0003` slot and was closed without merging; this proposal reuses the number with maintainer agreement.
    +
    +## Summary
    +
    +Add a `MetricDescriptor` type and descriptor-based factory methods to `CoreMetrics`,
    +so libraries can attach a human-readable description to a metric without turning it
    +into a dimension. Existing backends keep working unchanged; descriptor-aware backends
    +can opt in to receive the description.
    +
    +## Motivation
    +
    +Swift Metrics currently passes only a `label` and `dimensions` to backends. There is
    +no portable way to express:
    +
    +- a Prometheus / OpenMetrics `HELP` line, or
    +- an OpenTelemetry instrument `description`.
    +
    +Today this is worked around per-backend: `swift-prometheus` exposes a separate
    +registry API that takes `help:`, and `swift-otel` stuffs the description into a
    +dimension. Neither approach is portable, and stuffing it into a dimension risks
    +increasing cardinality unnecessarily.
    +
    +## Proposed solution
    +
    +Introduce a small, `Sendable` and `Equatable` `MetricDescriptor` struct that carries
    +`label`, `dimensions`, and an optional `description`, with a memberwise initializer
    +left open to evolve (for example, to add a `unit` field later without breaking
    +existing call sites).
    +
    +`MetricsFactory` gains descriptor-based factory requirements alongside the existing
    +`label:dimensions:` ones. Each new requirement ships a default implementation that
    +simply forwards `label` and `dimensions` to the existing method, so every backend
    +that implements `MetricsFactory` today keeps compiling and behaving exactly as
    +before. A backend only needs to override the descriptor-based method if it wants to
    +read the `description`.
    +
    +Convenience initializers on `Counter`, `FloatingPointCounter`, `Meter`, `Gauge`,
    +`Recorder`, and `Timer` let call sites construct a metric from a descriptor directly.
    +No existing initializer signature changes.
    +
    +## Detailed design

    Could you add the full API diff listing with the doc comments here?

    kukushechkin kukushechkin commented on code on Sep 24, 2026 12:42 UTC
    Code Review
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md:1
    @@ -0,0 +1,108 @@
    +# SMT-0003: Portable metric descriptions via `MetricDescriptor`
    +
    +* Proposal: SMT-0003
    +* Author(s): Manjunath Anawal ([@ManjunathAnawal](https://github.com/ManjunathAnawal))
    +* Status: **Draft** (pre-review)
    +* Implementation: [apple/swift-metrics#239](https://github.com/apple/swift-metrics/pull/239) (proof of concept, draft PR)
    +* Related: #236. Succeeds #237, which proposed the same `SMT-0003` slot and was closed without merging; this proposal reuses the number with maintainer agreement.
    +
    +## Summary
    +
    +Add a `MetricDescriptor` type and descriptor-based factory methods to `CoreMetrics`,
    +so libraries can attach a human-readable description to a metric without turning it
    +into a dimension. Existing backends keep working unchanged; descriptor-aware backends
    +can opt in to receive the description.
    +
    +## Motivation
    +
    +Swift Metrics currently passes only a `label` and `dimensions` to backends. There is
    +no portable way to express:
    +
    +- a Prometheus / OpenMetrics `HELP` line, or
    +- an OpenTelemetry instrument `description`.
    +
    +Today this is worked around per-backend: `swift-prometheus` exposes a separate
    +registry API that takes `help:`, and `swift-otel` stuffs the description into a
    +dimension. Neither approach is portable, and stuffing it into a dimension risks
    +increasing cardinality unnecessarily.
    +
    +## Proposed solution
    +
    +Introduce a small, `Sendable` and `Equatable` `MetricDescriptor` struct that carries
    +`label`, `dimensions`, and an optional `description`, with a memberwise initializer

    How about using metricDescription instead? Having .description breaks CustomStringConvertible conformance. While there are no existing users who could've added this conformance yet, it prevents from doing one in the future. And MetricDescriptor looks like a good candidate for such a conformance.

    kukushechkin kukushechkin commented on code on Sep 24, 2026 12:42 UTC
    Code Review
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md:1
    @@ -0,0 +1,108 @@
    +# SMT-0003: Portable metric descriptions via `MetricDescriptor`
    +
    +* Proposal: SMT-0003
    +* Author(s): Manjunath Anawal ([@ManjunathAnawal](https://github.com/ManjunathAnawal))
    +* Status: **Draft** (pre-review)
    +* Implementation: [apple/swift-metrics#239](https://github.com/apple/swift-metrics/pull/239) (proof of concept, draft PR)
    +* Related: #236. Succeeds #237, which proposed the same `SMT-0003` slot and was closed without merging; this proposal reuses the number with maintainer agreement.
    +
    +## Summary
    +
    +Add a `MetricDescriptor` type and descriptor-based factory methods to `CoreMetrics`,
    +so libraries can attach a human-readable description to a metric without turning it
    +into a dimension. Existing backends keep working unchanged; descriptor-aware backends
    +can opt in to receive the description.
    +
    +## Motivation
    +
    +Swift Metrics currently passes only a `label` and `dimensions` to backends. There is
    +no portable way to express:
    +
    +- a Prometheus / OpenMetrics `HELP` line, or
    +- an OpenTelemetry instrument `description`.
    +
    +Today this is worked around per-backend: `swift-prometheus` exposes a separate
    +registry API that takes `help:`, and `swift-otel` stuffs the description into a
    +dimension. Neither approach is portable, and stuffing it into a dimension risks
    +increasing cardinality unnecessarily.
    +
    +## Proposed solution

    Could add code examples using new APIs in the Proposed solution section?

    kukushechkin kukushechkin commented on code on Sep 24, 2026 12:43 UTC
    Code Review
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md:1
    @@ -0,0 +1,108 @@
    +# SMT-0003: Portable metric descriptions via `MetricDescriptor`
    +
    +* Proposal: SMT-0003
    +* Author(s): Manjunath Anawal ([@ManjunathAnawal](https://github.com/ManjunathAnawal))
    +* Status: **Draft** (pre-review)
    +* Implementation: [apple/swift-metrics#239](https://github.com/apple/swift-metrics/pull/239) (proof of concept, draft PR)
    +* Related: #236. Succeeds #237, which proposed the same `SMT-0003` slot and was closed without merging; this proposal reuses the number with maintainer agreement.
    +
    +## Summary
    +
    +Add a `MetricDescriptor` type and descriptor-based factory methods to `CoreMetrics`,
    +so libraries can attach a human-readable description to a metric without turning it
    +into a dimension. Existing backends keep working unchanged; descriptor-aware backends
    +can opt in to receive the description.
    +
    +## Motivation
    +
    +Swift Metrics currently passes only a `label` and `dimensions` to backends. There is
    +no portable way to express:
    +
    +- a Prometheus / OpenMetrics `HELP` line, or
    +- an OpenTelemetry instrument `description`.
    +
    +Today this is worked around per-backend: `swift-prometheus` exposes a separate
    +registry API that takes `help:`, and `swift-otel` stuffs the description into a

    registry API that takes `help:`, and `swift-otel` packs the description into a
    

    kukushechkin kukushechkin commented on code on Sep 24, 2026 12:44 UTC
    Code Review
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md:1
    @@ -0,0 +1,108 @@
    +# SMT-0003: Portable metric descriptions via `MetricDescriptor`
    +
    +* Proposal: SMT-0003
    +* Author(s): Manjunath Anawal ([@ManjunathAnawal](https://github.com/ManjunathAnawal))
    +* Status: **Draft** (pre-review)
    +* Implementation: [apple/swift-metrics#239](https://github.com/apple/swift-metrics/pull/239) (proof of concept, draft PR)
    +* Related: #236. Succeeds #237, which proposed the same `SMT-0003` slot and was closed without merging; this proposal reuses the number with maintainer agreement.
    +
    +## Summary
    +
    +Add a `MetricDescriptor` type and descriptor-based factory methods to `CoreMetrics`,
    +so libraries can attach a human-readable description to a metric without turning it
    +into a dimension. Existing backends keep working unchanged; descriptor-aware backends
    +can opt in to receive the description.
    +
    +## Motivation
    +
    +Swift Metrics currently passes only a `label` and `dimensions` to backends. There is
    +no portable way to express:
    +
    +- a Prometheus / OpenMetrics `HELP` line, or
    +- an OpenTelemetry instrument `description`.
    +
    +Today this is worked around per-backend: `swift-prometheus` exposes a separate
    +registry API that takes `help:`, and `swift-otel` stuffs the description into a
    +dimension. Neither approach is portable, and stuffing it into a dimension risks
    +increasing cardinality unnecessarily.
    +
    +## Proposed solution
    +
    +Introduce a small, `Sendable` and `Equatable` `MetricDescriptor` struct that carries
    +`label`, `dimensions`, and an optional `description`, with a memberwise initializer
    +left open to evolve (for example, to add a `unit` field later without breaking
    +existing call sites).
    +
    +`MetricsFactory` gains descriptor-based factory requirements alongside the existing
    +`label:dimensions:` ones. Each new requirement ships a default implementation that

    `label:dimensions:` ones. Each new requirement provides a default implementation that
    

    kukushechkin kukushechkin commented on code on Sep 24, 2026 12:44 UTC
    Code Review
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md:1
    @@ -0,0 +1,108 @@
    +# SMT-0003: Portable metric descriptions via `MetricDescriptor`
    +
    +* Proposal: SMT-0003
    +* Author(s): Manjunath Anawal ([@ManjunathAnawal](https://github.com/ManjunathAnawal))
    +* Status: **Draft** (pre-review)
    +* Implementation: [apple/swift-metrics#239](https://github.com/apple/swift-metrics/pull/239) (proof of concept, draft PR)
    +* Related: #236. Succeeds #237, which proposed the same `SMT-0003` slot and was closed without merging; this proposal reuses the number with maintainer agreement.
    +
    +## Summary
    +
    +Add a `MetricDescriptor` type and descriptor-based factory methods to `CoreMetrics`,
    +so libraries can attach a human-readable description to a metric without turning it
    +into a dimension. Existing backends keep working unchanged; descriptor-aware backends
    +can opt in to receive the description.
    +
    +## Motivation
    +
    +Swift Metrics currently passes only a `label` and `dimensions` to backends. There is
    +no portable way to express:
    +
    +- a Prometheus / OpenMetrics `HELP` line, or
    +- an OpenTelemetry instrument `description`.
    +
    +Today this is worked around per-backend: `swift-prometheus` exposes a separate
    +registry API that takes `help:`, and `swift-otel` stuffs the description into a
    +dimension. Neither approach is portable, and stuffing it into a dimension risks
    +increasing cardinality unnecessarily.
    +
    +## Proposed solution
    +
    +Introduce a small, `Sendable` and `Equatable` `MetricDescriptor` struct that carries
    +`label`, `dimensions`, and an optional `description`, with a memberwise initializer
    +left open to evolve (for example, to add a `unit` field later without breaking
    +existing call sites).
    +
    +`MetricsFactory` gains descriptor-based factory requirements alongside the existing
    +`label:dimensions:` ones. Each new requirement ships a default implementation that
    +simply forwards `label` and `dimensions` to the existing method, so every backend
    +that implements `MetricsFactory` today keeps compiling and behaving exactly as
    +before. A backend only needs to override the descriptor-based method if it wants to
    +read the `description`.
    +
    +Convenience initializers on `Counter`, `FloatingPointCounter`, `Meter`, `Gauge`,
    +`Recorder`, and `Timer` let call sites construct a metric from a descriptor directly.
    +No existing initializer signature changes.
    +
    +## Detailed design
    +
    +- **`MetricDescriptor`** (in `CoreMetrics`): `Sendable`, `Equatable`, holds `label`,
    +  `dimensions`, and an optional `description`.
    +- **Five new `MetricsFactory` requirements**, each with a default implementation that
    +  forwards to the existing `makeXXX(label:dimensions:)` method:
    +  - `makeCounter(descriptor:)`
    +  - `makeFloatingPointCounter(descriptor:)`
    +  - `makeMeter(descriptor:)`
    +  - `makeRecorder(descriptor:aggregate:)`
    +  - `makeTimer(descriptor:)`
    +- **Descriptor-based convenience initializers** on `Counter`, `FloatingPointCounter`,
    +  `Meter`, `Gauge`, `Recorder`, and `Timer` (including the `preferredDisplayUnit`
    +  variant).
    +- **`MultiplexMetricsHandler`** forwards the descriptor to every sub-factory.

    - **`MultiplexMetricsHandler`** forwards the descriptor to every underlying factory.
    

    kukushechkin kukushechkin commented on code on Sep 24, 2026 12:45 UTC
    Code Review
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md:1
    @@ -0,0 +1,108 @@
    +# SMT-0003: Portable metric descriptions via `MetricDescriptor`
    +
    +* Proposal: SMT-0003
    +* Author(s): Manjunath Anawal ([@ManjunathAnawal](https://github.com/ManjunathAnawal))
    +* Status: **Draft** (pre-review)
    +* Implementation: [apple/swift-metrics#239](https://github.com/apple/swift-metrics/pull/239) (proof of concept, draft PR)
    +* Related: #236. Succeeds #237, which proposed the same `SMT-0003` slot and was closed without merging; this proposal reuses the number with maintainer agreement.
    +
    +## Summary
    +
    +Add a `MetricDescriptor` type and descriptor-based factory methods to `CoreMetrics`,
    +so libraries can attach a human-readable description to a metric without turning it
    +into a dimension. Existing backends keep working unchanged; descriptor-aware backends
    +can opt in to receive the description.
    +
    +## Motivation
    +
    +Swift Metrics currently passes only a `label` and `dimensions` to backends. There is
    +no portable way to express:
    +
    +- a Prometheus / OpenMetrics `HELP` line, or
    +- an OpenTelemetry instrument `description`.
    +
    +Today this is worked around per-backend: `swift-prometheus` exposes a separate
    +registry API that takes `help:`, and `swift-otel` stuffs the description into a
    +dimension. Neither approach is portable, and stuffing it into a dimension risks
    +increasing cardinality unnecessarily.
    +
    +## Proposed solution
    +
    +Introduce a small, `Sendable` and `Equatable` `MetricDescriptor` struct that carries
    +`label`, `dimensions`, and an optional `description`, with a memberwise initializer
    +left open to evolve (for example, to add a `unit` field later without breaking
    +existing call sites).
    +
    +`MetricsFactory` gains descriptor-based factory requirements alongside the existing
    +`label:dimensions:` ones. Each new requirement ships a default implementation that
    +simply forwards `label` and `dimensions` to the existing method, so every backend
    +that implements `MetricsFactory` today keeps compiling and behaving exactly as
    +before. A backend only needs to override the descriptor-based method if it wants to
    +read the `description`.
    +
    +Convenience initializers on `Counter`, `FloatingPointCounter`, `Meter`, `Gauge`,
    +`Recorder`, and `Timer` let call sites construct a metric from a descriptor directly.
    +No existing initializer signature changes.
    +
    +## Detailed design
    +
    +- **`MetricDescriptor`** (in `CoreMetrics`): `Sendable`, `Equatable`, holds `label`,
    +  `dimensions`, and an optional `description`.
    +- **Five new `MetricsFactory` requirements**, each with a default implementation that
    +  forwards to the existing `makeXXX(label:dimensions:)` method:
    +  - `makeCounter(descriptor:)`
    +  - `makeFloatingPointCounter(descriptor:)`
    +  - `makeMeter(descriptor:)`
    +  - `makeRecorder(descriptor:aggregate:)`
    +  - `makeTimer(descriptor:)`
    +- **Descriptor-based convenience initializers** on `Counter`, `FloatingPointCounter`,
    +  `Meter`, `Gauge`, `Recorder`, and `Timer` (including the `preferredDisplayUnit`
    +  variant).
    +- **`MultiplexMetricsHandler`** forwards the descriptor to every sub-factory.
    +- **`MappingMetricsFactory`** transforms `label`/`dimensions` while preserving
    +  `description`.
    +- **`TestMetrics`** stores the full descriptor, with `label`/`dimensions` exposed as
    +  computed properties so existing test code that reads them keeps working, and new
    +  tests can assert on `description`.
    +
    +Full code is intentionally not inlined here — see the linked implementation PR for
    +the diff.
    +
    +## Compatibility
    +
    +- No existing public API is changed or removed.
    +- Every existing `MetricsFactory` conformance compiles unchanged, because the new
    +  requirements have default implementations.
    +- `swift package diagnose-api-breaking-changes` reports no breaking changes in
    +  `CoreMetrics`, `Metrics`, or `MetricsTestKit` for the PoC in #239.
    +
    +## Alternatives considered
    +
    +- **Put `description` in `dimensions`.** Rejected — this is what backends already do
    +  as a workaround, and it risks increasing cardinality since dimensions are commonly
    +  used for grouping/filtering.
    +- **`MetricDescription` as the type name**, instead of `MetricDescriptor`. Open for
    +  discussion; naming bikeshed, no functional difference.
    +- **Silent vs. surfaced fallback.** When a backend does not override the
    +  descriptor-based factory method, the description is currently dropped silently.
    +  An alternative is to make that drop observable somehow (for example via a debug
    +  log or a `Metrics` bootstrap warning) so authors notice a description isn't being
    +  used. Needs input from backend authors before deciding.
    +- **Where `aggregate` lives for `Recorder`.** The PoC keeps `aggregate` as a separate
    +  parameter alongside `descriptor:` rather than folding it into `MetricDescriptor`
    +  itself, to avoid growing the descriptor with parameters that only apply to one
    +  metric kind.
    +
    +## Open questions for reviewers

    In the final version of the proposal this section should not be present.

    kukushechkin kukushechkin commented on code on Sep 24, 2026 12:46 UTC
    Code Review
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md:1
    @@ -0,0 +1,108 @@
    +# SMT-0003: Portable metric descriptions via `MetricDescriptor`
    +
    +* Proposal: SMT-0003
    +* Author(s): Manjunath Anawal ([@ManjunathAnawal](https://github.com/ManjunathAnawal))
    +* Status: **Draft** (pre-review)
    +* Implementation: [apple/swift-metrics#239](https://github.com/apple/swift-metrics/pull/239) (proof of concept, draft PR)
    +* Related: #236. Succeeds #237, which proposed the same `SMT-0003` slot and was closed without merging; this proposal reuses the number with maintainer agreement.
    +
    +## Summary
    +
    +Add a `MetricDescriptor` type and descriptor-based factory methods to `CoreMetrics`,
    +so libraries can attach a human-readable description to a metric without turning it
    +into a dimension. Existing backends keep working unchanged; descriptor-aware backends
    +can opt in to receive the description.
    +
    +## Motivation
    +
    +Swift Metrics currently passes only a `label` and `dimensions` to backends. There is
    +no portable way to express:
    +
    +- a Prometheus / OpenMetrics `HELP` line, or
    +- an OpenTelemetry instrument `description`.
    +
    +Today this is worked around per-backend: `swift-prometheus` exposes a separate
    +registry API that takes `help:`, and `swift-otel` stuffs the description into a
    +dimension. Neither approach is portable, and stuffing it into a dimension risks
    +increasing cardinality unnecessarily.
    +
    +## Proposed solution
    +
    +Introduce a small, `Sendable` and `Equatable` `MetricDescriptor` struct that carries
    +`label`, `dimensions`, and an optional `description`, with a memberwise initializer
    +left open to evolve (for example, to add a `unit` field later without breaking
    +existing call sites).
    +
    +`MetricsFactory` gains descriptor-based factory requirements alongside the existing
    +`label:dimensions:` ones. Each new requirement ships a default implementation that
    +simply forwards `label` and `dimensions` to the existing method, so every backend
    +that implements `MetricsFactory` today keeps compiling and behaving exactly as
    +before. A backend only needs to override the descriptor-based method if it wants to
    +read the `description`.
    +
    +Convenience initializers on `Counter`, `FloatingPointCounter`, `Meter`, `Gauge`,
    +`Recorder`, and `Timer` let call sites construct a metric from a descriptor directly.
    +No existing initializer signature changes.
    +
    +## Detailed design
    +
    +- **`MetricDescriptor`** (in `CoreMetrics`): `Sendable`, `Equatable`, holds `label`,
    +  `dimensions`, and an optional `description`.
    +- **Five new `MetricsFactory` requirements**, each with a default implementation that
    +  forwards to the existing `makeXXX(label:dimensions:)` method:
    +  - `makeCounter(descriptor:)`
    +  - `makeFloatingPointCounter(descriptor:)`
    +  - `makeMeter(descriptor:)`
    +  - `makeRecorder(descriptor:aggregate:)`
    +  - `makeTimer(descriptor:)`
    +- **Descriptor-based convenience initializers** on `Counter`, `FloatingPointCounter`,
    +  `Meter`, `Gauge`, `Recorder`, and `Timer` (including the `preferredDisplayUnit`
    +  variant).
    +- **`MultiplexMetricsHandler`** forwards the descriptor to every sub-factory.
    +- **`MappingMetricsFactory`** transforms `label`/`dimensions` while preserving
    +  `description`.
    +- **`TestMetrics`** stores the full descriptor, with `label`/`dimensions` exposed as
    +  computed properties so existing test code that reads them keeps working, and new
    +  tests can assert on `description`.
    +
    +Full code is intentionally not inlined here — see the linked implementation PR for
    +the diff.
    +
    +## Compatibility
    +
    +- No existing public API is changed or removed.
    +- Every existing `MetricsFactory` conformance compiles unchanged, because the new
    +  requirements have default implementations.
    +- `swift package diagnose-api-breaking-changes` reports no breaking changes in
    +  `CoreMetrics`, `Metrics`, or `MetricsTestKit` for the PoC in #239.
    +
    +## Alternatives considered
    +
    +- **Put `description` in `dimensions`.** Rejected — this is what backends already do
    +  as a workaround, and it risks increasing cardinality since dimensions are commonly
    +  used for grouping/filtering.
    +- **`MetricDescription` as the type name**, instead of `MetricDescriptor`. Open for
    +  discussion; naming bikeshed, no functional difference.
    +- **Silent vs. surfaced fallback.** When a backend does not override the
    +  descriptor-based factory method, the description is currently dropped silently.
    +  An alternative is to make that drop observable somehow (for example via a debug
    +  log or a `Metrics` bootstrap warning) so authors notice a description isn't being
    +  used. Needs input from backend authors before deciding.
    +- **Where `aggregate` lives for `Recorder`.** The PoC keeps `aggregate` as a separate
    +  parameter alongside `descriptor:` rather than folding it into `MetricDescriptor`
    +  itself, to avoid growing the descriptor with parameters that only apply to one
    +  metric kind.
    +
    +## Open questions for reviewers
    +
    +- `MetricDescriptor` vs `MetricDescription` naming.
    +- Whether `aggregate` should move inside the descriptor for `Recorder`.
    +- Whether a dropped `description` (unsupported backend) should be silent or surfaced.
    +
    +## Implementation

    The implementation is already linked in the proposal header, no need for this section.

    kukushechkin kukushechkin commented on code on Sep 24, 2026 12:46 UTC
    Code Review
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md:1
    @@ -0,0 +1,108 @@
    +# SMT-0003: Portable metric descriptions via `MetricDescriptor`
    +
    +* Proposal: SMT-0003
    +* Author(s): Manjunath Anawal ([@ManjunathAnawal](https://github.com/ManjunathAnawal))
    +* Status: **Draft** (pre-review)
    +* Implementation: [apple/swift-metrics#239](https://github.com/apple/swift-metrics/pull/239) (proof of concept, draft PR)
    +* Related: #236. Succeeds #237, which proposed the same `SMT-0003` slot and was closed without merging; this proposal reuses the number with maintainer agreement.
    +
    +## Summary
    +
    +Add a `MetricDescriptor` type and descriptor-based factory methods to `CoreMetrics`,
    +so libraries can attach a human-readable description to a metric without turning it
    +into a dimension. Existing backends keep working unchanged; descriptor-aware backends
    +can opt in to receive the description.
    +
    +## Motivation
    +
    +Swift Metrics currently passes only a `label` and `dimensions` to backends. There is
    +no portable way to express:
    +
    +- a Prometheus / OpenMetrics `HELP` line, or
    +- an OpenTelemetry instrument `description`.
    +
    +Today this is worked around per-backend: `swift-prometheus` exposes a separate
    +registry API that takes `help:`, and `swift-otel` stuffs the description into a
    +dimension. Neither approach is portable, and stuffing it into a dimension risks
    +increasing cardinality unnecessarily.
    +
    +## Proposed solution
    +
    +Introduce a small, `Sendable` and `Equatable` `MetricDescriptor` struct that carries
    +`label`, `dimensions`, and an optional `description`, with a memberwise initializer
    +left open to evolve (for example, to add a `unit` field later without breaking
    +existing call sites).
    +
    +`MetricsFactory` gains descriptor-based factory requirements alongside the existing
    +`label:dimensions:` ones. Each new requirement ships a default implementation that
    +simply forwards `label` and `dimensions` to the existing method, so every backend
    +that implements `MetricsFactory` today keeps compiling and behaving exactly as
    +before. A backend only needs to override the descriptor-based method if it wants to
    +read the `description`.
    +
    +Convenience initializers on `Counter`, `FloatingPointCounter`, `Meter`, `Gauge`,
    +`Recorder`, and `Timer` let call sites construct a metric from a descriptor directly.
    +No existing initializer signature changes.
    +
    +## Detailed design
    +
    +- **`MetricDescriptor`** (in `CoreMetrics`): `Sendable`, `Equatable`, holds `label`,
    +  `dimensions`, and an optional `description`.
    +- **Five new `MetricsFactory` requirements**, each with a default implementation that
    +  forwards to the existing `makeXXX(label:dimensions:)` method:
    +  - `makeCounter(descriptor:)`
    +  - `makeFloatingPointCounter(descriptor:)`
    +  - `makeMeter(descriptor:)`
    +  - `makeRecorder(descriptor:aggregate:)`
    +  - `makeTimer(descriptor:)`
    +- **Descriptor-based convenience initializers** on `Counter`, `FloatingPointCounter`,
    +  `Meter`, `Gauge`, `Recorder`, and `Timer` (including the `preferredDisplayUnit`
    +  variant).
    +- **`MultiplexMetricsHandler`** forwards the descriptor to every sub-factory.
    +- **`MappingMetricsFactory`** transforms `label`/`dimensions` while preserving
    +  `description`.
    +- **`TestMetrics`** stores the full descriptor, with `label`/`dimensions` exposed as
    +  computed properties so existing test code that reads them keeps working, and new
    +  tests can assert on `description`.
    +
    +Full code is intentionally not inlined here — see the linked implementation PR for
    +the diff.
    +
    +## Compatibility
    +
    +- No existing public API is changed or removed.
    +- Every existing `MetricsFactory` conformance compiles unchanged, because the new
    +  requirements have default implementations.
    +- `swift package diagnose-api-breaking-changes` reports no breaking changes in
    +  `CoreMetrics`, `Metrics`, or `MetricsTestKit` for the PoC in #239.
    +
    +## Alternatives considered
    +
    +- **Put `description` in `dimensions`.** Rejected — this is what backends already do
    +  as a workaround, and it risks increasing cardinality since dimensions are commonly
    +  used for grouping/filtering.
    +- **`MetricDescription` as the type name**, instead of `MetricDescriptor`. Open for
    +  discussion; naming bikeshed, no functional difference.
    +- **Silent vs. surfaced fallback.** When a backend does not override the
    +  descriptor-based factory method, the description is currently dropped silently.
    +  An alternative is to make that drop observable somehow (for example via a debug
    +  log or a `Metrics` bootstrap warning) so authors notice a description isn't being
    +  used. Needs input from backend authors before deciding.
    +- **Where `aggregate` lives for `Recorder`.** The PoC keeps `aggregate` as a separate
    +  parameter alongside `descriptor:` rather than folding it into `MetricDescriptor`
    +  itself, to avoid growing the descriptor with parameters that only apply to one
    +  metric kind.
    +
    +## Open questions for reviewers
    +
    +- `MetricDescriptor` vs `MetricDescription` naming.

    Should match the property holding it and I have concerns about .description.

    kukushechkin kukushechkin commented on code on Sep 24, 2026 12:47 UTC
    Code Review
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md:1
    @@ -0,0 +1,108 @@
    +# SMT-0003: Portable metric descriptions via `MetricDescriptor`
    +
    +* Proposal: SMT-0003
    +* Author(s): Manjunath Anawal ([@ManjunathAnawal](https://github.com/ManjunathAnawal))
    +* Status: **Draft** (pre-review)
    +* Implementation: [apple/swift-metrics#239](https://github.com/apple/swift-metrics/pull/239) (proof of concept, draft PR)
    +* Related: #236. Succeeds #237, which proposed the same `SMT-0003` slot and was closed without merging; this proposal reuses the number with maintainer agreement.
    +
    +## Summary
    +
    +Add a `MetricDescriptor` type and descriptor-based factory methods to `CoreMetrics`,
    +so libraries can attach a human-readable description to a metric without turning it
    +into a dimension. Existing backends keep working unchanged; descriptor-aware backends
    +can opt in to receive the description.
    +
    +## Motivation
    +
    +Swift Metrics currently passes only a `label` and `dimensions` to backends. There is
    +no portable way to express:
    +
    +- a Prometheus / OpenMetrics `HELP` line, or
    +- an OpenTelemetry instrument `description`.
    +
    +Today this is worked around per-backend: `swift-prometheus` exposes a separate
    +registry API that takes `help:`, and `swift-otel` stuffs the description into a
    +dimension. Neither approach is portable, and stuffing it into a dimension risks
    +increasing cardinality unnecessarily.
    +
    +## Proposed solution
    +
    +Introduce a small, `Sendable` and `Equatable` `MetricDescriptor` struct that carries
    +`label`, `dimensions`, and an optional `description`, with a memberwise initializer
    +left open to evolve (for example, to add a `unit` field later without breaking
    +existing call sites).
    +
    +`MetricsFactory` gains descriptor-based factory requirements alongside the existing
    +`label:dimensions:` ones. Each new requirement ships a default implementation that
    +simply forwards `label` and `dimensions` to the existing method, so every backend
    +that implements `MetricsFactory` today keeps compiling and behaving exactly as
    +before. A backend only needs to override the descriptor-based method if it wants to
    +read the `description`.
    +
    +Convenience initializers on `Counter`, `FloatingPointCounter`, `Meter`, `Gauge`,
    +`Recorder`, and `Timer` let call sites construct a metric from a descriptor directly.
    +No existing initializer signature changes.
    +
    +## Detailed design
    +
    +- **`MetricDescriptor`** (in `CoreMetrics`): `Sendable`, `Equatable`, holds `label`,
    +  `dimensions`, and an optional `description`.
    +- **Five new `MetricsFactory` requirements**, each with a default implementation that
    +  forwards to the existing `makeXXX(label:dimensions:)` method:
    +  - `makeCounter(descriptor:)`
    +  - `makeFloatingPointCounter(descriptor:)`
    +  - `makeMeter(descriptor:)`
    +  - `makeRecorder(descriptor:aggregate:)`
    +  - `makeTimer(descriptor:)`
    +- **Descriptor-based convenience initializers** on `Counter`, `FloatingPointCounter`,
    +  `Meter`, `Gauge`, `Recorder`, and `Timer` (including the `preferredDisplayUnit`
    +  variant).
    +- **`MultiplexMetricsHandler`** forwards the descriptor to every sub-factory.
    +- **`MappingMetricsFactory`** transforms `label`/`dimensions` while preserving
    +  `description`.
    +- **`TestMetrics`** stores the full descriptor, with `label`/`dimensions` exposed as
    +  computed properties so existing test code that reads them keeps working, and new
    +  tests can assert on `description`.
    +
    +Full code is intentionally not inlined here — see the linked implementation PR for
    +the diff.
    +
    +## Compatibility
    +
    +- No existing public API is changed or removed.
    +- Every existing `MetricsFactory` conformance compiles unchanged, because the new
    +  requirements have default implementations.
    +- `swift package diagnose-api-breaking-changes` reports no breaking changes in
    +  `CoreMetrics`, `Metrics`, or `MetricsTestKit` for the PoC in #239.
    +
    +## Alternatives considered
    +
    +- **Put `description` in `dimensions`.** Rejected — this is what backends already do
    +  as a workaround, and it risks increasing cardinality since dimensions are commonly
    +  used for grouping/filtering.
    +- **`MetricDescription` as the type name**, instead of `MetricDescriptor`. Open for
    +  discussion; naming bikeshed, no functional difference.
    +- **Silent vs. surfaced fallback.** When a backend does not override the
    +  descriptor-based factory method, the description is currently dropped silently.
    +  An alternative is to make that drop observable somehow (for example via a debug
    +  log or a `Metrics` bootstrap warning) so authors notice a description isn't being
    +  used. Needs input from backend authors before deciding.
    +- **Where `aggregate` lives for `Recorder`.** The PoC keeps `aggregate` as a separate
    +  parameter alongside `descriptor:` rather than folding it into `MetricDescriptor`
    +  itself, to avoid growing the descriptor with parameters that only apply to one
    +  metric kind.
    +
    +## Open questions for reviewers
    +
    +- `MetricDescriptor` vs `MetricDescription` naming.
    +- Whether `aggregate` should move inside the descriptor for `Recorder`.

    How would it move, would it require a new structure specifically for Recorder?

    ManjunathAnawal ManjunathAnawal commented on Sep 24, 2026 13:43 UTC
    Author

    @kukushechkin ,

    Updated — renamed to metricDescription, added the full API diff and an example, removed the Open questions section. For aggregate: kept it as a separate parameter on makeRecorder(descriptor:aggregate:) rather than folding it into MetricDescriptor, since it only applies to Recorder — happy to reconsider if you'd rather see it moved.

    kukushechkin kukushechkin commented on code on Sep 29, 2026 10:37 UTC
    Code Review
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md:1
    @@ -22,51 +22,133 @@ no portable way to express:
     - an OpenTelemetry instrument `description`.
     
     Today this is worked around per-backend: `swift-prometheus` exposes a separate
    -registry API that takes `help:`, and `swift-otel` stuffs the description into a
    -dimension. Neither approach is portable, and stuffing it into a dimension risks
    +registry API that takes `help:`, and `swift-otel` packs the description into a
    +dimension. Neither approach is portable, and packing it into a dimension risks
     increasing cardinality unnecessarily.
     
     ## Proposed solution
     
     Introduce a small, `Sendable` and `Equatable` `MetricDescriptor` struct that carries
    -`label`, `dimensions`, and an optional `description`, with a memberwise initializer
    -left open to evolve (for example, to add a `unit` field later without breaking
    -existing call sites).
    +`label`, `dimensions`, and an optional `metricDescription`, with a memberwise
    +initializer left open to evolve (for example, to add a `unit` field later without
    +breaking existing call sites). The field is named `metricDescription` rather than
    +`description`, so `MetricDescriptor` remains free to conform to
    +`CustomStringConvertible` in the future without a naming clash.
     
     `MetricsFactory` gains descriptor-based factory requirements alongside the existing
    -`label:dimensions:` ones. Each new requirement ships a default implementation that
    -simply forwards `label` and `dimensions` to the existing method, so every backend
    -that implements `MetricsFactory` today keeps compiling and behaving exactly as
    -before. A backend only needs to override the descriptor-based method if it wants to
    -read the `description`.
    +`label:dimensions:` ones. Each new requirement provides a default implementation
    +that simply forwards `label` and `dimensions` to the existing method, so every
    +backend that implements `MetricsFactory` today keeps compiling and behaving exactly
    +as before. A backend only needs to override the descriptor-based method if it wants
    +to read the `metricDescription`.
     
     Convenience initializers on `Counter`, `FloatingPointCounter`, `Meter`, `Gauge`,
     `Recorder`, and `Timer` let call sites construct a metric from a descriptor directly.
     No existing initializer signature changes.
     
    +### Example
    +
    +```swift
    +// Before: no way to attach a description
    +let requests = Counter(label: "http_requests_total", dimensions: [("route", "/users")])
    +
    +// After: attach a description via MetricDescriptor
    +let descriptor = MetricDescriptor(
    +    label: "http_requests_total",
    +    dimensions: [("route", "/users")],
    +    metricDescription: "Total number of HTTP requests received"
    +)
    +let requests = Counter(descriptor: descriptor)
    +
    +// A descriptor-aware backend (e.g. swift-prometheus) can read metricDescription
    +// to emit a Prometheus HELP line; a backend that doesn't override the
    +// descriptor-based factory method simply falls back to label + dimensions,
    +// exactly as it does today.
    +```
    +
     ## Detailed design
     
    -- **`MetricDescriptor`** (in `CoreMetrics`): `Sendable`, `Equatable`, holds `label`,
    -  `dimensions`, and an optional `description`.
    -- **Five new `MetricsFactory` requirements**, each with a default implementation that
    -  forwards to the existing `makeXXX(label:dimensions:)` method:
    -  - `makeCounter(descriptor:)`
    -  - `makeFloatingPointCounter(descriptor:)`
    -  - `makeMeter(descriptor:)`
    -  - `makeRecorder(descriptor:aggregate:)`
    -  - `makeTimer(descriptor:)`
    -- **Descriptor-based convenience initializers** on `Counter`, `FloatingPointCounter`,
    -  `Meter`, `Gauge`, `Recorder`, and `Timer` (including the `preferredDisplayUnit`
    -  variant).
    -- **`MultiplexMetricsHandler`** forwards the descriptor to every sub-factory.
    -- **`MappingMetricsFactory`** transforms `label`/`dimensions` while preserving
    -  `description`.
    -- **`TestMetrics`** stores the full descriptor, with `label`/`dimensions` exposed as
    -  computed properties so existing test code that reads them keeps working, and new
    -  tests can assert on `description`.
    -
    -Full code is intentionally not inlined here — see the linked implementation PR for
    -the diff.
    +Full API diff, with doc comments, as implemented in the linked PoC (#239):

    I believe the PoC hasn't been updated with metricDescription change.

    kukushechkin kukushechkin commented on code on Sep 29, 2026 10:38 UTC
    Code Review
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md:1
    @@ -22,51 +22,133 @@ no portable way to express:
     - an OpenTelemetry instrument `description`.
     
     Today this is worked around per-backend: `swift-prometheus` exposes a separate
    -registry API that takes `help:`, and `swift-otel` stuffs the description into a
    -dimension. Neither approach is portable, and stuffing it into a dimension risks
    +registry API that takes `help:`, and `swift-otel` packs the description into a
    +dimension. Neither approach is portable, and packing it into a dimension risks
     increasing cardinality unnecessarily.
     
     ## Proposed solution
     
     Introduce a small, `Sendable` and `Equatable` `MetricDescriptor` struct that carries
    -`label`, `dimensions`, and an optional `description`, with a memberwise initializer
    -left open to evolve (for example, to add a `unit` field later without breaking
    -existing call sites).
    +`label`, `dimensions`, and an optional `metricDescription`, with a memberwise
    +initializer left open to evolve (for example, to add a `unit` field later without
    +breaking existing call sites). The field is named `metricDescription` rather than
    +`description`, so `MetricDescriptor` remains free to conform to
    +`CustomStringConvertible` in the future without a naming clash.
     
     `MetricsFactory` gains descriptor-based factory requirements alongside the existing
    -`label:dimensions:` ones. Each new requirement ships a default implementation that
    -simply forwards `label` and `dimensions` to the existing method, so every backend
    -that implements `MetricsFactory` today keeps compiling and behaving exactly as
    -before. A backend only needs to override the descriptor-based method if it wants to
    -read the `description`.
    +`label:dimensions:` ones. Each new requirement provides a default implementation
    +that simply forwards `label` and `dimensions` to the existing method, so every
    +backend that implements `MetricsFactory` today keeps compiling and behaving exactly
    +as before. A backend only needs to override the descriptor-based method if it wants
    +to read the `metricDescription`.
     
     Convenience initializers on `Counter`, `FloatingPointCounter`, `Meter`, `Gauge`,
     `Recorder`, and `Timer` let call sites construct a metric from a descriptor directly.
     No existing initializer signature changes.
     
    +### Example
    +
    +```swift
    +// Before: no way to attach a description
    +let requests = Counter(label: "http_requests_total", dimensions: [("route", "/users")])
    +
    +// After: attach a description via MetricDescriptor
    +let descriptor = MetricDescriptor(
    +    label: "http_requests_total",
    +    dimensions: [("route", "/users")],
    +    metricDescription: "Total number of HTTP requests received"
    +)
    +let requests = Counter(descriptor: descriptor)
    +
    +// A descriptor-aware backend (e.g. swift-prometheus) can read metricDescription
    +// to emit a Prometheus HELP line; a backend that doesn't override the
    +// descriptor-based factory method simply falls back to label + dimensions,
    +// exactly as it does today.
    +```
    +
     ## Detailed design
     
    -- **`MetricDescriptor`** (in `CoreMetrics`): `Sendable`, `Equatable`, holds `label`,
    -  `dimensions`, and an optional `description`.
    -- **Five new `MetricsFactory` requirements**, each with a default implementation that
    -  forwards to the existing `makeXXX(label:dimensions:)` method:
    -  - `makeCounter(descriptor:)`
    -  - `makeFloatingPointCounter(descriptor:)`
    -  - `makeMeter(descriptor:)`
    -  - `makeRecorder(descriptor:aggregate:)`
    -  - `makeTimer(descriptor:)`
    -- **Descriptor-based convenience initializers** on `Counter`, `FloatingPointCounter`,
    -  `Meter`, `Gauge`, `Recorder`, and `Timer` (including the `preferredDisplayUnit`
    -  variant).
    -- **`MultiplexMetricsHandler`** forwards the descriptor to every sub-factory.
    -- **`MappingMetricsFactory`** transforms `label`/`dimensions` while preserving
    -  `description`.
    -- **`TestMetrics`** stores the full descriptor, with `label`/`dimensions` exposed as
    -  computed properties so existing test code that reads them keeps working, and new
    -  tests can assert on `description`.
    -
    -Full code is intentionally not inlined here — see the linked implementation PR for
    -the diff.
    +Full API diff, with doc comments, as implemented in the linked PoC (#239):
    +
    +```swift
    +/// A portable description of a metric, carrying everything a backend needs to
    +/// register it, including an optional human-readable description.
    +public struct MetricDescriptor: Sendable, Equatable {
    +    /// The label identifying this metric.
    +    public let label: String
    +
    +    /// The dimensions (key-value pairs) attached to this metric.
    +    public let dimensions: [(String, String)]
    +
    +    /// An optional human-readable description of what this metric measures,
    +    /// e.g. surfaced as a Prometheus `HELP` line or an OpenTelemetry
    +    /// instrument description.
    +    public let metricDescription: String?
    +
    +    public init(
    +        label: String,
    +        dimensions: [(String, String)] = [],
    +        metricDescription: String? = nil
    +    ) {
    +        self.label = label

    No need for the implementation here, just the API. Here and below.

    kukushechkin kukushechkin commented on code on Sep 29, 2026 10:39 UTC
    Code Review
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md:1
    @@ -78,31 +160,26 @@ the diff.
     
     ## Alternatives considered
     
    -- **Put `description` in `dimensions`.** Rejected — this is what backends already do
    -  as a workaround, and it risks increasing cardinality since dimensions are commonly
    -  used for grouping/filtering.
    -- **`MetricDescription` as the type name**, instead of `MetricDescriptor`. Open for
    -  discussion; naming bikeshed, no functional difference.
    +- **Put the description in `dimensions`.** Rejected — this is what backends already
    +  do as a workaround, and it risks increasing cardinality since dimensions are
    +  commonly used for grouping/filtering.
    +- **`description` as the field name**, instead of `metricDescription`. Rejected —
    +  it would collide with `CustomStringConvertible.description` and block
    +  `MetricDescriptor` from conforming to that protocol in the future.
    +- **`MetricDescription` as the type name**, instead of `MetricDescriptor`. Rejected
    +  in favor of `MetricDescriptor`, to match the naming of the property it now holds
    +  (`metricDescription`) and keep `description` free for `CustomStringConvertible`.
     - **Silent vs. surfaced fallback.** When a backend does not override the
    -  descriptor-based factory method, the description is currently dropped silently.
    -  An alternative is to make that drop observable somehow (for example via a debug
    -  log or a `Metrics` bootstrap warning) so authors notice a description isn't being
    -  used. Needs input from backend authors before deciding.
    -- **Where `aggregate` lives for `Recorder`.** The PoC keeps `aggregate` as a separate
    -  parameter alongside `descriptor:` rather than folding it into `MetricDescriptor`
    -  itself, to avoid growing the descriptor with parameters that only apply to one
    -  metric kind.
    -
    -## Open questions for reviewers
    -
    -- `MetricDescriptor` vs `MetricDescription` naming.
    -- Whether `aggregate` should move inside the descriptor for `Recorder`.
    -- Whether a dropped `description` (unsupported backend) should be silent or surfaced.
    +  descriptor-based factory method, `metricDescription` is dropped silently. Decided
    +  to keep this silent for now, consistent with how unused `dimensions` are already
    +  handled by backends that ignore them; can be revisited if backend authors want a
    +  more visible signal.
    +- **Moving `aggregate` inside `MetricDescriptor` for `Recorder`.** Rejected —
    +  `aggregate` only applies to `Recorder`, not to any other metric kind, so folding
    +  it into the shared `MetricDescriptor` struct would mean either a `Recorder`-only
    +  descriptor type or an unused field on every other metric's descriptor. Kept as a
    +  separate parameter on `makeRecorder(descriptor:aggregate:)` instead.
     
     ## Implementation

    No need for this section at all.

    kukushechkin kukushechkin commented on code on Sep 29, 2026 10:39 UTC
    Code Review
    Sources/CoreMetrics/Docs.docc/Proposals/SMT-0003-metric-descriptors.md:1
    @@ -22,51 +22,133 @@ no portable way to express:
     - an OpenTelemetry instrument `description`.
     
     Today this is worked around per-backend: `swift-prometheus` exposes a separate
    -registry API that takes `help:`, and `swift-otel` stuffs the description into a
    -dimension. Neither approach is portable, and stuffing it into a dimension risks
    +registry API that takes `help:`, and `swift-otel` packs the description into a
    +dimension. Neither approach is portable, and packing it into a dimension risks
     increasing cardinality unnecessarily.
     
     ## Proposed solution
     
     Introduce a small, `Sendable` and `Equatable` `MetricDescriptor` struct that carries
    -`label`, `dimensions`, and an optional `description`, with a memberwise initializer
    -left open to evolve (for example, to add a `unit` field later without breaking
    -existing call sites).
    +`label`, `dimensions`, and an optional `metricDescription`, with a memberwise
    +initializer left open to evolve (for example, to add a `unit` field later without
    +breaking existing call sites). The field is named `metricDescription` rather than
    +`description`, so `MetricDescriptor` remains free to conform to
    +`CustomStringConvertible` in the future without a naming clash.
     
     `MetricsFactory` gains descriptor-based factory requirements alongside the existing
    -`label:dimensions:` ones. Each new requirement ships a default implementation that
    -simply forwards `label` and `dimensions` to the existing method, so every backend
    -that implements `MetricsFactory` today keeps compiling and behaving exactly as
    -before. A backend only needs to override the descriptor-based method if it wants to
    -read the `description`.
    +`label:dimensions:` ones. Each new requirement provides a default implementation
    +that simply forwards `label` and `dimensions` to the existing method, so every
    +backend that implements `MetricsFactory` today keeps compiling and behaving exactly
    +as before. A backend only needs to override the descriptor-based method if it wants
    +to read the `metricDescription`.
     
     Convenience initializers on `Counter`, `FloatingPointCounter`, `Meter`, `Gauge`,
     `Recorder`, and `Timer` let call sites construct a metric from a descriptor directly.
     No existing initializer signature changes.
     
    +### Example
    +
    +```swift
    +// Before: no way to attach a description
    +let requests = Counter(label: "http_requests_total", dimensions: [("route", "/users")])
    +
    +// After: attach a description via MetricDescriptor
    +let descriptor = MetricDescriptor(
    +    label: "http_requests_total",
    +    dimensions: [("route", "/users")],
    +    metricDescription: "Total number of HTTP requests received"
    +)
    +let requests = Counter(descriptor: descriptor)
    +
    +// A descriptor-aware backend (e.g. swift-prometheus) can read metricDescription
    +// to emit a Prometheus HELP line; a backend that doesn't override the
    +// descriptor-based factory method simply falls back to label + dimensions,
    +// exactly as it does today.
    +```
    +
     ## Detailed design
     
    -- **`MetricDescriptor`** (in `CoreMetrics`): `Sendable`, `Equatable`, holds `label`,
    -  `dimensions`, and an optional `description`.
    -- **Five new `MetricsFactory` requirements**, each with a default implementation that
    -  forwards to the existing `makeXXX(label:dimensions:)` method:
    -  - `makeCounter(descriptor:)`
    -  - `makeFloatingPointCounter(descriptor:)`
    -  - `makeMeter(descriptor:)`
    -  - `makeRecorder(descriptor:aggregate:)`
    -  - `makeTimer(descriptor:)`
    -- **Descriptor-based convenience initializers** on `Counter`, `FloatingPointCounter`,
    -  `Meter`, `Gauge`, `Recorder`, and `Timer` (including the `preferredDisplayUnit`
    -  variant).
    -- **`MultiplexMetricsHandler`** forwards the descriptor to every sub-factory.
    -- **`MappingMetricsFactory`** transforms `label`/`dimensions` while preserving
    -  `description`.
    -- **`TestMetrics`** stores the full descriptor, with `label`/`dimensions` exposed as
    -  computed properties so existing test code that reads them keeps working, and new
    -  tests can assert on `description`.
    -
    -Full code is intentionally not inlined here — see the linked implementation PR for
    -the diff.
    +Full API diff, with doc comments, as implemented in the linked PoC (#239):
    +
    +```swift
    +/// A portable description of a metric, carrying everything a backend needs to
    +/// register it, including an optional human-readable description.
    +public struct MetricDescriptor: Sendable, Equatable {
    +    /// The label identifying this metric.
    +    public let label: String
    +
    +    /// The dimensions (key-value pairs) attached to this metric.
    +    public let dimensions: [(String, String)]
    +
    +    /// An optional human-readable description of what this metric measures,
    +    /// e.g. surfaced as a Prometheus `HELP` line or an OpenTelemetry
    +    /// instrument description.
    +    public let metricDescription: String?
    +
    +    public init(
    +        label: String,
    +        dimensions: [(String, String)] = [],
    +        metricDescription: String? = nil
    +    ) {
    +        self.label = label
    +        self.dimensions = dimensions
    +        self.metricDescription = metricDescription
    +    }
    +}
    +
    +extension MetricsFactory {
    +    /// Default implementation forwards to `makeCounter(label:dimensions:)`,
    +    /// dropping `metricDescription`. Override to read it.
    +    public func makeCounter(descriptor: MetricDescriptor) -> CounterHandler {
    +        makeCounter(label: descriptor.label, dimensions: descriptor.dimensions)
    +    }
    +
    +    public func makeFloatingPointCounter(descriptor: MetricDescriptor) -> FloatingPointCounterHandler {
    +        makeFloatingPointCounter(label: descriptor.label, dimensions: descriptor.dimensions)
    +    }
    +
    +    public func makeMeter(descriptor: MetricDescriptor) -> MeterHandler {
    +        makeMeter(label: descriptor.label, dimensions: descriptor.dimensions)
    +    }
    +
    +    public func makeRecorder(descriptor: MetricDescriptor, aggregate: Bool) -> RecorderHandler {
    +        makeRecorder(label: descriptor.label, dimensions: descriptor.dimensions, aggregate: aggregate)
    +    }
    +
    +    public func makeTimer(descriptor: MetricDescriptor) -> TimerHandler {
    +        makeTimer(label: descriptor.label, dimensions: descriptor.dimensions)
    +    }
    +}
    +
    +extension Counter {
    +    public convenience init(descriptor: MetricDescriptor) { ... }
    +}
    +extension FloatingPointCounter {
    +    public convenience init(descriptor: MetricDescriptor) { ... }
    +}
    +extension Meter {
    +    public convenience init(descriptor: MetricDescriptor) { ... }
    +}
    +extension Gauge {
    +    public convenience init(descriptor: MetricDescriptor) { ... }
    +}
    +extension Recorder {
    +    public convenience init(descriptor: MetricDescriptor, aggregate: Bool = false) { ... }
    +}
    +extension Timer {
    +    public convenience init(descriptor: MetricDescriptor) { ... }
    +    public convenience init(descriptor: MetricDescriptor, preferredDisplayUnit: TimeUnit) { ... }
    +}
    +```
    +
    +`MultiplexMetricsHandler` forwards the descriptor to every underlying factory.
    +`MappingMetricsFactory` transforms `label`/`dimensions` while preserving
    +`metricDescription`. `TestMetrics` stores the full descriptor, with
    +`label`/`dimensions` exposed as computed properties so existing test code that
    +reads them keeps working, and new tests can assert on `metricDescription`.
    +
    +*(See #239 for the complete, up-to-date diff — the block above mirrors it but may

    Yet another unnecessary reference to the PoC.

    Reviewers
    Assignees
    ManjunathAnawal ManjunathAnawal
    Labels
    risk: low confidence: 89.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 34.2% (LOW) · Higher = larger blast radius
    34.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 89.1% · Lower = rushed or shallow review
    89.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.7% · Safe to merge
    3.7%