Class SkyWalkingConfig

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

public final class SkyWalkingConfig extends Object
Immutable configuration of a SkyWalkingClient (SPEC section 2.2): the OAP REST/GraphQL endpoint (port 12800), the OTLP endpoint used by SkyWalkingTracing.initTracing(codes.grow.packages.skywalking.tracing.TracingConfig) (gRPC, port 11800), the Zipkin query API where OAP stores OTLP spans (port 9412) and the common transport settings.

Build one with builder() or read it from the environment with fromEnv(). Precedence: explicit builder value > GROW_APACHE_SKYWALKING_<NAME> > vendor variables (GROW_SKYWALKING_<NAME>, then the SkyWalking/OpenTelemetry names) > default. toString() never prints credentials.

OAP has no query authentication: GraphQL and the native /v3 HTTP API are open. When OAP runs behind an authenticating gateway, put its credentials in SkyWalkingConfig.Builder.header(java.lang.String, java.lang.String).

  • Field Details

    • DEFAULT_URL

      public static final String DEFAULT_URL
      Default REST/GraphQL endpoint.
      See Also:
    • DEFAULT_GRAPHQL_PATH

      public static final String DEFAULT_GRAPHQL_PATH
      Default GraphQL path below the URL.
      See Also:
    • OTLP_GRPC_PORT

      public static final int OTLP_GRPC_PORT
      OAP gRPC port (OTLP receiver).
      See Also:
    • ZIPKIN_QUERY_PORT

      public static final int ZIPKIN_QUERY_PORT
      OAP Zipkin query port (SW_QUERY_ZIPKIN).
      See Also:
  • Method Details

    • builder

      public static SkyWalkingConfig.Builder builder()
      Starts an empty builder (every field at its default).
      Returns:
      a new builder
    • fromEnv

      public static SkyWalkingConfig fromEnv()
      Reads the configuration from the process environment.
      Returns:
      the validated configuration
      Throws:
      ConfigException - when a variable holds an invalid value (the message names the variable, never the value)
    • fromEnv

      public static SkyWalkingConfig fromEnv(Map<String,String> env)
      Reads the configuration from an explicit variable map (tests).
      Parameters:
      env - variable map
      Returns:
      the validated configuration
    • baseFromGraphqlUrl

      public static String baseFromGraphqlUrl(String url)
      Strips a trailing /graphql (and slashes) from a GraphQL URL: http://oap:12800/graphql → http://oap:12800.
      Parameters:
      url - URL
      Returns:
      the base URL
    • collectorToUrl

      public static String collectorToUrl(String value)
      Turns a SkyWalking agent collector address (host:port[,host:port]) into an OTLP endpoint URL (http://host:port, first entry).
      Parameters:
      value - collector address
      Returns:
      the endpoint URL
    • zipkinQueryUrl

      public static String zipkinQueryUrl(String value)
      Appends /zipkin to a Zipkin address that does not end with it.
      Parameters:
      value - Zipkin address, e.g. http://oap:9412
      Returns:
      the query API base, e.g. http://oap:9412/zipkin
    • parseOtlpHeaders

      public static Map<String,String> parseOtlpHeaders(String raw, String source)
      Parses OpenTelemetry-style headers k1=v1,k2=v2 (keys lower-cased, values URL-decoded).
      Parameters:
      raw - header list
      source - variable name for the error message (never the value)
      Returns:
      the headers
      Throws:
      ConfigException - when an entry is malformed
    • validate

      public void validate()
      Checks the URLs, protocol, backend, positive timeouts, TLS pairs and the proxy.
      Throws:
      ConfigException - when a rule is violated
    • toTransportConfig

      public TransportConfig toTransportConfig()
      Translates the common fields into transport settings.
      Returns:
      the transport configuration
    • knownSecrets

      public List<String> knownSecrets()
      Credential values to redact from error messages and logs: the authentication token and the values of sensitive OTLP headers.
      Returns:
      the secret values
    • url

      public String url()
      Returns the REST/GraphQL base URL (port 12800, no trailing /graphql).
      Returns:
      the URL
    • graphqlPath

      public String graphqlPath()
      Returns the GraphQL path (default /graphql).
      Returns:
      the path
    • graphqlUrl

      public String graphqlUrl()
      Returns the absolute GraphQL URL.
      Returns:
      url + graphqlPath
    • otlpEndpoint

      public String otlpEndpoint()
      Returns the OTLP endpoint of SkyWalkingTracing.initTracing(codes.grow.packages.skywalking.tracing.TracingConfig) (default http://<url host>:11800).
      Returns:
      the endpoint
    • otlpProtocol

      public OtlpProtocol otlpProtocol()
      Returns the OTLP protocol (default OtlpProtocol.GRPC).
      Returns:
      the protocol
    • otlpHeaders

      public Map<String,String> otlpHeaders()
      Returns the extra OTLP exporter headers (gRPC metadata), keys lower-case.
      Returns:
      immutable map
    • zipkinUrl

      public String zipkinUrl()
      Returns the Zipkin query API base (default http://<url host>:9412/zipkin).
      Returns:
      the URL (ends with /zipkin unless configured otherwise)
    • authentication

      public Optional<Secret> authentication()
      Returns the OAP gRPC token (SW_AUTHENTICATION), sent as the authentication metadata on OTLP exports. OAP does not protect GraphQL or /v3 with it.
      Returns:
      the token, or empty
    • traceBackend

      public TraceBackend traceBackend()
      Returns the trace store read by SkyWalkingClient.traces() (default TraceBackend.AUTO).
      Returns:
      the backend
    • connectTimeout

      public Duration connectTimeout()
      Returns the connect timeout.
      Returns:
      the timeout
    • requestTimeout

      public Duration requestTimeout()
      Returns the per-attempt timeout.
      Returns:
      the timeout
    • totalTimeout

      public Duration totalTimeout()
      Returns the total timeout per call including retries.
      Returns:
      the timeout
    • retry

      public RetryPolicy retry()
      Returns the retry policy.
      Returns:
      the policy
    • tls

      public TlsOptions tls()
      Returns the TLS options.
      Returns:
      the options
    • proxy

      public Optional<String> proxy()
      Returns the explicit proxy URL.
      Returns:
      the proxy, or empty
    • headers

      public Map<String,String> headers()
      Returns the extra request headers.
      Returns:
      immutable map
    • userAgentSuffix

      public Optional<String> userAgentSuffix()
      Returns the user agent suffix.
      Returns:
      the suffix, or empty
    • hooks

      public Hooks hooks()
      Returns the hooks.
      Returns:
      the hooks
    • logger

      public Logger logger()
      Returns the logger.
      Returns:
      the logger
    • toBuilder

      public SkyWalkingConfig.Builder toBuilder()
      Returns a builder holding these values.
      Returns:
      builder copy
    • toString

      public String toString()
      Overrides:
      toString in class Object