Record Class TraceState

java.lang.Object
java.lang.Record
com.jsgalactic.axiom.observability.TraceState
Record Components:
members - the members, most recently updated first; at most 32

public record TraceState(List<TraceState.Member> members) extends Record
The W3C Trace Context tracestate of a request: an ordered list of vendor-specific key=value members that travels with a TraceContext. Axiom does not interpret the members; it validates them and passes them on, so a service that sits in the middle of a trace does not drop what other vendors recorded.

Parsing is strict, and a value that breaks any rule is treated as absent, never partly kept: the request simply has no trace state, as the specification allows for an invalid header. The rules are the specification's grammar plus a fixed size limit.

  • At most 32 members and 512 characters in all (the smallest size every implementation must propagate). A longer header is ignored whole.
  • A key is a lowercase simple key ([a-z][a-z0-9_\-*&#47;]*, up to 256 characters) or a multi-tenant key tenant@system (tenant up to 241, system up to 14 characters).
  • A value is up to 256 printable ASCII characters other than , and =, not ending in a space.
  • Keys are unique; empty list elements are skipped; spaces and tabs may surround members.
Several tracestate headers, joined by the HTTP layer with commas, are one list. The values are chosen by the caller: they are for propagation, never for authorization or metric tags.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    One key=value pair of a trace state.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final TraceState
    A trace state without members.
    static final String
    The request header that carries the trace state.
    static final int
    Longest header value that is accepted and produced.
    static final int
    Most members in a trace state.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Copies and validates the members.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    get(String key)
    Returns the value of a member.
    final int
    Returns a hash code value for this object.
    Formats the state as a tracestate header value.
    boolean
    Reports whether there are no members.
    Returns the value of the members record component.
    parse(String header)
    Parses a tracestate header value strictly.
    final String
    Returns a string representation of this record class.
    with(String key, String value)
    Returns a state in which a member is set and moved to the front, as the specification asks of a vendor that changes its entry.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • MAX_MEMBERS

      public static final int MAX_MEMBERS
      Most members in a trace state.
      See Also:
    • MAX_LENGTH

      public static final int MAX_LENGTH
      Longest header value that is accepted and produced.
      See Also:
    • EMPTY

      public static final TraceState EMPTY
      A trace state without members.
  • Constructor Details

  • Method Details

    • parse

      public static Optional<TraceState> parse(String header)
      Parses a tracestate header value strictly.
      Parameters:
      header - the header value, or null if the request had none
      Returns:
      the trace state, or empty if the value is absent, has no members or is not valid
    • get

      public Optional<String> get(String key)
      Returns the value of a member.
      Parameters:
      key - the member's key
      Returns:
      its value, if present
    • with

      public TraceState with(String key, String value)
      Returns a state in which a member is set and moved to the front, as the specification asks of a vendor that changes its entry. If that makes the list longer than 32 members, the rightmost ones are dropped.
      Parameters:
      key - the member's key
      value - the new value
      Returns:
      the updated trace state
      Throws:
      IllegalArgumentException - if the key or value breaks the grammar, or the result would be longer than 512 characters
    • isEmpty

      public boolean isEmpty()
      Reports whether there are no members.
      Returns:
      true for EMPTY
    • header

      public String header()
      Formats the state as a tracestate header value.
      Returns:
      the members joined with commas; empty for no members
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • members

      public List<TraceState.Member> members()
      Returns the value of the members record component.
      Returns:
      the value of the members record component