Class Otlp
java.lang.Object
codes.grow.packages.otelcollector.Otlp
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA decoded OTLP partial success.static final recordA decodedgoogle.rpc.Status. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyTls(TlsOptions tls, BiConsumer<SSLContext, X509TrustManager> sslContext, Consumer<byte[]> trusted, BiConsumer<byte[], byte[]> clientTls) AppliesTlsOptionsto an OpenTelemetry exporter builder: trusted CA certificates, client certificate and key, or a trust-all context forinsecureSkipVerify(tests only).static ErrorCodecodeForGrpcStatus(int status) Maps a gRPC status code to an SDKErrorCode.static Otlp.PartialSuccessdecodePartialSuccess(byte[] body) Decodes thepartial_success(field 1) of a protobufExport*ServiceResponse.static Optional<Otlp.RpcStatus> decodeRpcStatus(byte[] body) Decodes a binarygoogle.rpc.Status(field 1code, field 2message).errorText(byte[] body) Human text of an OTLP error body: JSON{"code","message"}, a binarygoogle.rpc.Status, or printable text.static Optional<io.opentelemetry.sdk.common.export.RetryPolicy> exporterRetryPolicy(RetryPolicy retry) Exporter retry policy derived from the SDK retry policy (maxRetries + 1attempts, clamped to 2..5 as the OpenTelemetry exporters require); empty when retries are off.static OtelCollectorExceptiongrpcError(String operation, int status, String message, Collection<String> secrets) Builds the SDK exception for a gRPC status:"<op>: <message> (gRPC <NAME>)", redacted and truncated.static StringgrpcStatusName(int status) Name of a gRPC status code (UNAUTHENTICATED, …).static OtelCollectorExceptionhttpError(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.static OtelCollectorExceptionnetworkError(String operation, Throwable error, Collection<String> secrets) Converts a transport failure without a response (connection refused, timeout) into an SDK exception.static X509TrustManagertrustManager(TlsOptions tls) The trust manager matchingTlsOptions: trust-all forinsecureSkipVerify, the configured CA bundle, else the system default.
-
Field Details
-
GRPC_TRACES_METHOD
gRPC method ofTraceService/Export.- See Also:
-
GRPC_LOGS_METHOD
gRPC method ofLogsService/Export.- See Also:
-
GRPC_METRICS_METHOD
gRPC method ofMetricsService/Export.- See Also:
-
-
Method Details
-
decodeRpcStatus
Decodes a binarygoogle.rpc.Status(field 1code, field 2message).- Parameters:
body- bytes- Returns:
- the status, or empty when the bytes are not a well-formed non-empty Status
-
decodePartialSuccess
Decodes thepartial_success(field 1) of a protobufExport*ServiceResponse.- Parameters:
body- response bytes- Returns:
- the partial success,
Otlp.PartialSuccess.NONEwhen absent or malformed
-
errorText
Human text of an OTLP error body: JSON{"code","message"}, a binarygoogle.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 namestatus- HTTP statusbody- response body (protobuf Status, JSON or text), may be nullsecrets- secret values to remove- Returns:
- the exception of the matching subclass
-
codeForGrpcStatus
Maps a gRPC status code to an SDKErrorCode.- Parameters:
status- gRPC status code- Returns:
- the code
-
grpcStatusName
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 namestatus- gRPC status codemessage- grpc-message, may be nullsecrets- 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 nameerror- the failuresecrets- secret values to remove- Returns:
TimeoutExceptionfor timeouts, elseUnavailableException
-
exporterRetryPolicy
public static Optional<io.opentelemetry.sdk.common.export.RetryPolicy> exporterRetryPolicy(RetryPolicy retry) Exporter retry policy derived from the SDK retry policy (maxRetries + 1attempts, 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) AppliesTlsOptionsto an OpenTelemetry exporter builder: trusted CA certificates, client certificate and key, or a trust-all context forinsecureSkipVerify(tests only).- Parameters:
tls- TLS optionssslContext- the builder'ssetSslContexttrusted- the builder'ssetTrustedCertificatesclientTls- the builder'ssetClientTls(key, cert)- Throws:
ConfigException- when a file cannot be read
-
trustManager
The trust manager matchingTlsOptions: trust-all forinsecureSkipVerify, 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
-