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
Current
Gets or sets the current Baggage.
public static Baggage Current { get; set; }
Property Value
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
ClearBaggage(Baggage)
Returns a new Baggage with all the key/value pairs removed.
public static Baggage ClearBaggage(Baggage baggage = default)
Parameters
Returns
Remarks
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
Equals(Baggage)
public bool Equals(Baggage other)
Parameters
other
Baggage
Returns
Equals(object)
public override bool Equals(object obj)
Parameters
obj
object
Returns
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
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
stringBaggage item name.
Returns
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
Returns
GetEnumerator()
Returns an enumerator that iterates through the Baggage.
public Dictionary<string, string>.Enumerator GetEnumerator()
Returns
GetEnumerator(Baggage)
Returns an enumerator that iterates through the Baggage.
public static Dictionary<string, string>.Enumerator GetEnumerator(Baggage baggage = default)
Parameters
Returns
GetHashCode()
public override int GetHashCode()
Returns
RemoveBaggage(string)
Returns a new Baggage with the key/value pair removed.
public Baggage RemoveBaggage(string name)
Parameters
name
stringBaggage item name.
Returns
RemoveBaggage(string, Baggage)
Returns a new Baggage with the key/value pair removed.
public static Baggage RemoveBaggage(string name, Baggage baggage = default)
Parameters
Returns
Remarks
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
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
Returns
Remarks
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
SetBaggage(string, string)
Returns a new Baggage which contains the new key/value pair.
public Baggage SetBaggage(string name, string value)
Parameters
Returns
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
Returns
Remarks
Operators
operator ==(Baggage, Baggage)
Compare two entries of Baggage for equality.
public static bool operator ==(Baggage left, Baggage right)
Parameters
Returns
operator !=(Baggage, Baggage)
Compare two entries of Baggage for not equality.
public static bool operator !=(Baggage left, Baggage right)