Class OtelCollectorConfig

java.lang.Object
codes.grow.packages.otelcollector.OtelCollectorConfig

public final class OtelCollectorConfig extends Object
Immutable configuration of a OtelCollectorClient and of every OTLP exporter this package builds (traces, logs, metrics).

Build one with builder() or read it from the environment with fromEnv(). Precedence per field: explicit builder value > GROW_OPENTELEMETRY_COLLECTOR_<NAME> > GROW_OTEL_<NAME> > per-signal OTEL_* > generic OTEL_* > default. Map fields (headers, resource attributes) merge key by key in the same order. toString() never prints credentials.

  • Field Details

    • DEFAULT_URL

      public static final String DEFAULT_URL
      Default OTLP/HTTP base URL (port 4318).
      See Also:
    • DEFAULT_GRPC_URL

      public static final String DEFAULT_GRPC_URL
      Default OTLP/gRPC target (port 4317).
      See Also:
    • DEFAULT_EXPORT_TIMEOUT

      public static final Duration DEFAULT_EXPORT_TIMEOUT
      Default deadline of one OTLP export including the exporter's own retries.
    • DEFAULT_METRIC_EXPORT_INTERVAL

      public static final Duration DEFAULT_METRIC_EXPORT_INTERVAL
      Default interval of the periodic metric reader.
    • ALIAS_ENV_PREFIX

      public static final String ALIAS_ENV_PREFIX
      Alias prefix accepted after EnvReader.DEFAULT_PREFIX (ticket wording).
      See Also:
    • RESOURCE_DETECTORS

      public static final List<String> RESOURCE_DETECTORS
      Every resource detector, in a fixed order (the default).
    • DEFAULT_SERVICE_NAME

      public static final String DEFAULT_SERVICE_NAME
      Default service.name when none is configured (OpenTelemetry Java default).
      See Also:
  • Method Details

    • builder

      public static OtelCollectorConfig.Builder builder()
      Starts an empty builder (every field at its default).
      Returns:
      a new builder
    • fromEnv

      public static OtelCollectorConfig fromEnv()
      Reads the configuration from the process environment.
      Returns:
      the validated configuration
      Throws:
      ConfigException - when a variable holds an invalid value (the message names the variable, never the value)
    • fromEnv

      public static OtelCollectorConfig fromEnv(Map<String,String> env)
      Reads the configuration from an explicit variable map (tests).
      Parameters:
      env - variable map
      Returns:
      the validated configuration
    • toBuilder

      public OtelCollectorConfig.Builder toBuilder()
      Returns a builder with these values (every field counts as explicit).
      Returns:
      builder copy
    • validate

      public void validate()
      Checks URLs, timeouts, protocol, sampler, batch settings, resource detectors and TLS pairs.
      Throws:
      ConfigException - when a rule is violated
    • toTransportConfig

      public TransportConfig toTransportConfig()
      Translates the common fields into settings of the shared HTTP transport (OTLP base URL, export headers, TLS, retries).
      Returns:
      the transport configuration
    • knownSecrets

      public List<String> knownSecrets()
      Values of sensitive export headers (authorization, *token*, *key*, …) that are removed from every message.
      Returns:
      the secret values
    • signalUrl

      public String signalUrl(Signal signal)
      The OTLP/HTTP URL of a signal: the explicit per-signal URL, else url + /v1/<signal>.
      Parameters:
      signal - the signal
      Returns:
      the URL
    • endpointFor

      public String endpointFor(Signal signal)
      The export endpoint of a signal for the configured protocol: the explicit per-signal URL when set, else grpcUrl() for gRPC and signalUrl(Signal) for HTTP.
      Parameters:
      signal - the signal
      Returns:
      the endpoint
    • headersFor

      public Map<String,String> headersFor(Signal signal)
      Export headers of a signal: headers() with the per-signal headers on top.
      Parameters:
      signal - the signal
      Returns:
      a new map
    • serviceResource

      public Map<String,Object> serviceResource()
      Resource attributes of the service: resourceAttributes() plus service.name, service.version and deployment.environment.name.
      Returns:
      a new map
    • toTracingConfig

      public TracingConfig toTracingConfig()
      The tracing settings of the traces signal: service fields, resource, endpoint, protocol, headers, sampler, propagators, batch, TLS and compression.
      Returns:
      a new tracing config
    • url

      public String url()
      Returns the OTLP/HTTP base URL.
      Returns:
      the URL
    • connectTimeout

      public Duration connectTimeout()
      Returns the connect timeout.
      Returns:
      the timeout
    • requestTimeout

      public Duration requestTimeout()
      Returns the per-attempt timeout of health, ping and version calls.
      Returns:
      the timeout
    • totalTimeout

      public Duration totalTimeout()
      Returns the total timeout per call including retries.
      Returns:
      the timeout
    • retry

      public RetryPolicy retry()
      Returns the retry policy (health, ping, version; exporter retries derive from it).
      Returns:
      the policy
    • tls

      public TlsOptions tls()
      Returns the TLS options.
      Returns:
      the options
    • proxy

      public Optional<String> proxy()
      Returns the explicit proxy URL.
      Returns:
      the proxy, or empty
    • headers

      public Map<String,String> headers()
      Returns the export headers sent with every OTLP request (auth goes here).
      Returns:
      immutable map
    • userAgentSuffix

      public Optional<String> userAgentSuffix()
      Returns the user agent suffix.
      Returns:
      the suffix, or empty
    • hooks

      public Hooks hooks()
      Returns the hooks.
      Returns:
      the hooks
    • logger

      public Logger logger()
      Returns the logger.
      Returns:
      the logger
    • grpcUrl

      public String grpcUrl()
      Returns the OTLP/gRPC target.
      Returns:
      the URL
    • protocol

      public TracingConfig.Protocol protocol()
      Returns the export protocol (http/protobuf by default).
      Returns:
      the protocol
    • explicitSignalUrl

      public Optional<String> explicitSignalUrl(Signal signal)
      Returns the explicit per-signal URL (used as is, no path appended).
      Parameters:
      signal - the signal
      Returns:
      the URL, or empty
    • signalHeaders

      public Map<String,String> signalHeaders(Signal signal)
      Returns the headers sent only with exports of one signal.
      Parameters:
      signal - the signal
      Returns:
      immutable map
    • compression

      public TracingConfig.Compression compression()
      Returns the export compression.
      Returns:
      the compression
    • exportTimeout

      public Duration exportTimeout()
      Returns the deadline of one OTLP export.
      Returns:
      the timeout
    • healthUrl

      public String healthUrl()
      Returns the health_check URL (default: host of url(), port 13133).
      Returns:
      the URL
    • zpagesUrl

      public String zpagesUrl()
      Returns the zpages base URL (default: host of url(), port 55679).
      Returns:
      the URL
    • telemetryUrl

      public Optional<String> telemetryUrl()
      Returns the internal telemetry (Prometheus) URL, such as http://collector:8888/metrics.
      Returns:
      the URL, or empty
    • serviceName

      public String serviceName()
      Returns service.name.
      Returns:
      the name
    • serviceVersion

      public Optional<String> serviceVersion()
      Returns service.version.
      Returns:
      the version, or empty
    • environment

      public Optional<String> environment()
      Returns deployment.environment.name.
      Returns:
      the environment, or empty
    • resourceAttributes

      public Map<String,Object> resourceAttributes()
      Returns the resource attributes.
      Returns:
      immutable map
    • tracesEnabled

      public boolean tracesEnabled()
      Returns whether traces are exported.
      Returns:
      true by default
    • logsEnabled

      public boolean logsEnabled()
      Returns whether logs are exported.
      Returns:
      true by default
    • metricsEnabled

      public boolean metricsEnabled()
      Returns whether metrics are exported.
      Returns:
      true by default
    • sampler

      public TracingConfig.SamplerType sampler()
      Returns the trace sampler.
      Returns:
      the sampler
    • samplerRatio

      public double samplerRatio()
      Returns the ratio of the *traceidratio samplers.
      Returns:
      the ratio
    • propagators

      public List<String> propagators()
      Returns the propagator names.
      Returns:
      immutable list
    • tracesBatch

      public TracingConfig.BatchSettings tracesBatch()
      Returns the batch span processor settings.
      Returns:
      the settings
    • logsBatch

      public BatchOptions logsBatch()
      Returns the log batch settings.
      Returns:
      the options
    • metricExportInterval

      public Duration metricExportInterval()
      Returns the periodic metric reader interval.
      Returns:
      the interval
    • runtimeMetrics

      public boolean runtimeMetrics()
      Returns whether JVM runtime metrics are reported.
      Returns:
      false by default
    • resourceDetectors

      public List<String> resourceDetectors()
      Returns the resource detectors run by initTelemetry.
      Returns:
      immutable list
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • parseKeyValueList

      public static Map<String,String> parseKeyValueList(String raw, String variable)
      Parses k=v,k2=v2 (W3C baggage style, keys and values percent-decoded) as used by OTEL_EXPORTER_OTLP_HEADERS and OTEL_RESOURCE_ATTRIBUTES.
      Parameters:
      raw - the value
      variable - variable name for the error message
      Returns:
      ordered map
      Throws:
      ConfigException - naming variable (never the value) on malformed input