Class OtlpJson

java.lang.Object
codes.grow.packages.tempo.OtlpJson

public final class OtlpJson extends Object
Converts the OTLP JSON that Tempo returns for a trace by id (protobuf JSON: ids in base64, times as decimal nanosecond strings, enums as names) into the normalized Span model.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object
    fromAnyValue(com.fasterxml.jackson.databind.JsonNode value)
    Converts an OTLP AnyValue: strings, booleans, Long (intValue), Double (doubleValue), lists (arrayValue), maps (kvlistValue) and base64 text (bytesValue).
    static Map<String,Object>
    fromKeyValues(com.fasterxml.jackson.databind.JsonNode list)
    Converts an OTLP attribute list ([{key, value}]) to a map; empty values are dropped.
    static String
    idToHex(String id, int hexLength)
    Converts an id from the trace-by-id JSON (base64 protobuf bytes) to lower-case hex, left-padded to hexLength.
    static long
    longValue(com.fasterxml.jackson.databind.JsonNode node)
    Reads a 64-bit integer that protobuf JSON may send as a string or a number.
    static long
    nanosToMicros(com.fasterxml.jackson.databind.JsonNode node)
    Converts a decimal nanosecond value (string or number node) to whole microseconds.
    static List<Span>
    spansFromResourceSpans(com.fasterxml.jackson.databind.JsonNode resourceSpans)
    Flattens OTLP resourceSpans → scopeSpans → spans (v2 trace.resourceSpans, v1 batches) into model spans: ids base64 → hex, nanoseconds → microseconds, enums → model values, serviceName from the resource service.name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • idToHex

      public static String idToHex(String id, int hexLength)
      Converts an id from the trace-by-id JSON (base64 protobuf bytes) to lower-case hex, left-padded to hexLength. An id that already is hex of that length is kept.
      Parameters:
      id - base64 or hex id, or null
      hexLength - 32 for trace ids, 16 for span ids
      Returns:
      the hex id, or null when empty, all zero or not decodable
    • nanosToMicros

      public static long nanosToMicros(com.fasterxml.jackson.databind.JsonNode node)
      Converts a decimal nanosecond value (string or number node) to whole microseconds.
      Parameters:
      node - value node or null
      Returns:
      microseconds, 0 when missing or not a number
    • longValue

      public static long longValue(com.fasterxml.jackson.databind.JsonNode node)
      Reads a 64-bit integer that protobuf JSON may send as a string or a number.
      Parameters:
      node - value node or null
      Returns:
      the value, 0 when missing or not a number
    • fromAnyValue

      public static Object fromAnyValue(com.fasterxml.jackson.databind.JsonNode value)
      Converts an OTLP AnyValue: strings, booleans, Long (intValue), Double (doubleValue), lists (arrayValue), maps (kvlistValue) and base64 text (bytesValue).
      Parameters:
      value - AnyValue node or null
      Returns:
      the value, or null for an empty value
    • fromKeyValues

      public static Map<String,Object> fromKeyValues(com.fasterxml.jackson.databind.JsonNode list)
      Converts an OTLP attribute list ([{key, value}]) to a map; empty values are dropped.
      Parameters:
      list - array node or null
      Returns:
      attributes in list order
    • spansFromResourceSpans

      public static List<Span> spansFromResourceSpans(com.fasterxml.jackson.databind.JsonNode resourceSpans)
      Flattens OTLP resourceSpans → scopeSpans → spans (v2 trace.resourceSpans, v1 batches) into model spans: ids base64 → hex, nanoseconds → microseconds, enums → model values, serviceName from the resource service.name. Sorted by start, then span id.
      Parameters:
      resourceSpans - array node or null
      Returns:
      spans