Class InstrumentationConfigUtil

java.lang.Object
io.opentelemetry.api.incubator.config.InstrumentationConfigUtil

public class InstrumentationConfigUtil extends Object
A collection of convenience methods to extract instrumentation config from ConfigProvider.getInstrumentationConfig().
  • Method Details

    • peerServiceMapping

      @Nullable public static Map<String,String> peerServiceMapping(ConfigProvider configProvider)
      Return a map representation of the peer service map entries in .instrumentation.general.peer.service_mapping, or null if none is configured.
      Throws:
      DeclarativeConfigException - if an unexpected type is encountered accessing the property
    • httpClientRequestCapturedHeaders

      @Nullable public static List<String> httpClientRequestCapturedHeaders(ConfigProvider configProvider)
      Return .instrumentation.general.http.client.request_captured_headers, or null if none is configured.
      Throws:
      DeclarativeConfigException - if an unexpected type is encountered accessing the property
    • httpClientResponseCapturedHeaders

      @Nullable public static List<String> httpClientResponseCapturedHeaders(ConfigProvider configProvider)
      Return .instrumentation.general.http.client.response_captured_headers, or null if none is configured.
      Throws:
      DeclarativeConfigException - if an unexpected type is encountered accessing the property
    • httpServerRequestCapturedHeaders

      @Nullable public static List<String> httpServerRequestCapturedHeaders(ConfigProvider configProvider)
      Return .instrumentation.general.http.server.request_captured_headers, or null if none is configured.
      Throws:
      DeclarativeConfigException - if an unexpected type is encountered accessing the property
    • httpServerResponseCapturedHeaders

      @Nullable public static List<String> httpServerResponseCapturedHeaders(ConfigProvider configProvider)
      Return .instrumentation.general.http.server.response_captured_headers, or null if none is configured.
      Throws:
      DeclarativeConfigException - if an unexpected type is encountered accessing the property
    • javaInstrumentationConfig

      @Nullable public static DeclarativeConfigProperties javaInstrumentationConfig(ConfigProvider configProvider, String instrumentationName)
      Return .instrumentation.java.<instrumentationName>, or null if none is configured.
      Throws:
      DeclarativeConfigException - if an unexpected type is encountered accessing the property
    • getOrNull

      @Nullable public static <T> T getOrNull(ConfigProvider configProvider, Function<DeclarativeConfigProperties,T> accessor, String... segments)
      Walk down the segments of ConfigProvider.getInstrumentationConfig() and call accessor on the terminal node. Returns null if ConfigProvider.getInstrumentationConfig() is null, or if null is encountered walking the segments, or if accessor returns null.

      See other methods in InstrumentationConfigUtil for usage examples.

    • getInstrumentationConfigModel

      @Nullable public static <T> T getInstrumentationConfigModel(ConfigProvider configProvider, String instrumentationName, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<T> modelType)
      Return .instrumentation.java.<instrumentationName>, after converting it to the modelType using the objectMapper. If no configuration exists for the instrumentationName, returns null.

      This method is a convenience method for a common instrumentation library workflow:

      • During initialization, an instrumentation library is given an ConfigProvider and must initialize according to the relevant config
      • It checks if the user has provided configuration for it, and if so...
      • It converts the configuration to an in-memory model representing all of its relevant properties
      • It initializes using the strongly typed in-memory model

      Conversion is done using ObjectMapper.convertValue(Object, Class) from com.fasterxml.jackson.databind, and assumes the modelType is a POJO written / annotated to support jackson databinding.

      NOTE: callers MUST add their own dependency on com.fasterxml.jackson.core:jackson-databind. This module's dependency is compileOnly since jackson is a large dependency that many users will not require. It's very possible to convert between DeclarativeConfigProperties (or a map representation from DeclarativeConfigProperties.toMap(DeclarativeConfigProperties)) and a target model type without jackson. This method is provided as an optional convenience method.

      Throws:
      IllegalArgumentException - if conversion fails. See ObjectMapper.convertValue(Object, Class) for details.