Class OtlpLogs

java.lang.Object
codes.grow.packages.betterstack.OtlpLogs

public final class OtlpLogs extends Object
OTLP logs encoding without dependencies: ExportLogsServiceRequest as protobuf (field numbers of opentelemetry-proto collector/logs/v1 and logs/v1) or as OTLP/JSON, and partial_success parsing of the response.
  • Field Details

    • DEFAULT_SCOPE_NAME

      public static final String DEFAULT_SCOPE_NAME
      Instrumentation scope name of exported records.
      See Also:
  • Method Details

    • encodeLogRecord

      public static byte[] encodeLogRecord(LogRecord r)
      Encodes one OTLP LogRecord message.
      Parameters:
      r - record
      Returns:
      protobuf bytes
    • encodeProtobuf

      public static byte[] encodeProtobuf(List<LogRecord> records, String scopeName)
      Encodes an ExportLogsServiceRequest as protobuf: one ResourceLogs per distinct resource with one ScopeLogs (scopeName, SDK version).
      Parameters:
      records - records
      scopeName - instrumentation scope name
      Returns:
      protobuf bytes
    • jsonRequest

      public static Map<String,Object> jsonRequest(List<LogRecord> records, String scopeName)
      Builds the OTLP/JSON ExportLogsServiceRequest object.
      Parameters:
      records - records
      scopeName - instrumentation scope name
      Returns:
      the request as nested maps and lists
    • parsePartialSuccess

      public static Optional<OtlpLogs.PartialSuccess> parsePartialSuccess(byte[] body)
      Reads partial_success from a protobuf ExportLogsServiceResponse.
      Parameters:
      body - response bytes
      Returns:
      the partial success when records were rejected; empty otherwise or when unreadable
    • parsePartialSuccessJson

      public static Optional<OtlpLogs.PartialSuccess> parsePartialSuccessJson(byte[] body)
      Reads partialSuccess from an OTLP/JSON response body.
      Parameters:
      body - response bytes (may be empty)
      Returns:
      the partial success when records were rejected; empty otherwise or when unreadable