Package codes.grow.packages.datadogapm
Class DatadogApmClient
java.lang.Object
codes.grow.packages.datadogapm.DatadogApmClient
- All Implemented Interfaces:
AutoCloseable
The Datadog APM client (API.md section 1).
health(), ping() and serverVersion() use the local Datadog Agent's GET /info (trace intake port 8126, no
authentication); initTracing(TracingConfig) sets up OpenTelemetry exporting to the
Agent; spans() is the SaaS query API (needs apiKey + appKey).
Thread-safe.
try (DatadogApmClient client = DatadogApmClient.fromEnv()) {
DatadogTracingHandle tracing = client.initTracing(TracingConfig.builder("checkout").build());
String agent = client.serverVersion(); // "7.85.4"
} // close() flushes and shuts down the tracing it started
Every I/O method has a blocking form and an ...Async form returning CompletableFuture.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder that configures and creates a client in one chain. -
Method Summary
Modifier and TypeMethodDescriptionReturns the Agent'sGET /info.AsynchronousagentInfo().static DatadogApmClient.Builderbuilder()Starts a client builder.voidclose()Flushes and shuts down every tracing handle started withinitTracing(codes.grow.packages.datadogapm.tracing.TracingConfig), closes the query API and releases connections.config()Returns the configuration.static DatadogApmClientcreate(DatadogApmConfig config) Creates a client.static DatadogApmClientfromEnv()health()Checks Agent liveness withGET /info(one attempt): healthy with statusokand detailsversion,git_commitwhen the Agent answers;unhealthy(detailshttpStatus,error) on HTTP errors;unreachable(detailserror) on network errors.Asynchronoushealth().initTracing(TracingConfig)with every tracing setting from this client's configuration (DatadogTracing.tracingConfig(DatadogApmConfig)).initTracing(TracingConfig tracing) DatadogTracing.initTracing(TracingConfig, DatadogApmConfig)with this client's configuration as the defaults (Agent host, OTLP endpoint, service version, env, tags, TLS).booleanisClosed()Returns whetherclose()was called.ping()Round trip to the Agent (GET /info) and its latency.Asynchronousping().voidregister(AutoCloseable resource) Registers a resource closed with the client.The Datadog Agent version fromGET /info(e.g.AsynchronousserverVersion().spans()The SaaS spans query API (created on first use, closed byclose()).toString()Returns the HTTP transport to the Agent.
-
Method Details
-
create
Creates a client.- Parameters:
config- validated configuration- Returns:
- a new client
- Throws:
ConfigException- when the configuration is invalid
-
fromEnv
- 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 to the Agent.- Returns:
- the transport
-
register
Registers a resource closed with the client.- Parameters:
resource- the resource
-
spans
The SaaS spans query API (created on first use, closed byclose()).- Returns:
- query client
- Throws:
ConfigException- whenapiKeyorappKeyis missing
-
agentInfo
Returns the Agent'sGET /info.- Returns:
- the document
-
agentInfoAsync
AsynchronousagentInfo().- Returns:
- a future with the document
-
health
Checks Agent liveness withGET /info(one attempt): healthy with statusokand detailsversion,git_commitwhen the Agent answers;unhealthy(detailshttpStatus,error) on HTTP errors;unreachable(detailserror) on network errors. Never throws for an unhealthy or unreachable Agent.- Returns:
- the health status
- Throws:
CancelledException- when interrupted or closed
-
healthAsync
Asynchronoushealth().- Returns:
- a future with the health status
-
ping
Round trip to the Agent (GET /info) and its latency. The Agent has no authentication; to check Datadog API credentials usespans().ping().- Returns:
- the latency
-
pingAsync
Asynchronousping().- Returns:
- a future with the latency
-
serverVersion
The Datadog Agent version fromGET /info(e.g.7.85.4).- Returns:
- the version string
- Throws:
UnsupportedException- when the Agent reports none
-
serverVersionAsync
AsynchronousserverVersion().- Returns:
- a future with the version
-
initTracing
DatadogTracing.initTracing(TracingConfig, DatadogApmConfig)with this client's configuration as the defaults (Agent host, OTLP endpoint, service version, env, tags, TLS).close()shuts the handle down.- Parameters:
tracing- tracing config- Returns:
- handle
-
initTracing
initTracing(TracingConfig)with every tracing setting from this client's configuration (DatadogTracing.tracingConfig(DatadogApmConfig)).- Returns:
- handle
- Throws:
ConfigException- when the configuration has no service name
-
isClosed
public boolean isClosed()Returns whetherclose()was called.- Returns:
- true once closed
-
close
public void close()Flushes and shuts down every tracing handle started withinitTracing(codes.grow.packages.datadogapm.tracing.TracingConfig), closes the query API and releases connections. Idempotent; later calls raiseCancelledException.- Specified by:
closein interfaceAutoCloseable
-
toString
-