Class OtelCollectorClient
java.lang.Object
codes.grow.packages.otelcollector.OtelCollectorClient
- All Implemented Interfaces:
AutoCloseable
Client for an OpenTelemetry Collector: health (
health_check with zpages fallback), an
authenticated OTLP ping, the collector version, and factories for the telemetry
bootstrap, tracing, log clients and exporters whose lifetime the client owns (close()
flushes and shuts them down).
try (OtelCollectorClient client = OtelCollectorClient.fromEnv()) {
HealthStatus health = client.health();
TelemetryHandle telemetry = client.initTelemetry();
}
Every I/O method has a blocking form and an …Async form returning CompletableFuture. Thread-safe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder that configures and creates a client in one chain. -
Method Summary
Modifier and TypeMethodDescriptionstatic OtelCollectorClient.Builderbuilder()Starts a client builder.voidclose()Flushes and shuts down every handle, log client and exporter this client created (newest first), then releases connections.Returns the health client (closed with this client).config()Returns the configuration.static OtelCollectorClientcreate(OtelCollectorConfig config) Creates a client.static OtelCollectorClientfromEnv()Creates a client fromGROW_OPENTELEMETRY_COLLECTOR_*,GROW_OTEL_*and the standardOTEL_*variables.health()Unauthenticated health:GET {healthUrl}(port 13133), falling back to zpages when the health endpoint is unreachable.Asynchronoushealth().OtelCollectorTelemetry.initTelemetry(OtelCollectorConfig)with this client's config;close()shuts the handle down.initTelemetry(TelemetryOptions options) OtelCollectorTelemetry.initTelemetry(OtelCollectorConfig, TelemetryOptions)with this client's config;close()shuts the handle down.Tracing with every setting from this client's config;close()shuts it down.initTracing(TracingConfig tracing) Tracing with an explicit config over this client's config (seeOtelCollectorTracing.resolve(codes.grow.packages.otelcollector.tracing.TracingConfig, codes.grow.packages.otelcollector.OtelCollectorConfig));close()shuts it down.booleanisClosed()Returns whetherclose()was called.An OTLP log client with the configured batch options;close()flushes and closes it.logClient(BatchOptions batch) An OTLP log client with explicit batch options;close()flushes and closes it.A bare OTLP log exporter for this config;close()shuts it down.logQuery()Log query client: the collector has none, every method throwsUnsupportedException.ping()Authenticated round trip: an empty OTLP trace export (creates no telemetry) with the configured headers:POST {tracesUrl}with an empty protobuf body (HTTP) orTraceService/Exportwith a 0-byte message (gRPC).Asynchronousping().voidregister(AutoCloseable resource) Registers a resource closed with the client.Collector version from zpages/debug/servicez(works on stock stacks), elsetarget_infoattelemetryUrl.AsynchronousserverVersion().toString()Trace query client: the collector has none, every method throwsUnsupportedException.Returns the HTTP transport (OTLP base URL, export headers), for service modules.waitUntilReady(Duration timeout) Pollshealth()until healthy.waitUntilReadyAsync(Duration timeout) AsynchronouswaitUntilReady(Duration).
-
Method Details
-
create
Creates a client.- Parameters:
config- validated configuration- Returns:
- a new client
- Throws:
ConfigException- when the configuration is invalid
-
fromEnv
Creates a client fromGROW_OPENTELEMETRY_COLLECTOR_*,GROW_OTEL_*and the standardOTEL_*variables.- 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 (OTLP base URL, export headers), for service modules.- Returns:
- the transport
-
register
Registers a resource closed with the client.- Parameters:
resource- the resource- Throws:
CancelledException- when the client is closed (the resource is closed first)
-
collectorHealth
Returns the health client (closed with this client).- Returns:
- the health client
-
health
Unauthenticated health:GET {healthUrl}(port 13133), falling back to zpages when the health endpoint is unreachable. Never throws for an unhealthy or unreachable collector.- Returns:
- the status
- Throws:
CancelledException- when interrupted or closed
-
healthAsync
Asynchronoushealth().- Returns:
- a future with the status
-
waitUntilReady
Pollshealth()until healthy.- Parameters:
timeout- deadline- Returns:
- the healthy status
- Throws:
TimeoutException- at the deadline
-
waitUntilReadyAsync
AsynchronouswaitUntilReady(Duration).- Parameters:
timeout- deadline- Returns:
- a future with the healthy status
-
ping
Authenticated round trip: an empty OTLP trace export (creates no telemetry) with the configured headers:POST {tracesUrl}with an empty protobuf body (HTTP) orTraceService/Exportwith a 0-byte message (gRPC).- Returns:
- the latency
- Throws:
AuthenticationException- on 401 / gRPC UNAUTHENTICATEDPermissionDeniedException- on 403 / gRPC PERMISSION_DENIEDNotFoundException- for a wrong path / gRPC UNIMPLEMENTED
-
pingAsync
Asynchronousping().- Returns:
- a future with the latency
-
serverVersion
Collector version from zpages/debug/servicez(works on stock stacks), elsetarget_infoattelemetryUrl.- Returns:
- the version, such as
0.165.0 - Throws:
UnsupportedException- when neither source is reachable
-
serverVersionAsync
AsynchronousserverVersion().- Returns:
- a future with the version
-
initTelemetry
OtelCollectorTelemetry.initTelemetry(OtelCollectorConfig)with this client's config;close()shuts the handle down.- Returns:
- the handle
-
initTelemetry
OtelCollectorTelemetry.initTelemetry(OtelCollectorConfig, TelemetryOptions)with this client's config;close()shuts the handle down.- Parameters:
options- options- Returns:
- the handle
-
initTracing
Tracing with every setting from this client's config;close()shuts it down.- Returns:
- the handle
-
initTracing
Tracing with an explicit config over this client's config (seeOtelCollectorTracing.resolve(codes.grow.packages.otelcollector.tracing.TracingConfig, codes.grow.packages.otelcollector.OtelCollectorConfig));close()shuts it down.- Parameters:
tracing- explicit tracing config- Returns:
- the handle
-
logClient
An OTLP log client with the configured batch options;close()flushes and closes it.- Returns:
- the log client
-
logClient
An OTLP log client with explicit batch options;close()flushes and closes it.- Parameters:
batch- batch options- Returns:
- the log client
-
logExporter
A bare OTLP log exporter for this config;close()shuts it down.- Returns:
- the exporter
-
traceQuery
Trace query client: the collector has none, every method throwsUnsupportedException.- Returns:
- the client
-
logQuery
Log query client: the collector has none, every method throwsUnsupportedException.- Returns:
- the client
-
isClosed
public boolean isClosed()Returns whetherclose()was called.- Returns:
- true once closed
-
close
public void close()Flushes and shuts down every handle, log client and exporter this client created (newest first), then releases connections. Idempotent.- Specified by:
closein interfaceAutoCloseable
-
toString
-