Closed
Description
Background and Motivation
Both Activity.Tags
and Activity.Baggage
have a somewhat unusual IEnumerable<KeyValuePair<string, string?>>
type, which makes it cumbersome to access individual values (i.e. can't do activity.Tags.TryGetValue(key, out var value)
). The latter adds a Activity.GetBaggageItem to compensate, but there isn't an equivalent one for Tags
.
Proposed API
namespace System.Diagnostics
{
public class Activity {
+ public object? GetTagItem(string key)
Usage Examples
Activity activity = ...;
var tag = activity.GetTagItem("Foo");
if (tag != null) {
// do something with tag
}
Alternative Designs
The obvious alternative would be to use the dictionary-style bool TryGetTag(string key)
instead.
namespace System.Diagnostics
{
public class Activity {
+ public bool TryGetTag(string key, out string? value)
For consistency, that would likely require changing the existing GetBaggageItem(string key)
to bool TryGetBaggage(string key)
too, I think.
namespace System.Diagnostics
{
public class Activity {
- public string? GetBaggageItem(string key)
+ public bool TryGetBaggage(string key, out object? value)
I think this alternative proposal is much more idiomatic than the existing GetBaggageItem
and the proposed GetTagItem
.
Risks
None I can think of.