Class Otlp

java.lang.Object
codes.grow.packages.otelcollector.Otlp

public final class Otlp extends Object
Shared OTLP plumbing: gRPC method paths, decoding of google.rpc.Status and partial success bodies, mapping of HTTP and gRPC statuses to the SDK exceptions, and exporter settings (retry policy, TLS) for the official OpenTelemetry exporters.
  • Field Details

    • GRPC_TRACES_METHOD

      public static final String GRPC_TRACES_METHOD
      gRPC method of TraceService/Export.
      See Also:
    • GRPC_LOGS_METHOD

      public static final String GRPC_LOGS_METHOD
      gRPC method of LogsService/Export.
      See Also:
    • GRPC_METRICS_METHOD

      public static final String GRPC_METRICS_METHOD
      gRPC method of MetricsService/Export.
      See Also:
  • Method Details

    • decodeRpcStatus

      public static Optional<Otlp.RpcStatus> decodeRpcStatus(byte[] body)
      Decodes a binary google.rpc.Status (field 1 code, field 2 message).
      Parameters:
      body - bytes
      Returns:
      the status, or empty when the bytes are not a well-formed non-empty Status
    • decodePartialSuccess

      public static Otlp.PartialSuccess decodePartialSuccess(byte[] body)
      Decodes the partial_success (field 1) of a protobuf Export*ServiceResponse.
      Parameters:
      body - response bytes
      Returns:
      the partial success, Otlp.PartialSuccess.NONE when absent or malformed
    • errorText

      public static Optional<String> errorText(byte[] body)
      Human text of an OTLP error body: JSON {"code","message"}, a binary google.rpc.Status, or printable text. Whitespace collapsed; not yet redacted.
      Parameters:
      body - response body
      Returns:
      the text, or empty
    • httpError

      public static OtelCollectorException httpError(String operation, int status, byte[] body, Collection<String> secrets)
      Builds the SDK exception for an HTTP status with an OTLP error body: "<op>: <phrase>: <message> (HTTP <status>)", redacted and truncated.
      Parameters:
      operation - operation name
      status - HTTP status
      body - response body (protobuf Status, JSON or text), may be null
      secrets - secret values to remove
      Returns:
      the exception of the matching subclass
    • codeForGrpcStatus

      public static ErrorCode codeForGrpcStatus(int status)
      Maps a gRPC status code to an SDK ErrorCode.
      Parameters:
      status - gRPC status code
      Returns:
      the code
    • grpcStatusName

      public static String grpcStatusName(int status)
      Name of a gRPC status code (UNAUTHENTICATED, …).
      Parameters:
      status - code
      Returns:
      the name, or the number for unknown codes
    • grpcError

      public static OtelCollectorException grpcError(String operation, int status, String message, Collection<String> secrets)
      Builds the SDK exception for a gRPC status: "<op>: <message> (gRPC <NAME>)", redacted and truncated.
      Parameters:
      operation - operation name
      status - gRPC status code
      message - grpc-message, may be null
      secrets - secret values to remove
      Returns:
      the exception of the matching subclass
    • networkError

      public static OtelCollectorException networkError(String operation, Throwable error, Collection<String> secrets)
      Converts a transport failure without a response (connection refused, timeout) into an SDK exception.
      Parameters:
      operation - operation name
      error - the failure
      secrets - secret values to remove
      Returns:
      TimeoutException for timeouts, else UnavailableException
    • exporterRetryPolicy

      public static Optional<io.opentelemetry.sdk.common.export.RetryPolicy> exporterRetryPolicy(RetryPolicy retry)
      Exporter retry policy derived from the SDK retry policy (maxRetries + 1 attempts, clamped to 2..5 as the OpenTelemetry exporters require); empty when retries are off.
      Parameters:
      retry - SDK retry policy
      Returns:
      the exporter policy, or empty
    • applyTls

      public static void applyTls(TlsOptions tls, BiConsumer<SSLContext,X509TrustManager> sslContext, Consumer<byte[]> trusted, BiConsumer<byte[],byte[]> clientTls)
      Applies TlsOptions to an OpenTelemetry exporter builder: trusted CA certificates, client certificate and key, or a trust-all context for insecureSkipVerify (tests only).
      Parameters:
      tls - TLS options
      sslContext - the builder's setSslContext
      trusted - the builder's setTrustedCertificates
      clientTls - the builder's setClientTls(key, cert)
      Throws:
      ConfigException - when a file cannot be read
    • trustManager

      public static X509TrustManager trustManager(TlsOptions tls)
      The trust manager matching TlsOptions: trust-all for insecureSkipVerify, the configured CA bundle, else the system default.
      Parameters:
      tls - TLS options
      Returns:
      the trust manager
      Throws:
      ConfigException - when the CA bundle cannot be read or parsed