func ContextWithBaggage(parent context.Context, b Baggage) context.Context
ContextWithBaggage returns a copy of parent with baggage.
func ContextWithoutBaggage(parent context.Context) context.Context
ContextWithoutBaggage returns a copy of parent with no baggage.
Baggage is a list of baggage members representing the baggage-string as defined by the W3C Baggage specification.
type Baggage struct {
// contains filtered or unexported fields
}
func FromContext(ctx context.Context) Baggage
FromContext returns the baggage contained in ctx.
func New(members ...Member) (Baggage, error)
New returns a new valid Baggage. It returns an error if it results in a Baggage exceeding limits set in that specification.
It expects all the provided members to have already been validated.
func Parse(bStr string) (Baggage, error)
Parse attempts to decode a baggage-string from the passed string. It returns an error if the input is invalid according to the W3C Baggage specification.
If there are duplicate list-members contained in baggage, the last one defined (reading left-to-right) will be the only one kept. This diverges from the W3C Baggage specification which allows duplicate list-members, but conforms to the OpenTelemetry Baggage specification.
func (b Baggage) DeleteMember(key string) Baggage
DeleteMember returns a copy of the Baggage with the list-member identified by key removed.
func (b Baggage) Len() int
Len returns the number of list-members in the Baggage.
func (b Baggage) Member(key string) Member
Member returns the baggage list-member identified by key.
If there is no list-member matching the passed key the returned Member will be a zero-value Member. The returned member is not validated, as we assume the validation happened when it was added to the Baggage.
func (b Baggage) Members() []Member
Members returns all the baggage list-members. The order of the returned list-members does not have significance.
The returned members are not validated, as we assume the validation happened when they were added to the Baggage.
func (b Baggage) SetMember(member Member) (Baggage, error)
SetMember returns a copy the Baggage with the member included. If the baggage contains a Member with the same key the existing Member is replaced.
If member is invalid according to the W3C Baggage specification, an error is returned with the original Baggage.
func (b Baggage) String() string
String encodes Baggage into a string compliant with the W3C Baggage specification. The returned string will be invalid if the Baggage contains any invalid list-members.
Member is a list-member of a baggage-string as defined by the W3C Baggage specification.
type Member struct {
// contains filtered or unexported fields
}
func NewMember(key, value string, props ...Property) (Member, error)
NewMember returns a new Member from the passed arguments. The key will be used directly while the value will be url decoded after validation. An error is returned if the created Member would be invalid according to the W3C Baggage specification.
func (m Member) Key() string
Key returns the Member key.
func (m Member) Properties() []Property
Properties returns a copy of the Member properties.
func (m Member) String() string
String encodes Member into a string compliant with the W3C Baggage specification.
func (m Member) Value() string
Value returns the Member value.
Property is an additional metadata entry for a baggage list-member.
type Property struct {
// contains filtered or unexported fields
}
func NewKeyProperty(key string) (Property, error)
NewKeyProperty returns a new Property for key.
If key is invalid, an error will be returned.
func NewKeyValueProperty(key, value string) (Property, error)
NewKeyValueProperty returns a new Property for key with value.
If key or value are invalid, an error will be returned.
func (p Property) Key() string
Key returns the Property key.
func (p Property) String() string
String encodes Property into a string compliant with the W3C Baggage specification.
func (p Property) Value() (string, bool)
Value returns the Property value. Additionally, a boolean value is returned indicating if the returned value is the empty if the Property has a value that is empty or if the value is not set.