Package codes.grow.packages.datadoglogs
Class DatadogLogsConfig
java.lang.Object
codes.grow.packages.datadoglogs.DatadogLogsConfig
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();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder of the configuration. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefaultddsourceof every log (DECISIONS 9). -
Method Summary
Modifier and TypeMethodDescriptionapiKey()Returns the Datadog API key (headerDD-API-KEY).apiUrl()Returns the effective API base URL.appKey()Returns the Datadog application key (headerDD-APPLICATION-KEY, query API only).static DatadogLogsConfig.Builderbuilder()Starts an empty builder (every field at its default).Returns the connect timeout.env()Returns the environment, sent as tagenv:<value>.static DatadogLogsConfigfromEnv()Reads the configuration from the process environment.static DatadogLogsConfigReads the configuration from an explicit variable map (tests).headers()Returns the extra request headers.hooks()Returns the hooks.hostname()Returns the defaulthostnameof every log.Returns the effective logs intake base URL.Credential values to redact from error messages and logs.logger()Returns the logger.Parses Datadog tags:key:valueitems separated by commas and/or whitespace (theDD_TAGSconvention).proxy()Returns the explicit proxy URL.Returns the per-attempt timeout.retry()Returns the retry policy.service()Returns the defaultserviceof every log.site()Returns the normalized Datadog site.source()Returns theddsourceof every log.tags()Returns the tags added to every log.tls()Returns the TLS options.toString()Returns the total timeout per call including retries.Translates the common fields into transport settings.url()Returns the explicit base URL for both hosts.Returns the user agent suffix.voidvalidate()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.version()Returns the version, sent as tagversion:<value>.
-
Field Details
-
DEFAULT_SOURCE
Defaultddsourceof every log (DECISIONS 9).- See Also:
-
-
Method Details
-
builder
Starts an empty builder (every field at its default).- Returns:
- a new builder
-
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
Reads the configuration from an explicit variable map (tests).- Parameters:
env- variable map- Returns:
- the validated configuration
-
parseTags
Parses Datadog tags:key:valueitems separated by commas and/or whitespace (theDD_TAGSconvention). 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
Translates the common fields into transport settings. The transport base URL isapiUrl(); intake requests use absolute URLs.- Returns:
- the transport configuration
-
knownSecrets
Credential values to redact from error messages and logs.- Returns:
- the API and application key values that are set
-
apiKey
Returns the Datadog API key (headerDD-API-KEY).- Returns:
- the key, or empty (never empty after
validate())
-
appKey
Returns the Datadog application key (headerDD-APPLICATION-KEY, query API only).- Returns:
- the key, or empty
-
site
Returns the normalized Datadog site.- Returns:
- the site, default
DatadogSites.DEFAULT_SITE
-
url
Returns the explicit base URL for both hosts.- Returns:
- the URL, or empty
-
intakeUrl
Returns the effective logs intake base URL.- Returns:
- the URL (
intakeUrl, elseurl, else derived from the site)
-
apiUrl
Returns the effective API base URL.- Returns:
- the URL (
apiUrl, elseurl, else derived from the site)
-
service
Returns the defaultserviceof every log.- Returns:
- the service, or empty
-
env
Returns the environment, sent as tagenv:<value>.- Returns:
- the environment, or empty
-
version
Returns the version, sent as tagversion:<value>.- Returns:
- the version, or empty
-
tags
Returns the tags added to every log.- Returns:
- immutable list of
key:valuestrings
-
hostname
Returns the defaulthostnameof every log.- Returns:
- the hostname, or empty
-
source
Returns theddsourceof every log.- Returns:
- the source, default
DEFAULT_SOURCE
-
connectTimeout
Returns the connect timeout.- Returns:
- the timeout
-
requestTimeout
Returns the per-attempt timeout.- Returns:
- the timeout
-
totalTimeout
Returns the total timeout per call including retries.- Returns:
- the timeout
-
retry
Returns the retry policy.- Returns:
- the policy
-
tls
Returns the TLS options.- Returns:
- the options
-
proxy
Returns the explicit proxy URL.- Returns:
- the proxy, or empty
-
headers
Returns the extra request headers.- Returns:
- immutable map
-
userAgentSuffix
Returns the user agent suffix.- Returns:
- the suffix, or empty
-
hooks
Returns the hooks.- Returns:
- the hooks
-
logger
Returns the logger.- Returns:
- the logger
-
toString
-