baggage

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 7 Imported by: 0

README

Why do we have this "otel/baggage" folder?

The root sentry-go SDK (namely, the Dynamic Sampling functionality) needs an implementation of the baggage spec. For that reason, we've taken the existing baggage implementation from the opentelemetry-go repository, and fixed a few things that in our opinion were violating the specification.

These issues are:

  1. Baggage string value one%20two should be properly parsed as "one two"
  2. Baggage string value one+two should be parsed as "one+two"
  3. Go string value "one two" should be encoded as one%20two (percent encoding), and NOT as one+two (URL query encoding).
  4. Go string value "1=1" might be encoded as 1=1, because the spec says: "Note, value MAY contain any number of the equal sign (=) characters. Parsers MUST NOT assume that the equal sign is only used to separate key and value.". 1%3D1 is also valid, but to simplify the implementation we're not doing it.

Changes were made in this PR: https://github.com/getsentry/sentry-go/pull/568

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Baggage

type Baggage struct {
	// contains filtered or unexported fields
}

Baggage is a list of baggage members representing the baggage-string as defined by the W3C Baggage specification.

func New

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

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 (Baggage) DeleteMember

func (b Baggage) DeleteMember(key string) Baggage

DeleteMember returns a copy of the Baggage with the list-member identified by key removed.

func (Baggage) Len

func (b Baggage) Len() int

Len returns the number of list-members in the Baggage.

func (Baggage) Member

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 (Baggage) Members

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 (Baggage) SetMember

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 (Baggage) String

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.

type Member

type Member struct {
	// contains filtered or unexported fields
}

Member is a list-member of a baggage-string as defined by the W3C Baggage specification.

func NewMember

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 (Member) Key

func (m Member) Key() string

Key returns the Member key.

func (Member) Properties

func (m Member) Properties() []Property

Properties returns a copy of the Member properties.

func (Member) String

func (m Member) String() string

String encodes Member into a string compliant with the W3C Baggage specification.

func (Member) Value

func (m Member) Value() string

Value returns the Member value.

type Property

type Property struct {
	// contains filtered or unexported fields
}

Property is an additional metadata entry for a baggage list-member.

func NewKeyProperty

func NewKeyProperty(key string) (Property, error)

NewKeyProperty returns a new Property for key.

If key is invalid, an error will be returned.

func NewKeyValueProperty

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 (Property) Key

func (p Property) Key() string

Key returns the Property key.

func (Property) String

func (p Property) String() string

String encodes Property into a string compliant with the W3C Baggage specification.

func (Property) Value

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.

Directories

Path Synopsis
internal
baggage
Package baggage provides base types and functionality to store and retrieve baggage in Go context.
Package baggage provides base types and functionality to store and retrieve baggage in Go context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL