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
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_\-*/]*, up to 256 characters) or a multi-tenant keytenant@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.
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 ClassesModifier and TypeClassDescriptionstatic final recordOnekey=valuepair of a trace state. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TraceStateA trace state without members.static final StringThe request header that carries the trace state.static final intLongest header value that is accepted and produced.static final intMost members in a trace state. -
Constructor Summary
ConstructorsConstructorDescriptionTraceState(List<TraceState.Member> members) Copies and validates the members. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.Returns the value of a member.final inthashCode()Returns a hash code value for this object.header()Formats the state as atracestateheader value.booleanisEmpty()Reports whether there are no members.members()Returns the value of themembersrecord component.static Optional<TraceState> Parses atracestateheader value strictly.final StringtoString()Returns a string representation of this record class.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.
-
Field Details
-
HEADER
The request header that carries the trace state.- See Also:
-
MAX_MEMBERS
public static final int MAX_MEMBERSMost members in a trace state.- See Also:
-
MAX_LENGTH
public static final int MAX_LENGTHLongest header value that is accepted and produced.- See Also:
-
EMPTY
A trace state without members.
-
-
Constructor Details
-
TraceState
Copies and validates the members.- Throws:
IllegalArgumentException- for more than 32 members, duplicate keys or a header form longer than 512 characters
-
-
Method Details
-
parse
Parses atracestateheader 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
Returns the value of a member.- Parameters:
key- the member's key- Returns:
- its value, if present
-
with
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 keyvalue- 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
Formats the state as atracestateheader value.- Returns:
- the members joined with commas; empty for no members
-
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
members
Returns the value of themembersrecord component.- Returns:
- the value of the
membersrecord component
-