Class DatadogLogsConfig

java.lang.Object
codes.grow.packages.datadoglogs.DatadogLogsConfig

public final class DatadogLogsConfig extends Object
Immutable configuration of a DatadogLogsClient (SPEC section 2.2, API.md section 2).

Build one with builder() or read it from the environment with fromEnv(). Precedence: explicit builder value > GROW_DATADOG_LOGS_<NAME> > vendor variables (DD_API_KEY, DD_APP_KEY/DD_APPLICATION_KEY, DD_SITE, DD_SERVICE, DD_ENV, DD_VERSION, DD_TAGS, DD_HOSTNAME) > default. toString() never prints credentials.

Requests go to two hosts derived from site(): the logs intake and the API. url sets both at once (tests, proxies, fakeintake); intakeUrl and apiUrl override one each.


 DatadogLogsConfig cfg = DatadogLogsConfig.builder()
     .apiKey(System.getenv("DD_API_KEY"))
     .site("datadoghq.eu")
     .service("checkout")
     .build();
 
  • Field Details

    • DEFAULT_SOURCE

      public static final String DEFAULT_SOURCE
      Default ddsource of every log (DECISIONS 9).
      See Also:
  • Method Details

    • builder

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

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

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

      public static List<String> parseTags(String value)
      Parses Datadog tags: key:value items separated by commas and/or whitespace (the DD_TAGS convention). Empty items are dropped and duplicates removed, order kept.
      Parameters:
      value - tag list text, may be null
      Returns:
      the tags
    • validate

      public void validate()
      Checks the rules: known site (unless both base URLs are set), http(s) URLs, required non-blank API key, non-blank application key, positive timeouts, TLS pairs and the proxy URL.
      Throws:
      ConfigException - when a rule is violated
    • toTransportConfig

      public TransportConfig toTransportConfig()
      Translates the common fields into transport settings. The transport base URL is apiUrl(); intake requests use absolute URLs.
      Returns:
      the transport configuration
    • knownSecrets

      public Collection<String> knownSecrets()
      Credential values to redact from error messages and logs.
      Returns:
      the API and application key values that are set
    • apiKey

      public Optional<Secret> apiKey()
      Returns the Datadog API key (header DD-API-KEY).
      Returns:
      the key, or empty (never empty after validate())
    • appKey

      public Optional<Secret> appKey()
      Returns the Datadog application key (header DD-APPLICATION-KEY, query API only).
      Returns:
      the key, or empty
    • site

      public String site()
      Returns the normalized Datadog site.
      Returns:
      the site, default DatadogSites.DEFAULT_SITE
    • url

      public Optional<String> url()
      Returns the explicit base URL for both hosts.
      Returns:
      the URL, or empty
    • intakeUrl

      public String intakeUrl()
      Returns the effective logs intake base URL.
      Returns:
      the URL (intakeUrl, else url, else derived from the site)
    • apiUrl

      public String apiUrl()
      Returns the effective API base URL.
      Returns:
      the URL (apiUrl, else url, else derived from the site)
    • service

      public Optional<String> service()
      Returns the default service of every log.
      Returns:
      the service, or empty
    • env

      public Optional<String> env()
      Returns the environment, sent as tag env:<value>.
      Returns:
      the environment, or empty
    • version

      public Optional<String> version()
      Returns the version, sent as tag version:<value>.
      Returns:
      the version, or empty
    • tags

      public List<String> tags()
      Returns the tags added to every log.
      Returns:
      immutable list of key:value strings
    • hostname

      public Optional<String> hostname()
      Returns the default hostname of every log.
      Returns:
      the hostname, or empty
    • source

      public String source()
      Returns the ddsource of every log.
      Returns:
      the source, default DEFAULT_SOURCE
    • connectTimeout

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

      public Duration requestTimeout()
      Returns the per-attempt timeout.
      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.
      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 extra request headers.
      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
    • toString

      public String toString()
      Overrides:
      toString in class Object