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

Code before:
			// 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.delta = d2c
	}

	return wh
}

type rwExporter struct {
	*writeHandler
	config func() config.Config
}

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:                 true,
		AllowUTF8:                         otlpCfg.TranslationStrategy == config.NoUTF8EscapingWithSuffixes,
		ResourceAttributesSetting:         otlptranslator.NewResourceAttributesSetting(otlpCfg),
		KeepIdentifyingResourceAttributes: otlpCfg.KeepIdentifyingResourceAttributes,
		ConvertHistogramsToNHCB:           otlpCfg.ConvertHistogramsToNHCB,
	})
	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)
	}

	err = rw.write(ctx, &prompb.WriteRequest{
		Timeseries: converter.TimeSeries(),
		Metadata:   converter.Metadata(),
	})
	return err
}

func (rw *rwExporter) Capabilities() consumer.Capabilities {
	return consumer.Capabilities{MutatesData: false}
}

type otlpWriteHandler struct {
	logger *slog.Logger


Review comment (suggestion):
```suggestion
		PromoteResourceAttributes:         otlptranslator.NewPromoteResourceAttributes(otlpCfg),
```

Code after:
		}
		d2c, err := fac.CreateMetrics(context.Background(), set, fac.CreateDefaultConfig(), wh.defaultConsumer)
		if err != nil {
			// 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
}

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 != config.NoTranslation,
		AllowUTF8:                         otlpCfg.TranslationStrategy != config.UnderscoreEscapingWithSuffixes,
		PromoteResourceAttributes:         otlptranslator.NewPromoteResourceAttributes(otlpCfg),
		KeepIdentifyingResourceAttributes: otlpCfg.KeepIdentifyingResourceAttributes,
		ConvertHistogramsToNHCB:           otlpCfg.ConvertHistogramsToNHCB,
		AllowDeltaTemporality:             rw.allowDeltaTemporality,
	})
	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)
	}

	err = rw.write(ctx, &prompb.WriteRequest{
		Timeseries: converter.TimeSeries(),