Repository: open-telemetry/opentelemetry-java
File: sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactory.java (Java)

Code before:
 */

package io.opentelemetry.sdk.extension.incubator.fileconfig;

import io.opentelemetry.api.incubator.config.DeclarativeConfigException;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.OpenTelemetrySdkBuilder;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel;
import io.opentelemetry.sdk.internal.ExtendedOpenTelemetrySdk;
import io.opentelemetry.sdk.internal.OpenTelemetrySdkBuilderUtil;
import io.opentelemetry.sdk.internal.SdkConfigProvider;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Objects;
import java.util.logging.Logger;
import java.util.regex.Pattern;

final class OpenTelemetryConfigurationFactory
    implements Factory<OpenTelemetryConfigurationModel, ExtendedOpenTelemetrySdk> {

  private static final Logger logger =
      Logger.getLogger(OpenTelemetryConfigurationFactory.class.getName());
  private static final Pattern SUPPORTED_FILE_FORMATS =
      Pattern.compile("^(0.4)|(1.0(-rc.\\d*)?)|(1.0.0-rc.\\d*)$");
  private static final String EXPECTED_FILE_FORMAT = "1.0.0-rc.3";

  private static final OpenTelemetryConfigurationFactory INSTANCE =
      new OpenTelemetryConfigurationFactory();

  private OpenTelemetryConfigurationFactory() {}

  static OpenTelemetryConfigurationFactory getInstance() {
    return INSTANCE;
  }

  @Override
  public ExtendedOpenTelemetrySdk create(
      OpenTelemetryConfigurationModel model, DeclarativeConfigContext context) {
    DeclarativeConfigProperties modelProperties =
        DeclarativeConfiguration.toConfigProperties(
            model, context.getSpiHelper().getComponentLoader());
    SdkConfigProvider sdkConfigProvider = SdkConfigProvider.create(modelProperties);
    OpenTelemetrySdkBuilder builder =
        OpenTelemetrySdkBuilderUtil.setConfigProvider(
            OpenTelemetrySdk.builder(), sdkConfigProvider);
    String fileFormat = model.getFileFormat();
    if (fileFormat == null || !SUPPORTED_FILE_FORMATS.matcher(fileFormat).matches()) {
      throw new DeclarativeConfigException(
          "Unsupported file format '" + fileFormat + "'. Supported formats include 0.4, 1.0*");
    }

Review comment (bug):
The file format is supposed to omit the patch version. See docs here: https://github.com/open-telemetry/opentelemetry-configuration/blob/main/schema-docs.md#opentelemetryconfiguration-

The idea is that since patches will only be for bug fixes, there should never be something actionable on the part of an implementation, and so forcing or even allowing the user to specify the patch version adds possible confusion by implying that it matters.

Code after:
 */

package io.opentelemetry.sdk.extension.incubator.fileconfig;

import io.opentelemetry.api.incubator.config.DeclarativeConfigException;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.OpenTelemetrySdkBuilder;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel;
import io.opentelemetry.sdk.internal.ExtendedOpenTelemetrySdk;
import io.opentelemetry.sdk.internal.OpenTelemetrySdkBuilderUtil;
import io.opentelemetry.sdk.internal.SdkConfigProvider;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Objects;
import java.util.logging.Logger;
import java.util.regex.Pattern;

final class OpenTelemetryConfigurationFactory
    implements Factory<OpenTelemetryConfigurationModel, ExtendedOpenTelemetrySdk> {

  private static final Logger logger =
      Logger.getLogger(OpenTelemetryConfigurationFactory.class.getName());
  private static final Pattern SUPPORTED_FILE_FORMATS = Pattern.compile("^(0.4)|(1.0(-rc.\\d*)?)$");
  private static final String EXPECTED_FILE_FORMAT = "1.0-rc.3";

  private static final OpenTelemetryConfigurationFactory INSTANCE =
      new OpenTelemetryConfigurationFactory();

  private OpenTelemetryConfigurationFactory() {}

  static OpenTelemetryConfigurationFactory getInstance() {
    return INSTANCE;
  }

  @Override
  public ExtendedOpenTelemetrySdk create(
      OpenTelemetryConfigurationModel model, DeclarativeConfigContext context) {
    DeclarativeConfigProperties modelProperties =
        DeclarativeConfiguration.toConfigProperties(
            model, context.getSpiHelper().getComponentLoader());
    SdkConfigProvider sdkConfigProvider = SdkConfigProvider.create(modelProperties);
    OpenTelemetrySdkBuilder builder =
        OpenTelemetrySdkBuilderUtil.setConfigProvider(
            OpenTelemetrySdk.builder(), sdkConfigProvider);
    String fileFormat = model.getFileFormat();
    if (fileFormat == null || !SUPPORTED_FILE_FORMATS.matcher(fileFormat).matches()) {
      throw new DeclarativeConfigException(
          "Unsupported file format '" + fileFormat + "'. Supported formats include 0.4, 1.0*");
    }
    if (!EXPECTED_FILE_FORMAT.equals(fileFormat)) {