Class SkyWalkingTracing

java.lang.Object
codes.grow.packages.skywalking.SkyWalkingTracing

public final class SkyWalkingTracing extends Object
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 Details

    • AUTHENTICATION_HEADER

      public static final String AUTHENTICATION_HEADER
      gRPC metadata key OAP reads the token from (SW_AUTHENTICATION).
      See Also:
    • DEFAULT_OTLP_ENDPOINT

      public static final String DEFAULT_OTLP_ENDPOINT
      Default OTLP endpoint when neither the tracing nor the SkyWalking config names one.
      See Also:
  • Method Details

    • initTracing

      public static TracingHandle initTracing(TracingConfig config)
      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

      public static TracingHandle initTracing(TracingConfig config, SkyWalkingConfig skywalking)
      Starts tracing that exports to SkyWalking OAP. The SkyWalking settings fill what config leaves open (see withDefaults(codes.grow.packages.skywalking.tracing.TracingConfig, codes.grow.packages.skywalking.SkyWalkingConfig)); the sw8 propagator name is available (extract by default; see Sw8Propagator).
      Parameters:
      config - tracing config
      skywalking - endpoint, protocol, headers, token and TLS source
      Returns:
      the handle (close it to flush)
      Throws:
      ConfigException - for invalid settings
    • configBuilder

      public static TracingConfig.Builder configBuilder(String serviceName, SkyWalkingConfig skywalking)
      A tracing config builder prefilled with the SkyWalking settings (endpoint, protocol, OTLP headers, token, TLS); set further fields on it.
      Parameters:
      serviceName - service.name
      skywalking - SkyWalking settings
      Returns:
      the builder
    • withDefaults

      public static TracingConfig withDefaults(TracingConfig config, SkyWalkingConfig skywalking)
      Fills the open fields of a tracing config from the SkyWalking settings: without an endpoint, the endpoint becomes SkyWalkingConfig.otlpEndpoint(); a protocol equal to the TracingConfig template default (http/protobuf) counts as unset and becomes SkyWalkingConfig.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) with SkyWalkingConfig.Builder.otlpProtocol or OTEL_EXPORTER_OTLP_PROTOCOL. OTLP headers and the authentication token are added unless already present; the SkyWalking TLS options apply when the tracing config has none.
      Parameters:
      config - tracing config
      skywalking - SkyWalking settings
      Returns:
      the merged config
    • exporterFactory

      public static SpanExporterFactory 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 (see exporterFactory()).
      Parameters:
      config - tracing config
      Returns:
      the exporter
      Throws:
      ConfigException - for the native protocol or http/protobuf without an endpoint