Package codes.grow.packages.skywalking
Class SkyWalkingTracing
java.lang.Object
codes.grow.packages.skywalking.SkyWalkingTracing
initTracing for SkyWalking: OpenTelemetry tracing that exports OTLP/gRPC to the OAP
receiver (port 11800). OAP stores OTLP spans in its Zipkin model; read them back with SkyWalkingClient.traces() (zipkin or auto backend; the server needs SW_QUERY_ZIPKIN)
about 5–15 s after export.
try (TracingHandle tracing = SkyWalkingTracing.initTracing(
TracingConfig.builder("checkout").build())) {
Spans.withSpan("charge", () -> pay());
}
Teams that prefer full native SkyWalking traces (segments, sw8 between services, endpoint metrics) use the official SkyWalking Java agent instead: https://skywalking.apache.org/docs/skywalking-java/next/en/setup/service-agent/java-agent/readme/
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic TracingConfig.BuilderconfigBuilder(String serviceName, SkyWalkingConfig skywalking) A tracing config builder prefilled with the SkyWalking settings (endpoint, protocol, OTLP headers, token, TLS); set further fields on it.static io.opentelemetry.sdk.trace.export.SpanExportercreateSpanExporter(TracingConfig config) Creates the span exporter (seeexporterFactory()).static SpanExporterFactoryThe SkyWalking span exporter factory:grpc→ OTLP/gRPC (default endpoint "http://127.0.0.1:11800"; headers become gRPC metadata);http/protobuf→ OTLP/HTTP to<endpoint>/v1/traces(only for an OpenTelemetry Collector in front of OAP — OAP 10.4 serves no OTLP/HTTP; an explicit endpoint is required);native→ConfigException(use the official SkyWalking agents).static TracingHandleinitTracing(TracingConfig config) Starts tracing with the SkyWalking settings from the environment (SkyWalkingConfig.fromEnv()).static TracingHandleinitTracing(TracingConfig config, SkyWalkingConfig skywalking) Starts tracing that exports to SkyWalking OAP.static TracingConfigwithDefaults(TracingConfig config, SkyWalkingConfig skywalking) Fills the open fields of a tracing config from the SkyWalking settings: without an endpoint, the endpoint becomesSkyWalkingConfig.otlpEndpoint(); a protocol equal to theTracingConfigtemplate default (http/protobuf) counts as unset and becomesSkyWalkingConfig.otlpProtocol()(default grpc, the only OTLP transport OAP 10.4 serves) — the same rule as TypeScript, Go and Python.
-
Field Details
-
AUTHENTICATION_HEADER
gRPC metadata key OAP reads the token from (SW_AUTHENTICATION).- See Also:
-
DEFAULT_OTLP_ENDPOINT
Default OTLP endpoint when neither the tracing nor the SkyWalking config names one.- See Also:
-
-
Method Details
-
initTracing
Starts tracing with the SkyWalking settings from the environment (SkyWalkingConfig.fromEnv()).- Parameters:
config- tracing config- Returns:
- the handle (close it to flush)
- Throws:
ConfigException- for invalid settings
-
initTracing
Starts tracing that exports to SkyWalking OAP. The SkyWalking settings fill whatconfigleaves open (seewithDefaults(codes.grow.packages.skywalking.tracing.TracingConfig, codes.grow.packages.skywalking.SkyWalkingConfig)); thesw8propagator name is available (extract by default; seeSw8Propagator).- Parameters:
config- tracing configskywalking- endpoint, protocol, headers, token and TLS source- Returns:
- the handle (close it to flush)
- Throws:
ConfigException- for invalid settings
-
configBuilder
A tracing config builder prefilled with the SkyWalking settings (endpoint, protocol, OTLP headers, token, TLS); set further fields on it.- Parameters:
serviceName-service.nameskywalking- SkyWalking settings- Returns:
- the builder
-
withDefaults
Fills the open fields of a tracing config from the SkyWalking settings: without an endpoint, the endpoint becomesSkyWalkingConfig.otlpEndpoint(); a protocol equal to theTracingConfigtemplate default (http/protobuf) counts as unset and becomesSkyWalkingConfig.otlpProtocol()(default grpc, the only OTLP transport OAP 10.4 serves) — the same rule as TypeScript, Go and Python. Select http/protobuf (an OpenTelemetry Collector in front of OAP) withSkyWalkingConfig.Builder.otlpProtocolorOTEL_EXPORTER_OTLP_PROTOCOL. OTLP headers and theauthenticationtoken are added unless already present; the SkyWalking TLS options apply when the tracing config has none.- Parameters:
config- tracing configskywalking- SkyWalking settings- Returns:
- the merged config
-
exporterFactory
The SkyWalking span exporter factory:grpc→ OTLP/gRPC (default endpoint "http://127.0.0.1:11800"; headers become gRPC metadata);http/protobuf→ OTLP/HTTP to<endpoint>/v1/traces(only for an OpenTelemetry Collector in front of OAP — OAP 10.4 serves no OTLP/HTTP; an explicit endpoint is required);native→ConfigException(use the official SkyWalking agents).- Returns:
- the factory
-
createSpanExporter
public static io.opentelemetry.sdk.trace.export.SpanExporter createSpanExporter(TracingConfig config) Creates the span exporter (seeexporterFactory()).- Parameters:
config- tracing config- Returns:
- the exporter
- Throws:
ConfigException- for the native protocol or http/protobuf without an endpoint
-