Class OtelCollectorConfig.Builder

java.lang.Object
codes.grow.packages.otelcollector.OtelCollectorConfig.Builder
Enclosing class:
OtelCollectorConfig

public static final class OtelCollectorConfig.Builder extends Object
Builder of the configuration.

Unset fields take the environment (when fromEnv(EnvReader) is called) or the default.

  • Method Details

    • fromEnv

      public OtelCollectorConfig.Builder fromEnv(EnvReader env)
      Fills every field that was not set explicitly from the environment: GROW_OPENTELEMETRY_COLLECTOR_*, then GROW_OTEL_*, then the standard OTEL_* variables.
      Parameters:
      env - environment reader
      Returns:
      this builder
      Throws:
      ConfigException - when a variable holds an invalid value
    • url

      Sets the OTLP/HTTP base URL (default http://127.0.0.1:4318); signal paths are appended.
      Parameters:
      url - http or https URL
      Returns:
      this builder
    • grpcUrl

      public OtelCollectorConfig.Builder grpcUrl(String grpcUrl)
      Sets the OTLP/gRPC target (default: host of url(String), port 4317); https:// enables TLS.
      Parameters:
      grpcUrl - URL
      Returns:
      this builder
    • protocol

      Sets the export protocol (NATIVE is rejected by build()).
      Parameters:
      protocol - protocol
      Returns:
      this builder
    • protocol

      public OtelCollectorConfig.Builder protocol(String protocol)
      Sets the export protocol by name: grpc, http/protobuf or native.
      Parameters:
      protocol - name
      Returns:
      this builder
      Throws:
      ConfigException - for an unknown name or native
    • signalUrl

      public OtelCollectorConfig.Builder signalUrl(Signal signal, String url)
      Sets the full OTLP endpoint of one signal, used as is (no path appended).
      Parameters:
      signal - signal
      url - URL
      Returns:
      this builder
    • header

      public OtelCollectorConfig.Builder header(String name, String value)
      Adds a header sent with every export and with ping (for example Authorization).
      Parameters:
      name - header name
      value - header value
      Returns:
      this builder
    • headers

      public OtelCollectorConfig.Builder headers(Map<String,String> headers)
      Adds headers sent with every export.
      Parameters:
      headers - headers
      Returns:
      this builder
    • signalHeader

      public OtelCollectorConfig.Builder signalHeader(Signal signal, String name, String value)
      Adds a header sent only with exports of one signal (merged over header(java.lang.String, java.lang.String)).
      Parameters:
      signal - signal
      name - header name
      value - header value
      Returns:
      this builder
    • compression

      public OtelCollectorConfig.Builder compression(TracingConfig.Compression compression)
      Sets the export compression (default gzip).
      Parameters:
      compression - compression
      Returns:
      this builder
    • exportTimeout

      public OtelCollectorConfig.Builder exportTimeout(Duration timeout)
      Sets the deadline of one OTLP export including the exporter's retries (default 10 s).
      Parameters:
      timeout - positive duration
      Returns:
      this builder
    • healthUrl

      public OtelCollectorConfig.Builder healthUrl(String healthUrl)
      Sets the health_check URL.
      Parameters:
      healthUrl - URL
      Returns:
      this builder
    • zpagesUrl

      public OtelCollectorConfig.Builder zpagesUrl(String zpagesUrl)
      Sets the zpages base URL.
      Parameters:
      zpagesUrl - URL
      Returns:
      this builder
    • telemetryUrl

      public OtelCollectorConfig.Builder telemetryUrl(String telemetryUrl)
      Sets the internal telemetry (Prometheus) URL used by serverVersion as fallback.
      Parameters:
      telemetryUrl - URL such as http://collector:8888/metrics
      Returns:
      this builder
    • serviceName

      public OtelCollectorConfig.Builder serviceName(String serviceName)
      Sets service.name.
      Parameters:
      serviceName - name
      Returns:
      this builder
    • serviceVersion

      public OtelCollectorConfig.Builder serviceVersion(String serviceVersion)
      Sets service.version.
      Parameters:
      serviceVersion - version
      Returns:
      this builder
    • environment

      public OtelCollectorConfig.Builder environment(String environment)
      Sets deployment.environment.name.
      Parameters:
      environment - environment
      Returns:
      this builder
    • resourceAttributes

      public OtelCollectorConfig.Builder resourceAttributes(Map<String,?> attributes)
      Adds resource attributes (explicit keys win over environment keys).
      Parameters:
      attributes - attributes
      Returns:
      this builder
    • resourceAttribute

      public OtelCollectorConfig.Builder resourceAttribute(String key, Object value)
      Adds one resource attribute.
      Parameters:
      key - key
      value - value
      Returns:
      this builder
    • traces

      public OtelCollectorConfig.Builder traces(boolean enabled)
      Turns trace export on or off (default on).
      Parameters:
      enabled - on
      Returns:
      this builder
    • logs

      public OtelCollectorConfig.Builder logs(boolean enabled)
      Turns log export on or off (default on).
      Parameters:
      enabled - on
      Returns:
      this builder
    • metrics

      public OtelCollectorConfig.Builder metrics(boolean enabled)
      Turns metric export on or off (default on).
      Parameters:
      enabled - on
      Returns:
      this builder
    • sampler

      Sets the trace sampler (default parentbased_always_on).
      Parameters:
      sampler - sampler
      Returns:
      this builder
    • samplerRatio

      public OtelCollectorConfig.Builder samplerRatio(double ratio)
      Sets the ratio of the *traceidratio samplers (default 1).
      Parameters:
      ratio - ratio between 0 and 1
      Returns:
      this builder
    • propagators

      public OtelCollectorConfig.Builder propagators(List<String> propagators)
      Sets the propagators (default tracecontext, baggage).
      Parameters:
      propagators - names
      Returns:
      this builder
    • propagators

      public OtelCollectorConfig.Builder propagators(String... propagators)
      Sets the propagators.
      Parameters:
      propagators - names
      Returns:
      this builder
    • tracesBatch

      Sets the batch span processor settings (OTEL_BSP_* are then ignored).
      Parameters:
      batch - settings
      Returns:
      this builder
    • logsBatch

      public OtelCollectorConfig.Builder logsBatch(BatchOptions batch)
      Sets the log batch settings (OTEL_BLRP_* are then ignored).
      Parameters:
      batch - options
      Returns:
      this builder
    • metricExportInterval

      public OtelCollectorConfig.Builder metricExportInterval(Duration interval)
      Sets the periodic metric reader interval (default 60 s).
      Parameters:
      interval - positive duration
      Returns:
      this builder
    • runtimeMetrics

      public OtelCollectorConfig.Builder runtimeMetrics(boolean enabled)
      Turns JVM runtime metrics on or off (default off).
      Parameters:
      enabled - on
      Returns:
      this builder
    • resourceDetectors

      public OtelCollectorConfig.Builder resourceDetectors(List<String> detectors)
      Sets the resource detectors (host, process, container, k8s); an empty list disables detection.
      Parameters:
      detectors - names
      Returns:
      this builder
    • connectTimeout

      public OtelCollectorConfig.Builder connectTimeout(Duration d)
      Sets the connect timeout (default 10 s).
      Parameters:
      d - positive duration
      Returns:
      this builder
    • requestTimeout

      public OtelCollectorConfig.Builder requestTimeout(Duration d)
      Sets the per-attempt timeout of health, ping and version calls (default 30 s).
      Parameters:
      d - positive duration
      Returns:
      this builder
    • totalTimeout

      public OtelCollectorConfig.Builder totalTimeout(Duration d)
      Sets the total timeout per call including retries (default 120 s).
      Parameters:
      d - positive duration
      Returns:
      this builder
    • retry

      Sets the retry policy (default RetryPolicy.defaults()).
      Parameters:
      retry - policy
      Returns:
      this builder
    • tls

      Sets the TLS options; environment TLS variables are then ignored.
      Parameters:
      tls - options
      Returns:
      this builder
    • proxy

      public OtelCollectorConfig.Builder proxy(String proxy)
      Sets an explicit proxy URL for health, ping and version calls.
      Parameters:
      proxy - proxy URL
      Returns:
      this builder
    • userAgentSuffix

      public OtelCollectorConfig.Builder userAgentSuffix(String suffix)
      Sets the text appended to the User-Agent.
      Parameters:
      suffix - suffix
      Returns:
      this builder
    • hooks

      public OtelCollectorConfig.Builder hooks(Hooks hooks)
      Sets request hooks.
      Parameters:
      hooks - hooks
      Returns:
      this builder
    • logger

      public OtelCollectorConfig.Builder logger(Logger logger)
      Sets the logger (default silent).
      Parameters:
      logger - logger
      Returns:
      this builder
    • build

      public OtelCollectorConfig build()
      Builds and validates the configuration.
      Returns:
      the configuration
      Throws:
      ConfigException - when a rule is violated