Repository: open-telemetry/opentelemetry-java
File: exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/Otel2PrometheusConverter.java (Java)

Code before:
      OtelScopeMode otelScopeMode, @Nullable Predicate<String> allowedResourceAttributesFilter) {
    this.otelScopeMode = otelScopeMode;
    this.allowedResourceAttributesFilter = allowedResourceAttributesFilter;
    this.resourceAttributesToAllowedKeysCache =
        allowedResourceAttributesFilter != null
            ? new ConcurrentHashMap<>()
            : Collections.emptyMap();
  }

  MetricSnapshots convert(@Nullable Collection<MetricData> metricDataCollection) {
    if (metricDataCollection == null || metricDataCollection.isEmpty()) {
      return MetricSnapshots.of();
    }
    Map<String, MetricSnapshot> snapshotsByName = new HashMap<>(metricDataCollection.size());
    Resource resource = null;
    Set<InstrumentationScopeInfo> scopes = new LinkedHashSet<>();
    for (MetricData metricData : metricDataCollection) {
      MetricSnapshot snapshot = convert(metricData);
      if (snapshot == null) {
        continue;
      }
      putOrMerge(snapshotsByName, snapshot);
      if (resource == null) {
        resource = metricData.getResource();
      }
      if (!metricData.getInstrumentationScopeInfo().getAttributes().isEmpty()) {
        scopes.add(metricData.getInstrumentationScopeInfo());
      }
    }
    if (resource != null) {
      putOrMerge(snapshotsByName, makeTargetInfo(resource));
    }
    if (otelScopeMode.isScopeInfoEnabled() && !scopes.isEmpty()) {
      putOrMerge(snapshotsByName, makeScopeInfo(scopes));
    }
    return new MetricSnapshots(snapshotsByName.values());
  }

  @Nullable
  private MetricSnapshot convert(MetricData metricData) {

    // Note that AggregationTemporality.DELTA should never happen
    // because PrometheusMetricReader#getAggregationTemporality returns CUMULATIVE.

    MetricMetadata metadata = convertMetadata(metricData);
    InstrumentationScopeInfo scope = metricData.getInstrumentationScopeInfo();
    switch (metricData.getType()) {
      case LONG_GAUGE:
        return convertLongGauge(
            metadata, scope, metricData.getLongGaugeData().getPoints(), metricData.getResource());
      case DOUBLE_GAUGE:

Review comment (suggestion):
this looks like a pre-existing optimization(?)
```suggestion
      if (otelScopeMode.isScopeInfoEnabled() && !metricData.getInstrumentationScopeInfo().getAttributes().isEmpty()) {
```

Code after:
  }

  MetricSnapshots convert(@Nullable Collection<MetricData> metricDataCollection) {
    if (metricDataCollection == null || metricDataCollection.isEmpty()) {
      return MetricSnapshots.of();
    }
    Map<String, MetricSnapshot> snapshotsByName = new HashMap<>(metricDataCollection.size());
    Resource resource = null;
    for (MetricData metricData : metricDataCollection) {
      MetricSnapshot snapshot = convert(metricData);
      if (snapshot == null) {
        continue;
      }
      putOrMerge(snapshotsByName, snapshot);
      if (resource == null) {
        resource = metricData.getResource();
      }
    }
    if (resource != null) {
      putOrMerge(snapshotsByName, makeTargetInfo(resource));
    }
    return new MetricSnapshots(snapshotsByName.values());
  }

  @Nullable
  private MetricSnapshot convert(MetricData metricData) {

    // Note that AggregationTemporality.DELTA should never happen
    // because PrometheusMetricReader#getAggregationTemporality returns CUMULATIVE.

    MetricMetadata metadata = convertMetadata(metricData);
    InstrumentationScopeInfo scope = metricData.getInstrumentationScopeInfo();
    switch (metricData.getType()) {
      case LONG_GAUGE:
        return convertLongGauge(
            metadata, scope, metricData.getLongGaugeData().getPoints(), metricData.getResource());
      case DOUBLE_GAUGE:
        return convertDoubleGauge(
            metadata, scope, metricData.getDoubleGaugeData().getPoints(), metricData.getResource());
      case LONG_SUM:
        SumData<LongPointData> longSumData = metricData.getLongSumData();
        if (longSumData.getAggregationTemporality() == AggregationTemporality.DELTA) {
          return null;
        } else if (longSumData.isMonotonic()) {
          return convertLongCounter(
              metadata, scope, longSumData.getPoints(), metricData.getResource());
        } else {
          return convertLongGauge(
              metadata, scope, longSumData.getPoints(), metricData.getResource());
        }
      case DOUBLE_SUM: