Class TraceState

Class Documentation

class TraceState

TraceState carries tracing-system specific context in a list of key-value pairs. TraceState allows different vendors to propagate additional information and inter-operate with their legacy id formats.

For more information, see the W3C Trace Context specification: https://www.w3.org/TR/trace-context

Public Functions

inline std::string ToHeader() const noexcept

Creates a w3c tracestate header from TraceState object

inline bool Get(nostd::string_view key, std::string &value) const noexcept

Returns value associated with key passed as argument Returns empty string if key is invalid or not found

inline nostd::shared_ptr<TraceState> Set(const nostd::string_view &key, const nostd::string_view &value) noexcept

Returns shared_ptr of new TraceState object with following mutations applied to the existing instance: Update Key value: The updated value must be moved to beginning of List Add : The new key-value pair SHOULD be added to beginning of List

If the provided key-value pair is invalid, or results in transtate that violates the tracecontext specification, empty TraceState instance will be returned.

If the existing object has maximum list members, it’s copy is returned.

inline nostd::shared_ptr<TraceState> Delete(const nostd::string_view &key) noexcept

Returns shared_ptr to a new TraceState object after removing the attribute with given key ( if present )

Returns:

empty TraceState object if key is invalid

Returns:

copy of original TraceState object if key is not present (??)

inline bool Empty() const noexcept
inline bool GetAllEntries(nostd::function_ref<bool(nostd::string_view, nostd::string_view)> callback) const noexcept

Public Static Functions

static inline OPENTELEMETRY_API_SINGLETON nostd::shared_ptr< TraceState > GetDefault ()
static inline nostd::shared_ptr<TraceState> FromHeader(nostd::string_view header) noexcept

Returns shared_ptr to a newly created TraceState parsed from the header provided.

Parameters:

header – Encoding of the tracestate header defined by the W3C Trace Context specification https://www.w3.org/TR/trace-context/

Returns:

TraceState A new TraceState instance or DEFAULT

static inline bool IsValidKey(nostd::string_view key)

Returns whether key is a valid key. See https://www.w3.org/TR/trace-context/#key Identifiers MUST begin with a lowercase letter or a digit, and can only contain lowercase letters (a-z), digits (0-9), underscores (_), dashes (-), asterisks (*), and forward slashes (/). For multi-tenant vendor scenarios, an at sign (@) can be used to prefix the vendor name.

static inline bool IsValidValue(nostd::string_view value)

Returns whether value is a valid value. See https://www.w3.org/TR/trace-context/#value The value is an opaque string containing up to 256 printable ASCII (RFC0020) characters ((i.e., the range 0x20 to 0x7E) except comma , and equal =)

Public Static Attributes

static constexpr int kKeyMaxSize = 256
static constexpr int kValueMaxSize = 256
static constexpr int kMaxKeyValuePairs = 32
static constexpr auto kKeyValueSeparator = '='
static constexpr auto kMembersSeparator = ','