Record Class ZipkinSpan

java.lang.Object
java.lang.Record
codes.grow.packages.skywalking.ZipkinSpan
Record Components:
traceId - trace id (hex)
id - span id (hex)
parentId - parent span id, "" for roots
kind - CLIENT, SERVER, PRODUCER, CONSUMER or "" (internal)
name - span name (lower-cased by OAP)
timestamp - start in epoch microseconds
duration - duration in microseconds
localServiceName - localEndpoint.serviceName
annotations - events (name|attributesJSON|droppedCount)
tags - tags

public record ZipkinSpan(String traceId, String id, String parentId, String kind, String name, long timestamp, long duration, String localServiceName, List<ZipkinSpan.Annotation> annotations, Map<String,String> tags) extends Record
A span as OAP's Zipkin query API returns it (:9412/zipkin/api/v2): the stored form of spans exported over OTLP. OAP lower-cases span names on ingest and stores attribute values as strings.
  • Constructor Details

    • ZipkinSpan

      public ZipkinSpan(String traceId, String id, String parentId, String kind, String name, long timestamp, long duration, String localServiceName, List<ZipkinSpan.Annotation> annotations, Map<String,String> tags)
      Copies collections and normalises nulls.
      Parameters:
      traceId - trace id
      id - span id
      parentId - parent id
      kind - kind
      name - name
      timestamp - start
      duration - duration
      localServiceName - service
      annotations - annotations
      tags - tags
  • Method Details

    • isHexTraceId

      public static boolean isHexTraceId(String id)
      Whether id is a 16- or 32-character hex id (OTLP/Zipkin), as opposed to a native SkyWalking id.
      Parameters:
      id - trace id
      Returns:
      true for hex ids
    • zipkinTraceId

      public static String zipkinTraceId(String id, String operation)
      Lower-cases and validates a Zipkin trace id.
      Parameters:
      id - trace id
      operation - operation name for the error
      Returns:
      the lower-case id
      Throws:
      ValidationException - unless the id is 16 or 32 hex characters, not all zero
    • fromJson

      public static Optional<ZipkinSpan> fromJson(com.fasterxml.jackson.databind.JsonNode s)
      Decodes a span; empty when traceId or id is missing.
      Parameters:
      s - JSON object
      Returns:
      the span, or empty
    • listFrom

      public static List<ZipkinSpan> listFrom(com.fasterxml.jackson.databind.JsonNode body)
      Decodes the well-formed spans of a [span...] body.
      Parameters:
      body - JSON array
      Returns:
      the spans
    • isBookkeepingTag

      public static boolean isBookkeepingTag(String key)
      Whether a tag is OAP bookkeeping (otel.*, error, w3c.tracestate); such tags become status fields or are dropped from the attributes.
      Parameters:
      key - tag key
      Returns:
      true for bookkeeping tags
    • toEvent

      public static Span.Event toEvent(ZipkinSpan.Annotation a)
      Decodes an OAP annotation into an event: name|{"k":"v"}|0 (split on the first and last |) → name and attributes; any other value is the event name without attributes.
      Parameters:
      a - annotation
      Returns:
      the event
    • toSpan

      public Span toSpan()
      Converts to the SPEC model: ids lower-case (trace id padded to 32), kind lower-case (absent → internal, unknown → unspecified), service = localEndpoint.serviceName, status from otel.status_code (STATUS_CODE_ERROR → error with otel.status_description, STATUS_CODE_OK → ok, an error tag alone → error), attributes = tags without the bookkeeping tags, annotations → events.
      Returns:
      the span
    • toTrace

      public static Optional<Trace> toTrace(List<ZipkinSpan> spans)
      Converts the spans of one Zipkin trace into a SPEC trace (spans sorted).
      Parameters:
      spans - spans of one trace
      Returns:
      the trace, or empty when there are no spans
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • traceId

      public String traceId()
      Returns the value of the traceId record component.
      Returns:
      the value of the traceId record component
    • id

      public String id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • parentId

      public String parentId()
      Returns the value of the parentId record component.
      Returns:
      the value of the parentId record component
    • kind

      public String kind()
      Returns the value of the kind record component.
      Returns:
      the value of the kind record component
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • timestamp

      public long timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component
    • duration

      public long duration()
      Returns the value of the duration record component.
      Returns:
      the value of the duration record component
    • localServiceName

      public String localServiceName()
      Returns the value of the localServiceName record component.
      Returns:
      the value of the localServiceName record component
    • annotations

      public List<ZipkinSpan.Annotation> annotations()
      Returns the value of the annotations record component.
      Returns:
      the value of the annotations record component
    • tags

      public Map<String,String> tags()
      Returns the value of the tags record component.
      Returns:
      the value of the tags record component