Table of Contents

Struct Baggage

Namespace
OpenTelemetry
Assembly
OpenTelemetry.Api.dll

Baggage implementation.

public readonly struct Baggage : IEquatable<Baggage>
Implements
Inherited Members

Remarks

Spec reference: Baggage API.

Properties

Count

Gets the number of key/value pairs in the baggage.

public int Count { get; }

Property Value

int

Current

Gets or sets the current Baggage.

public static Baggage Current { get; set; }

Property Value

Baggage

Remarks

Note: Current returns a forked version of the current Baggage. Changes to the forked version will not automatically be reflected back on Current. To update Current either use one of the static methods that target Current as the default source or set Current to a new instance of Baggage. Examples:

Baggage.SetBaggage("newKey1", "newValue1"); // Updates Baggage.Current with 'newKey1'
Baggage.SetBaggage("newKey2", "newValue2"); // Updates Baggage.Current with 'newKey2'

Or:

var baggageCopy = Baggage.Current;
Baggage.SetBaggage("newKey1", "newValue1"); // Updates Baggage.Current with 'newKey1'
var newBaggage = baggageCopy
    .SetBaggage("newKey2", "newValue2");
    .SetBaggage("newKey3", "newValue3");
// Sets Baggage.Current to 'newBaggage' which will override any
// changes made to Baggage.Current after the copy was made. For example
// the 'newKey1' change is lost.
Baggage.Current = newBaggage;

Methods

ClearBaggage()

Returns a new Baggage with all the key/value pairs removed.

public Baggage ClearBaggage()

Returns

Baggage

New Baggage containing the key/value pair.

ClearBaggage(Baggage)

Returns a new Baggage with all the key/value pairs removed.

public static Baggage ClearBaggage(Baggage baggage = default)

Parameters

baggage Baggage

Optional Baggage. Current is used if not specified.

Returns

Baggage

New Baggage containing the key/value pair.

Remarks

Note: The Baggage returned will be set as the new Current instance.

Create(Dictionary<string, string>)

Create a Baggage instance from dictionary of baggage key/value pairs.

public static Baggage Create(Dictionary<string, string> baggageItems = null)

Parameters

baggageItems Dictionary<string, string>

Baggage key/value pairs.

Returns

Baggage

Baggage.

Equals(Baggage)

public bool Equals(Baggage other)

Parameters

other Baggage

Returns

bool

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

GetBaggage()

Returns the name/value pairs in the Baggage.

public IReadOnlyDictionary<string, string> GetBaggage()

Returns

IReadOnlyDictionary<string, string>

Baggage key/value pairs.

GetBaggage(Baggage)

Returns the name/value pairs in the Baggage.

public static IReadOnlyDictionary<string, string> GetBaggage(Baggage baggage = default)

Parameters

baggage Baggage

Optional Baggage. Current is used if not specified.

Returns

IReadOnlyDictionary<string, string>

Baggage key/value pairs.

GetBaggage(string)

Returns the value associated with the given name, or null if the given name is not present.

public string GetBaggage(string name)

Parameters

name string

Baggage item name.

Returns

string

Baggage item or null if nothing was found.

GetBaggage(string, Baggage)

Returns the value associated with the given name, or null if the given name is not present.

public static string GetBaggage(string name, Baggage baggage = default)

Parameters

name string

Baggage item name.

baggage Baggage

Optional Baggage. Current is used if not specified.

Returns

string

Baggage item or null if nothing was found.

GetEnumerator()

Returns an enumerator that iterates through the Baggage.

public Dictionary<string, string>.Enumerator GetEnumerator()

Returns

Dictionary<string, string>.Enumerator

Dictionary<TKey, TValue>.Enumerator.

GetEnumerator(Baggage)

Returns an enumerator that iterates through the Baggage.

public static Dictionary<string, string>.Enumerator GetEnumerator(Baggage baggage = default)

Parameters

baggage Baggage

Optional Baggage. Current is used if not specified.

Returns

Dictionary<string, string>.Enumerator

Dictionary<TKey, TValue>.Enumerator.

GetHashCode()

public override int GetHashCode()

Returns

int

RemoveBaggage(string)

Returns a new Baggage with the key/value pair removed.

public Baggage RemoveBaggage(string name)

Parameters

name string

Baggage item name.

Returns

Baggage

New Baggage containing the key/value pair.

RemoveBaggage(string, Baggage)

Returns a new Baggage with the key/value pair removed.

public static Baggage RemoveBaggage(string name, Baggage baggage = default)

Parameters

name string

Baggage item name.

baggage Baggage

Optional Baggage. Current is used if not specified.

Returns

Baggage

New Baggage containing the key/value pair.

Remarks

Note: The Baggage returned will be set as the new Current instance.

SetBaggage(IEnumerable<KeyValuePair<string, string>>)

Returns a new Baggage which contains the new key/value pair.

public Baggage SetBaggage(IEnumerable<KeyValuePair<string, string>> baggageItems)

Parameters

baggageItems IEnumerable<KeyValuePair<string, string>>

Baggage key/value pairs.

Returns

Baggage

New Baggage containing the key/value pair.

SetBaggage(IEnumerable<KeyValuePair<string, string>>, Baggage)

Returns a new Baggage which contains the new key/value pair.

public static Baggage SetBaggage(IEnumerable<KeyValuePair<string, string>> baggageItems, Baggage baggage = default)

Parameters

baggageItems IEnumerable<KeyValuePair<string, string>>

Baggage key/value pairs.

baggage Baggage

Optional Baggage. Current is used if not specified.

Returns

Baggage

New Baggage containing the key/value pair.

Remarks

Note: The Baggage returned will be set as the new Current instance.

SetBaggage(params KeyValuePair<string, string>[])

Returns a new Baggage which contains the new key/value pair.

public Baggage SetBaggage(params KeyValuePair<string, string>[] baggageItems)

Parameters

baggageItems KeyValuePair<string, string>[]

Baggage key/value pairs.

Returns

Baggage

New Baggage containing the key/value pair.

SetBaggage(string, string)

Returns a new Baggage which contains the new key/value pair.

public Baggage SetBaggage(string name, string value)

Parameters

name string

Baggage item name.

value string

Baggage item value.

Returns

Baggage

New Baggage containing the key/value pair.

SetBaggage(string, string, Baggage)

Returns a new Baggage which contains the new key/value pair.

public static Baggage SetBaggage(string name, string value, Baggage baggage = default)

Parameters

name string

Baggage item name.

value string

Baggage item value.

baggage Baggage

Optional Baggage. Current is used if not specified.

Returns

Baggage

New Baggage containing the key/value pair.

Remarks

Note: The Baggage returned will be set as the new Current instance.

Operators

operator ==(Baggage, Baggage)

Compare two entries of Baggage for equality.

public static bool operator ==(Baggage left, Baggage right)

Parameters

left Baggage

First Entry to compare.

right Baggage

Second Entry to compare.

Returns

bool

operator !=(Baggage, Baggage)

Compare two entries of Baggage for not equality.

public static bool operator !=(Baggage left, Baggage right)

Parameters

left Baggage

First Entry to compare.

right Baggage

Second Entry to compare.

Returns

bool