-
Notifications
You must be signed in to change notification settings - Fork 790
/
Copy pathSpanAttributes.cs
126 lines (110 loc) · 3.46 KB
/
SpanAttributes.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
using System.Diagnostics;
using OpenTelemetry.Internal;
namespace OpenTelemetry.Trace;
/// <summary>
/// A class that represents the span attributes. Read more here https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/README.md#attribute.
/// </summary>
/// <remarks>SpanAttributes is a wrapper around <see cref="ActivityTagsCollection"/> class.</remarks>
public class SpanAttributes
{
/// <summary>
/// Initializes a new instance of the <see cref="SpanAttributes"/> class.
/// </summary>
public SpanAttributes()
{
this.Attributes = new ActivityTagsCollection();
}
/// <summary>
/// Initializes a new instance of the <see cref="SpanAttributes"/> class.
/// </summary>
/// <param name="attributes">Initial attributes to store in the collection.</param>
public SpanAttributes(IEnumerable<KeyValuePair<string, object?>> attributes)
: this()
{
Guard.ThrowIfNull(attributes);
foreach (KeyValuePair<string, object?> kvp in attributes)
{
this.AddInternal(kvp.Key, kvp.Value);
}
}
internal ActivityTagsCollection Attributes { get; }
/// <summary>
/// Add entry to the attributes.
/// </summary>
/// <param name="key">Entry key.</param>
/// <param name="value">Entry value.</param>
public void Add(string key, long value)
{
this.AddInternal(key, value);
}
/// <summary>
/// Add entry to the attributes.
/// </summary>
/// <param name="key">Entry key.</param>
/// <param name="value">Entry value.</param>
public void Add(string key, string? value)
{
this.AddInternal(key, value);
}
/// <summary>
/// Add entry to the attributes.
/// </summary>
/// <param name="key">Entry key.</param>
/// <param name="value">Entry value.</param>
public void Add(string key, bool value)
{
this.AddInternal(key, value);
}
/// <summary>
/// Add entry to the attributes.
/// </summary>
/// <param name="key">Entry key.</param>
/// <param name="value">Entry value.</param>
public void Add(string key, double value)
{
this.AddInternal(key, value);
}
/// <summary>
/// Add entry to the attributes.
/// </summary>
/// <param name="key">Entry key.</param>
/// <param name="values">Entry value.</param>
public void Add(string key, long[]? values)
{
this.AddInternal(key, values);
}
/// <summary>
/// Add entry to the attributes.
/// </summary>
/// <param name="key">Entry key.</param>
/// <param name="values">Entry value.</param>
public void Add(string key, string?[]? values)
{
this.AddInternal(key, values);
}
/// <summary>
/// Add entry to the attributes.
/// </summary>
/// <param name="key">Entry key.</param>
/// <param name="values">Entry value.</param>
public void Add(string key, bool[]? values)
{
this.AddInternal(key, values);
}
/// <summary>
/// Add entry to the attributes.
/// </summary>
/// <param name="key">Entry key.</param>
/// <param name="values">Entry value.</param>
public void Add(string key, double[]? values)
{
this.AddInternal(key, values);
}
private void AddInternal(string key, object? value)
{
Guard.ThrowIfNull(key);
this.Attributes[key] = value;
}
}