ocaml-opentelemetry/src/core/trace_state.mli
2026-04-04 01:06:51 -04:00

42 lines
1.4 KiB
OCaml
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(** W3C Trace State.
A list of vendor-specific key/value pairs propagated across distributed
tracing systems.
@since NEXT_RELEASE
https://www.w3.org/TR/trace-context/#tracestate-header *)
type t = (string * string) list
val empty : t
val is_valid_key : string -> bool
(** [is_valid_key k] is true if [k] is a valid W3C tracestate key. Keys must
start with [a-z], followed by [a-z0-9_-*/], and be at most 256 chars. *)
val is_valid_value : string -> bool
(** [is_valid_value v] is true if [v] is a valid W3C tracestate value. Values
must be printable ASCII (0x200x7E), excluding [,] and [=], with no
leading/trailing space, and at most 256 chars. *)
val get : t -> string -> string option
val set : t -> string -> string -> t
(** [set ts key value] adds or replaces [key] in [ts], placing it at the front
(most-recently-updated), per the W3C spec.
@raise Invalid_argument
if [key] or [value] fail their respective validators. *)
val delete : t -> string -> t
val encoded_length : t -> int
(** Length of the string produced by {!to_w3c_string}. *)
val to_w3c_string : t -> string
(** Encodes as a W3C tracestate header value ([k1=v1,k2=v2,...]). Returns [""]
for an empty list. *)
val of_w3c_string : string -> (t, string) result
(** Parses a W3C tracestate header value. Malformed or invalid entries are
silently skipped rather than returning an error. *)