Skip to content

feat: add OTel preserve_names for scrape-time suffix handling#1956

Open
zeitlinger wants to merge 5 commits intomainfrom
scrape-time-suffix-otel
Open

feat: add OTel preserve_names for scrape-time suffix handling#1956
zeitlinger wants to merge 5 commits intomainfrom
scrape-time-suffix-otel

Conversation

@zeitlinger
Copy link
Member

@zeitlinger zeitlinger commented Mar 17, 2026

Blocked by #1955 (core + OM1 writers)

Summary

Adds preserve_names configuration to the OpenTelemetry exporter.
When enabled, metric names are passed through exactly as the user
wrote them instead of stripping _total and unit suffixes.
Part of #1942.

Key changes

  • Add preserve_names to ExporterOpenTelemetryProperties
  • MetricDataFactory uses originalName + preserve_names to
    decide naming
  • OtelAutoConfig wires the new property

Key table

User provides OTel OTel preserve_names
Counter("events") events events
Counter("events_total") events events_total
Counter("req").unit(BYTES) name req, unit By name req, unit By
Counter("req_bytes").unit(BYTES) name req, unit By name req_bytes, unit By
Gauge("events_total") events_total events_total

PR stack

  1. Core model + OM1/protobuf writers (feat: move suffix handling to scrape time #1955)
  2. This PR — OTel preserve_names
  3. OM2 writer no-suffix (independent)

Test plan

  • mise run compile passes
  • Tests for preserve_names=true with units, unit already in
    name, and without unit
  • OtelAutoConfigTest covers new property wiring

Part of #1912.

@zeitlinger zeitlinger changed the base branch from scrape-time-suffix-core to main March 17, 2026 10:32
@zeitlinger zeitlinger marked this pull request as ready for review March 17, 2026 10:32
Move metric name suffix handling (_total, _info, unit suffixes) from
creation time to scrape time. Each format writer now owns its suffix
conventions:

- OM1: smart-appends suffixes (skip if already present)
- Registry detects cross-format name collisions at registration time

Key changes:
- Remove all reserved metric name suffixes from PrometheusNaming
- Store original user-provided name separately from exposition base
  name in MetricMetadata (originalName vs expositionBaseName)
- Smart-append logic in OM1/protobuf writers for _total and _info
- Two-layer collision detection in PrometheusRegistry

Closes #1941
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
- Fix race condition: use putIfAbsent for atomic exposition name claiming
  with proper rollback on failure
- Extract claimExpositionNames/releaseExpositionNames for single rollback path
- Rename Info test methods to reflect that _info suffix is now allowed
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Add preserve_names configuration to the OpenTelemetry exporter. When
enabled, metric names are passed through exactly as the user wrote them
instead of stripping _total and unit suffixes.

- Add preserve_names to ExporterOpenTelemetryProperties
- MetricDataFactory uses originalName + preserve_names to decide naming
- OtelAutoConfig wires the new property
- Tests for preserve_names with units, unit-in-name, and without unit

Part of #1942
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
…ests

Avoids brittle reflective access to OpenTelemetryExtension internals.
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
@zeitlinger zeitlinger force-pushed the scrape-time-suffix-otel branch from d89df06 to 5f80626 Compare March 18, 2026 09:01
@zeitlinger zeitlinger requested review from dhoard and fstab as code owners March 18, 2026 09:01
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants