Package codes.grow.packages.tempo
Class OtlpJson
java.lang.Object
codes.grow.packages.tempo.OtlpJson
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 TypeMethodDescriptionstatic ObjectfromAnyValue(com.fasterxml.jackson.databind.JsonNode value) Converts an OTLPAnyValue: strings, booleans,Long(intValue),Double(doubleValue), lists (arrayValue), maps (kvlistValue) and base64 text (bytesValue).fromKeyValues(com.fasterxml.jackson.databind.JsonNode list) Converts an OTLP attribute list ([{key, value}]) to a map; empty values are dropped.static StringConverts an id from the trace-by-id JSON (base64 protobuf bytes) to lower-case hex, left-padded tohexLength.static longlongValue(com.fasterxml.jackson.databind.JsonNode node) Reads a 64-bit integer that protobuf JSON may send as a string or a number.static longnanosToMicros(com.fasterxml.jackson.databind.JsonNode node) Converts a decimal nanosecond value (string or number node) to whole microseconds.spansFromResourceSpans(com.fasterxml.jackson.databind.JsonNode resourceSpans) Flattens OTLPresourceSpans → scopeSpans → spans(v2trace.resourceSpans, v1batches) into model spans: ids base64 → hex, nanoseconds → microseconds, enums → model values,serviceNamefrom the resourceservice.name.
-
Method Details
-
idToHex
Converts an id from the trace-by-id JSON (base64 protobuf bytes) to lower-case hex, left-padded tohexLength. An id that already is hex of that length is kept.- Parameters:
id- base64 or hex id, ornullhexLength- 32 for trace ids, 16 for span ids- Returns:
- the hex id, or
nullwhen 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 ornull- 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 ornull- Returns:
- the value, 0 when missing or not a number
-
fromAnyValue
Converts an OTLPAnyValue: strings, booleans,Long(intValue),Double(doubleValue), lists (arrayValue), maps (kvlistValue) and base64 text (bytesValue).- Parameters:
value- AnyValue node ornull- Returns:
- the value, or
nullfor an empty value
-
fromKeyValues
Converts an OTLP attribute list ([{key, value}]) to a map; empty values are dropped.- Parameters:
list- array node ornull- Returns:
- attributes in list order
-
spansFromResourceSpans
public static List<Span> spansFromResourceSpans(com.fasterxml.jackson.databind.JsonNode resourceSpans) Flattens OTLPresourceSpans → scopeSpans → spans(v2trace.resourceSpans, v1batches) into model spans: ids base64 → hex, nanoseconds → microseconds, enums → model values,serviceNamefrom the resourceservice.name. Sorted by start, then span id.- Parameters:
resourceSpans- array node ornull- Returns:
- spans
-