Repository: prometheus/prometheus
File: storage/remote/write_handler.go (Go)

Code before:
			// fac.CreateMetrics directly calls [deltatocumulativeprocessor.createMetricsProcessor],
			// which only errors if:
			//   - cfg.(type) != *Config
			//   - telemetry.New fails due to bad set.TelemetrySettings
			//
			// both cannot be the case, as we pass a valid *Config and valid TelemetrySettings.
			// as such, we assume this error to never occur.
			// if it is, our assumptions are broken in which case a panic seems acceptable.
			panic(fmt.Errorf("failed to create metrics processor: %w", err))
		}
		if err := d2c.Start(context.Background(), nil); err != nil {
			// deltatocumulative does not error on start. see above for panic reasoning
			panic(err)
		}
		wh.d2cConsumer = d2c
	}

	return wh
}

type rwExporter struct {
	*writeHandler
	config                   func() config.Config
	allowDeltaTemporality    bool
	lookbackDelta            time.Duration
	typeAndUnitLabelsEnabled bool
}

func (rw *rwExporter) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error {
	otlpCfg := rw.config().OTLPConfig

	converter := otlptranslator.NewPrometheusConverter()

	annots, err := converter.FromMetrics(ctx, md, otlptranslator.Settings{
		AddMetricSuffixes:                 otlpCfg.TranslationStrategy.ShouldAddSuffixes(),
		AllowUTF8:                         !otlpCfg.TranslationStrategy.ShouldEscape(),
		PromoteResourceAttributes:         otlptranslator.NewPromoteResourceAttributes(otlpCfg),
		KeepIdentifyingResourceAttributes: otlpCfg.KeepIdentifyingResourceAttributes,
		ConvertHistogramsToNHCB:           otlpCfg.ConvertHistogramsToNHCB,
		PromoteScopeMetadata:              otlpCfg.PromoteScopeMetadata,
		AllowDeltaTemporality:             rw.allowDeltaTemporality,
		LookbackDelta:                     rw.lookbackDelta,
		AddTypeAndUnitLabels:              rw.typeAndUnitLabelsEnabled,
	})
	if err != nil {
		rw.logger.Warn("Error translating OTLP metrics to Prometheus write request", "err", err)
	}
	ws, _ := annots.AsStrings("", 0, 0)
	if len(ws) > 0 {
		rw.logger.Warn("Warnings translating OTLP metrics to Prometheus write request", "warnings", ws)
	}

Review comment (suggestion):
[Nit] For consistency:
```suggestion
	enableTypeAndUnitLabels bool
```


Code after:
			// fac.CreateMetrics directly calls [deltatocumulativeprocessor.createMetricsProcessor],
			// which only errors if:
			//   - cfg.(type) != *Config
			//   - telemetry.New fails due to bad set.TelemetrySettings
			//
			// both cannot be the case, as we pass a valid *Config and valid TelemetrySettings.
			// as such, we assume this error to never occur.
			// if it is, our assumptions are broken in which case a panic seems acceptable.
			panic(fmt.Errorf("failed to create metrics processor: %w", err))
		}
		if err := d2c.Start(context.Background(), nil); err != nil {
			// deltatocumulative does not error on start. see above for panic reasoning
			panic(err)
		}
		wh.d2cConsumer = d2c
	}

	return wh
}

type rwExporter struct {
	*writeHandler
	config                  func() config.Config
	allowDeltaTemporality   bool
	lookbackDelta           time.Duration
	enableTypeAndUnitLabels bool
}

func (rw *rwExporter) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error {
	otlpCfg := rw.config().OTLPConfig

	converter := otlptranslator.NewPrometheusConverter()

	annots, err := converter.FromMetrics(ctx, md, otlptranslator.Settings{
		AddMetricSuffixes:                 otlpCfg.TranslationStrategy.ShouldAddSuffixes(),
		AllowUTF8:                         !otlpCfg.TranslationStrategy.ShouldEscape(),
		PromoteResourceAttributes:         otlptranslator.NewPromoteResourceAttributes(otlpCfg),
		KeepIdentifyingResourceAttributes: otlpCfg.KeepIdentifyingResourceAttributes,
		ConvertHistogramsToNHCB:           otlpCfg.ConvertHistogramsToNHCB,
		PromoteScopeMetadata:              otlpCfg.PromoteScopeMetadata,
		AllowDeltaTemporality:             rw.allowDeltaTemporality,
		LookbackDelta:                     rw.lookbackDelta,
		EnableTypeAndUnitLabels:           rw.enableTypeAndUnitLabels,
	})
	if err != nil {
		rw.logger.Warn("Error translating OTLP metrics to Prometheus write request", "err", err)
	}
	ws, _ := annots.AsStrings("", 0, 0)
	if len(ws) > 0 {
		rw.logger.Warn("Warnings translating OTLP metrics to Prometheus write request", "warnings", ws)
	}