Package codes.grow.packages.skywalking
Class SkyWalkingClient
java.lang.Object
codes.grow.packages.skywalking.SkyWalkingClient
- All Implemented Interfaces:
AutoCloseable
Client for Apache SkyWalking OAP.
Implements SPEC section 2.4 plus the SkyWalking modules: query() (GraphQL query API),
traces() (SPEC TraceQueryClient), logs() (SPEC LogQueryClient),
logClient(codes.grow.packages.skywalking.core.HttpTransport, codes.grow.packages.skywalking.SkyWalkingLogClientOptions, boolean) (native log sender) and initTracing(codes.grow.packages.skywalking.tracing.TracingConfig) (OTLP/gRPC tracing). Thread-safe;
create one per OAP and close it when done.
try (SkyWalkingClient client = SkyWalkingClient.fromEnv()) {
System.out.println(client.serverVersion());
client.query().listServices().forEach(s -> System.out.println(s.name()));
}
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 TypeMethodDescriptionstatic SkyWalkingClient.Builderbuilder()Starts a client builder.voidclose()Flushes and closes log clients and tracing handles created here, then releases the connections.config()Returns the configuration.static SkyWalkingClientcreate(SkyWalkingConfig config) Creates a client.static BatchingLogClientcreateLogClient(SkyWalkingConfig config, SkyWalkingLogClientOptions options) A standaloneBatchingLogClientthat sends native logs toPOST /v3/logs(owns its connections;close()flushes and releases them).static SkyWalkingClientfromEnv()Creates a client from the SDK and vendor environment variables.Raw GraphQL without variables.Raw GraphQL (same asquery().graphql).graphqlAsync(String query, Map<String, ?> variables) Asynchronousgraphql(String, Map).health()Liveness:GET /healthcheck(OAP health checker,SW_HEALTH_CHECKER=default): 2xx → ok, other statuses → unhealthy.Asynchronoushealth().initTracing(TracingConfig tracing) SkyWalkingTracing.initTracing(TracingConfig, SkyWalkingConfig)with this client's configuration (OTLP endpoint, protocol, headers, token, TLS).booleanisClosed()Returns whetherclose()was called.logClient(SkyWalkingLogClientOptions options) ABatchingLogClientthat sends native logs (POST /v3/logs) over this client's connections.A log client for one service with default batching.logs()SPECLogQueryClient.ping()Timed GraphQL round trip (getTimeInfo; also caches the OAP time zone).Asynchronousping().query()The GraphQL query API: services, endpoints, instances, native traces, logs, topology.voidregister(AutoCloseable resource) Registers a resource closed with the client.The OAP version from GraphQL{version}, for example10.4.0-b272da3.AsynchronousserverVersion().toString()traces()SPECTraceQueryClient(Zipkin store for OTLP spans, native store for agents) with the configuredSkyWalkingConfig.traceBackend().Returns the HTTP transport, for service modules built on this client.
-
Method Details
-
create
Creates a client.- Parameters:
config- validated configuration- Returns:
- a new client
- Throws:
ConfigException- when TLS or proxy settings are invalid
-
fromEnv
Creates a client from the SDK and vendor environment variables.- Returns:
- a new client
-
builder
Starts a client builder.- Returns:
- a new builder
-
createLogClient
public static BatchingLogClient createLogClient(SkyWalkingConfig config, SkyWalkingLogClientOptions options) A standaloneBatchingLogClientthat sends native logs toPOST /v3/logs(owns its connections;close()flushes and releases them).- Parameters:
config- configurationoptions- service name, instance, resource and batch settings- Returns:
- the log client
-
config
Returns the configuration.- Returns:
- the configuration
-
transport
Returns the HTTP transport, for service modules built on this client.- Returns:
- the transport
-
query
The GraphQL query API: services, endpoints, instances, native traces, logs, topology.- Returns:
- the query client
-
traces
SPECTraceQueryClient(Zipkin store for OTLP spans, native store for agents) with the configuredSkyWalkingConfig.traceBackend().- Returns:
- the trace query client
-
logs
SPECLogQueryClient.- Returns:
- the log query client
-
register
Registers a resource closed with the client.- Parameters:
resource- the resource
-
health
Liveness:GET /healthcheck(OAP health checker,SW_HEALTH_CHECKER=default): 2xx → ok, other statuses → unhealthy. Without the health checker (404/405) falls back to GraphQLcheckHealth(score 0 = ok). Never throws for an unhealthy or unreachable service (onlyCancelledExceptionandConfigException).- Returns:
- the health status
-
healthAsync
Asynchronoushealth().- Returns:
- a future with the health status
-
ping
Timed GraphQL round trip (getTimeInfo; also caches the OAP time zone). OAP has no query authentication: an authentication error only comes from a gateway in front of it.- Returns:
- the latency
-
pingAsync
Asynchronousping().- Returns:
- a future with the latency
-
serverVersion
The OAP version from GraphQL{version}, for example10.4.0-b272da3.- Returns:
- the version string
- Throws:
UnsupportedException- when the server reports none
-
serverVersionAsync
AsynchronousserverVersion().- Returns:
- a future with the version
-
graphql
Raw GraphQL (same asquery().graphql).- Parameters:
query- GraphQL documentvariables- variables (may be null)- Returns:
- the response
-
graphql
Raw GraphQL without variables.- Parameters:
query- GraphQL document- Returns:
- the response
-
graphqlAsync
Asynchronousgraphql(String, Map).- Parameters:
query- GraphQL documentvariables- variables (may be null)- Returns:
- a future with the response
-
logClient
ABatchingLogClientthat sends native logs (POST /v3/logs) over this client's connections.close()flushes and closes it.- Parameters:
options- service name, instance, resource and batch settings- Returns:
- the log client
-
logClient
A log client for one service with default batching.- Parameters:
serviceName-service.nameof the records- Returns:
- the log client
-
initTracing
SkyWalkingTracing.initTracing(TracingConfig, SkyWalkingConfig)with this client's configuration (OTLP endpoint, protocol, headers, token, TLS).close()shuts the handle down.- Parameters:
tracing- tracing config- Returns:
- the handle
-
isClosed
public boolean isClosed()Returns whetherclose()was called.- Returns:
- true once closed
-
close
public void close()Flushes and closes log clients and tracing handles created here, then releases the connections. Idempotent.- Specified by:
closein interfaceAutoCloseable
-
toString
-