Package codes.grow.packages.datadoglogs
Class DatadogLogsClient
java.lang.Object
codes.grow.packages.datadoglogs.DatadogLogsClient
- All Implemented Interfaces:
AutoCloseable
Client for Datadog Log Management: API key checks, the logs intake (
logClient(), exporter()) and the query API (query(), needs the application key).
Implements SPEC section 2.4. Thread-safe; create one per Datadog site and close it when done.
Every I/O method has a blocking form and an …Async form returning CompletableFuture.
try (DatadogLogsClient client = DatadogLogsClient.fromEnv()) {
DatadogLogClient logs = client.logClient();
logs.logger("checkout").info("user signed in", Map.of("user", Map.of("id", 42)));
} // close() flushes the log client
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder that configures and creates a client in one chain. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic DatadogLogsClient.Builderbuilder()Starts a client builder.voidclose()Flushes and closes every log client, stops running tails, then releases connections.config()Returns the configuration.static DatadogLogsClientcreate(DatadogLogsConfig config) Creates a client.exporter()Returns the intake exporter (Datadog limits).static DatadogLogsClientfromEnv()Creates a client fromGROW_DATADOG_LOGS_*,DD_API_KEY,DD_SITE, …health()Reachability throughGET /api/v1/validate(Datadog has no health endpoint): 2xx is healthyok(details.apiKeyValid); 401/403 isunauthorized(not healthy); 429degraded; other statusesunhealthy; network errorsunreachable.Asynchronoushealth().booleanisClosed()Returns whetherclose()was called.A batching log client with the default options.logClient(DatadogLogClient.Options options) A batching log client.logClient(BatchOptions batchOptions) A batching log client with the given batch options.ping()Validates the API key withGET /api/v1/validateand returns the latency.Asynchronousping().query()The query client (search, aggregate, indexes, tail).voidregister(AutoCloseable resource) Registers a resource (log client, tail) closed with the client.Datadog is a SaaS without a version endpoint.AsynchronousserverVersion(): always failed withUnsupportedException.toString()Returns the HTTP transport (base URL = the API host).booleanReports whether Datadog accepts the configured API key (GET /api/v1/validate):truefor{"valid": true},falsefor HTTP 403 or{"valid": false}.AsynchronousvalidateApiKey().
-
Field Details
-
VALIDATE_PATH
API key validation path.- See Also:
-
-
Method Details
-
create
Creates a client.- Parameters:
config- validated configuration- Returns:
- a new client
- Throws:
ConfigException- when the configuration, TLS or proxy settings are invalid
-
fromEnv
Creates a client fromGROW_DATADOG_LOGS_*,DD_API_KEY,DD_SITE, …- Returns:
- a new client
-
builder
Starts a client builder.- Returns:
- a new builder
-
config
Returns the configuration.- Returns:
- the configuration
-
transport
Returns the HTTP transport (base URL = the API host).- Returns:
- the transport
-
register
Registers a resource (log client, tail) closed with the client.- Parameters:
resource- the resource- Throws:
CancelledException- afterclose()
-
health
Reachability throughGET /api/v1/validate(Datadog has no health endpoint): 2xx is healthyok(details.apiKeyValid); 401/403 isunauthorized(not healthy); 429degraded; other statusesunhealthy; network errorsunreachable. Never throws except for cancellation and configuration errors.- Returns:
- the health status
-
healthAsync
Asynchronoushealth().- Returns:
- a future with the health status
-
ping
Validates the API key withGET /api/v1/validateand returns the latency.- Returns:
- the latency
- Throws:
AuthenticationException- when Datadog rejects the key (401/403)UnavailableException- when a 2xx answer has no{"valid": true}
-
pingAsync
Asynchronousping().- Returns:
- a future with the latency
-
validateApiKey
public boolean validateApiKey()Reports whether Datadog accepts the configured API key (GET /api/v1/validate):truefor{"valid": true},falsefor HTTP 403 or{"valid": false}. Never needs the application key.- Returns:
- whether the key is valid
- Throws:
UnavailableException- when a 2xx answer has novalidfield
-
validateApiKeyAsync
AsynchronousvalidateApiKey().- Returns:
- a future with the result
-
serverVersion
Datadog is a SaaS without a version endpoint.- Returns:
- never
- Throws:
UnsupportedException- always
-
serverVersionAsync
AsynchronousserverVersion(): always failed withUnsupportedException.- Returns:
- a failed future
-
exporter
Returns the intake exporter (Datadog limits). Most users calllogClient()instead.- Returns:
- the exporter
-
logClient
A batching log client with the default options.- Returns:
- a new log client
-
logClient
A batching log client with the given batch options.- Parameters:
batchOptions- batch options (capped at 1000 records / 5 000 000 bytes per batch)- Returns:
- a new log client
-
logClient
A batching log client. The resource defaults to the configuredservice(service.name),version(service.version),env(deployment.environment) andhostname(host.name);options.resource()wins.close()flushes and closes every log client it created.- Parameters:
options- batching, resource, redaction and intake limits- Returns:
- a new log client
- Throws:
CancelledException- afterclose()
-
query
The query client (search, aggregate, indexes, tail).- Returns:
- the query client
- Throws:
ConfigException- without an application key
-
isClosed
public boolean isClosed()Returns whetherclose()was called.- Returns:
- true once closed
-
close
public void close()Flushes and closes every log client, stops running tails, then releases connections. Idempotent.- Specified by:
closein interfaceAutoCloseable
-
toString
-