Repository: open-telemetry/opentelemetry-java
File: sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/IncubatingUtil.java (Java)

Code before:
          for (Object configProvider : componentLoader.load(providerClass)) {
            Object model = getConfigurationModel.invoke(configProvider);
            if (model != null) {
              return getOpenTelemetrySdk(model, componentLoader);
            }
          }
          return null;
        });
  }

  private static AutoConfiguredOpenTelemetrySdk getOpenTelemetrySdk(
      Object model, ComponentLoader componentLoader)
      throws IllegalAccessException,
          InvocationTargetException,
          ClassNotFoundException,
          NoSuchMethodException {

    Class<?> openTelemetryConfiguration =
        Class.forName(
            "io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel");
    Class<?> declarativeConfiguration =
        Class.forName(
            "io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfiguration");
    Method create =
        declarativeConfiguration.getMethod(
            "createAutoConfiguredSdk", openTelemetryConfiguration, ComponentLoader.class);

    return (AutoConfiguredOpenTelemetrySdk) create.invoke(null, model, componentLoader);
  }

  // Visible for testing
  @Nullable
  static AutoConfiguredOpenTelemetrySdk createWithFactory(String name, Factory factory) {
    try {
      return factory.create();
    } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) {
      throw new ConfigurationException(
          String.format(
              "Error configuring from %s. Is opentelemetry-sdk-extension-incubator on the classpath?",
              name),
          e);
    } catch (InvocationTargetException e) {
      Throwable cause = e.getCause();
      if (cause instanceof DeclarativeConfigException) {
        throw toConfigurationException((DeclarativeConfigException) cause);
      }
      throw new ConfigurationException("Unexpected error configuring from " + name, e);
    }
  }

  private static ConfigurationException toConfigurationException(

Review comment (suggestion):
Let's keep calling this `create`, which comes from the spec: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk.md#create

I think we have a good argument that the `AutoConfiguredOpenTelemetrySdk` is just a composite of all the required SDK components.

Code after:
          Method getConfigurationModel = providerClass.getMethod("getConfigurationModel");

          for (Object configProvider : componentLoader.load(providerClass)) {
            Object model = getConfigurationModel.invoke(configProvider);
            if (model != null) {
              return getOpenTelemetrySdk(model, componentLoader);
            }
          }
          return null;
        });
  }

  private static AutoConfiguredOpenTelemetrySdk getOpenTelemetrySdk(
      Object model, ComponentLoader componentLoader)
      throws IllegalAccessException,
          InvocationTargetException,
          ClassNotFoundException,
          NoSuchMethodException {

    Class<?> openTelemetryConfiguration =
        Class.forName(
            "io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel");
    Class<?> declarativeConfiguration =
        Class.forName(
            "io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfiguration");

    Class<?> contextClass =
        Class.forName(
            "io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfigContext");
    Method createContext = contextClass.getDeclaredMethod("create", ComponentLoader.class);
    createContext.setAccessible(true);
    Object context = createContext.invoke(null, componentLoader);

    Method create =
        declarativeConfiguration.getDeclaredMethod(
            "create", openTelemetryConfiguration, contextClass);
    create.setAccessible(true);
    OpenTelemetrySdk sdk = (OpenTelemetrySdk) create.invoke(null, model, context);

    Class<?> providerClass =
        Class.forName("io.opentelemetry.sdk.extension.incubator.fileconfig.SdkConfigProvider");
    Object provider =
        providerClass
            .getDeclaredMethod("create", openTelemetryConfiguration, ComponentLoader.class)
            .invoke(null, model, componentLoader);

    Method getResource = contextClass.getDeclaredMethod("getResource");
    getResource.setAccessible(true);
    Resource resource = (Resource) getResource.invoke(context);

    return AutoConfiguredOpenTelemetrySdk.create(sdk, resource, null, provider);