class TagContext

TagContext represents a collection of tags.

A TagContext can be used to label anything that is associated with a specific operation, such as an HTTP request. Each tag is composed of a key (TagKey), and a value (TagValue). A TagContext represents a map from keys to values, i.e., each key is associated with exactly one value, but multiple keys can be associated with the same value. TagContext is serializable, and it represents all of the information that must be propagated across process boundaries.

Traits

Internal utility methods for working with tag keys, tag values, and metric names.

Constants

CTX_KEY

The key used for storing and retrieving a TagContext object from Context.

MAX_LENGTH

The maximum length for a serialized TagContext.

EX_INVALID_CONTEXT

Invalid Context Error message

Methods

string
value(TagKey $key)

Returns the value for the key if a value for the key exists.

bool
insert(TagKey $key, TagValue $value)

Insert a Tag into TagContext given provided TagKey and string value.

bool
update(TagKey $key, TagValue $value)

Update a Tag into TagContext given provided TagKey with string value.

upsert(TagKey $key, TagValue $value)

Insert or Update a Tag into TagContext given provided TagKey with provided string value.

bool
delete(TagKey $key)

Deletes Tag from TagContext identified by its TagKey.

string
__toString()

Serializes the TagContext to a string representation.

array
tags()

Returns an array of Tag objects this map holds.

static TagContext
empty()

Returns an empty YagContext object.

static TagContext
fromContext(Context $ctx = null)

Extract a TagContext from the provided Context object.

static TagContext
new(Context $ctx = null)

Copy and return the TagContext as found in the provided Context object.

newContext(Context $ctx = null)

Creates a new Context with our TagContext attached.

Details

at line 61
final string value(TagKey $key)

Returns the value for the key if a value for the key exists.

Parameters

TagKey $key The key to retrieve the value for.

Return Value

string

at line 74
final bool insert(TagKey $key, TagValue $value)

Insert a Tag into TagContext given provided TagKey and string value.

If TagKey already exists in TagContext this method is a noop.

Parameters

TagKey $key the key of the Tag.
TagValue $value the value of the Tag.

Return Value

bool returns true on successful insert.

at line 92
final bool update(TagKey $key, TagValue $value)

Update a Tag into TagContext given provided TagKey with string value.

If TagKey does not exist in TagContext this method is a noop.

Parameters

TagKey $key the key of the Tag.
TagValue $value the value of the Tag.

Return Value

bool returns true on successful update.

at line 109
final upsert(TagKey $key, TagValue $value)

Insert or Update a Tag into TagContext given provided TagKey with provided string value.

Parameters

TagKey $key key of the Tag.
TagValue $value value of the Tag.

at line 120
final bool delete(TagKey $key)

Deletes Tag from TagContext identified by its TagKey.

Parameters

TagKey $key

Return Value

bool returns true if Tag was found and deleted.

at line 135
final string __toString()

Serializes the TagContext to a string representation.

Return Value

string

Exceptions

Exception on failure to serialize.

at line 151
final array tags()

Returns an array of Tag objects this map holds.

Return Value

array

at line 161
final static TagContext empty()

Returns an empty YagContext object.

Return Value

TagContext

at line 173
final static TagContext fromContext(Context $ctx = null)

Extract a TagContext from the provided Context object.

If Context is not provided, the current Context is used. If no TagContext is found, a new empty TagContext is returned.

Parameters

Context $ctx The Context to extract the TagContext from.

Return Value

TagContext

at line 189
final static TagContext new(Context $ctx = null)

Copy and return the TagContext as found in the provided Context object.

If Context is not provided, the current Context is used. If no TagContext is found, a new empty TagContext is returned.

Parameters

Context $ctx The Context to extract and copy the TagContext from.

Return Value

TagContext

at line 202
final Context newContext(Context $ctx = null)

Creates a new Context with our TagContext attached.

To propagate a TagContext to downstream methods and downstream RPCs, add a TagContext to the current Context. If there is already a TagContext in the current context, it will be replaced with this TagContext.

Parameters

Context $ctx The source context to copy.

Return Value

Context The target context with our TagContext added.