Class DeclarativeConfiguration

java.lang.Object
io.opentelemetry.sdk.autoconfigure.declarativeconfig.DeclarativeConfiguration

public final class DeclarativeConfiguration extends Object
Configure OpenTelemetrySdk using declarative configuration. For most users, this means calling parseAndCreate(InputStream) with a YAML configuration file.

For Implementers

External consumers needing to parse OpenTelemetry YAML configuration files should use the same Jackson ObjectMapper configuration for compatibility. This configuration is intentionally not exposed as API to avoid coupling. Instead, copy the following setup:


 ObjectMapper mapper = new ObjectMapper()
     // Create empty object instances for keys which are present but have null values
     .setDefaultSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
 // Boxed primitives which are present but have null values should be set to null,
 // rather than empty instances
 mapper.configOverride(String.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SET));
 mapper.configOverride(Integer.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SET));
 mapper.configOverride(Double.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SET));
 mapper.configOverride(Boolean.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SET));
 

Why this configuration:

  • Default behavior creates empty objects for null values to match YAML schema expectations
  • Boxed primitives remain null to distinguish between absent and explicitly null values
  • Method Details

    • parseAndCreate

      public static DeclarativeConfigResult parseAndCreate(InputStream inputStream)
      Throws:
      io.opentelemetry.api.incubator.config.DeclarativeConfigException - if unable to parse or interpret
    • create

      public static DeclarativeConfigResult create(OpenTelemetryConfigurationModel configurationModel)
      Interpret the configurationModel to create OpenTelemetrySdk instance corresponding to the configuration.
      Parameters:
      configurationModel - the configuration model
      Returns:
      the DeclarativeConfigResult
      Throws:
      io.opentelemetry.api.incubator.config.DeclarativeConfigException - if unable to interpret
    • create

      public static DeclarativeConfigResult create(OpenTelemetryConfigurationModel configurationModel, io.opentelemetry.common.ComponentLoader componentLoader)
      Interpret the configurationModel to create OpenTelemetrySdk instance corresponding to the configuration.
      Parameters:
      configurationModel - the configuration model
      componentLoader - the component loader used to load ComponentProvider implementations
      Returns:
      the DeclarativeConfigResult
      Throws:
      io.opentelemetry.api.incubator.config.DeclarativeConfigException - if unable to interpret
    • parse

      public static OpenTelemetryConfigurationModel parse(InputStream configuration)
      Parse the configuration YAML and return the OpenTelemetryConfigurationModel.

      During parsing, environment variable and system property substitution is performed as defined in the OpenTelemetry Configuration Data Model specification.

      Throws:
      io.opentelemetry.api.incubator.config.DeclarativeConfigException - if unable to parse
    • toConfigProperties

      public static io.opentelemetry.api.incubator.config.DeclarativeConfigProperties toConfigProperties(Object model)
      Convert the model to a generic DeclarativeConfigProperties.
      Parameters:
      model - the configuration model
      Returns:
      a generic DeclarativeConfigProperties representation of the model
    • toConfigProperties

      public static io.opentelemetry.api.incubator.config.DeclarativeConfigProperties toConfigProperties(InputStream configuration)
      Convert the configuration YAML to a generic DeclarativeConfigProperties.
      Parameters:
      configuration - configuration YAML
      Returns:
      a generic DeclarativeConfigProperties representation of the model
    • createSampler

      public static io.opentelemetry.sdk.trace.samplers.Sampler createSampler(io.opentelemetry.api.incubator.config.DeclarativeConfigProperties genericSamplerModel)
      Create a SamplerModel from the samplerModel representing the sampler config.

      This is used when samplers are composed, with one sampler accepting one or more additional samplers as config properties. The ComponentProvider implementation can call this to configure a delegate SamplerModel from the DeclarativeConfigProperties corresponding to a particular config property.