* Wrapping up enumerables for #407 and some cleanup * Fixing whitespaces * One more Co-authored-by: Sergey Kanzhelev <S.Kanzhelev@live.com>
This commit is contained in:
parent
5fa22a3bc2
commit
77b56f8847
|
|
@ -28,6 +28,9 @@ namespace OpenTelemetry.Context.Propagation
|
|||
/// </summary>
|
||||
public class TraceContextFormat : ITextFormat
|
||||
{
|
||||
private const string TraceParent = "traceparent";
|
||||
private const string TraceState = "tracestate";
|
||||
|
||||
private static readonly int VersionLength = "00".Length;
|
||||
private static readonly int VersionPrefixIdLength = "00-".Length;
|
||||
private static readonly int TraceIdLength = "0af7651916cd43dd8448eb211c80319c".Length;
|
||||
|
|
@ -38,14 +41,14 @@ namespace OpenTelemetry.Context.Propagation
|
|||
private static readonly int TraceparentLengthV0 = "00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-00".Length;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ISet<string> Fields => new HashSet<string> { "tracestate", "traceparent" };
|
||||
public ISet<string> Fields => new HashSet<string> { TraceState, TraceParent };
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SpanContext Extract<T>(T carrier, Func<T, string, IEnumerable<string>> getter)
|
||||
{
|
||||
try
|
||||
{
|
||||
var traceparentCollection = getter(carrier, "traceparent");
|
||||
var traceparentCollection = getter(carrier, TraceParent);
|
||||
|
||||
// There must be a single traceparent
|
||||
if (traceparentCollection == null || traceparentCollection.Count() != 1)
|
||||
|
|
@ -62,7 +65,7 @@ namespace OpenTelemetry.Context.Propagation
|
|||
}
|
||||
|
||||
List<KeyValuePair<string, string>> tracestate = null;
|
||||
var tracestateCollection = getter(carrier, "tracestate");
|
||||
var tracestateCollection = getter(carrier, TraceState);
|
||||
if (tracestateCollection != null)
|
||||
{
|
||||
this.TryExtractTracestate(tracestateCollection.ToArray(), out tracestate);
|
||||
|
|
@ -103,12 +106,12 @@ namespace OpenTelemetry.Context.Propagation
|
|||
var traceparent = string.Concat("00-", spanContext.TraceId.ToHexString(), "-", spanContext.SpanId.ToHexString());
|
||||
traceparent = string.Concat(traceparent, (spanContext.TraceOptions & ActivityTraceFlags.Recorded) != 0 ? "-01" : "-00");
|
||||
|
||||
setter(carrier, "traceparent", traceparent);
|
||||
setter(carrier, TraceParent, traceparent);
|
||||
|
||||
string tracestateStr = TracestateUtils.GetString(spanContext.Tracestate);
|
||||
if (tracestateStr.Length > 0)
|
||||
{
|
||||
setter(carrier, "tracestate", tracestateStr);
|
||||
setter(carrier, TraceState, tracestateStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@ namespace OpenTelemetry.Context
|
|||
{
|
||||
private static readonly List<DistributedContextEntry> EmptyList = new List<DistributedContextEntry>();
|
||||
private static DistributedContextCarrier carrier = NoopDistributedContextCarrier.Instance;
|
||||
private readonly IEnumerable<DistributedContextEntry> entries;
|
||||
private readonly List<DistributedContextEntry> entries;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DistributedContext"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="entries">Entries for distributed context.</param>
|
||||
internal DistributedContext(IEnumerable<DistributedContextEntry> entries)
|
||||
internal DistributedContext(List<DistributedContextEntry> entries)
|
||||
{
|
||||
this.entries = entries;
|
||||
}
|
||||
|
|
@ -89,20 +89,7 @@ namespace OpenTelemetry.Context
|
|||
/// <inheritdoc/>
|
||||
public bool Equals(DistributedContext other)
|
||||
{
|
||||
if (this.entries.Count() != other.entries.Count())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (DistributedContextEntry entry in this.entries)
|
||||
{
|
||||
if (other.GetEntryValue(entry.Key) != entry.Value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return this.entries.Count == other.entries.Count && this.entries.All(entry => other.GetEntryValue(entry.Key) == entry.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,12 +14,7 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization;
|
||||
using OpenTelemetry.Internal;
|
||||
|
||||
namespace OpenTelemetry.Context
|
||||
{
|
||||
|
|
@ -156,7 +151,7 @@ namespace OpenTelemetry.Context
|
|||
return this;
|
||||
}
|
||||
|
||||
foreach (DistributedContextEntry entry in entries)
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
this.Add(entry);
|
||||
}
|
||||
|
|
@ -176,7 +171,7 @@ namespace OpenTelemetry.Context
|
|||
return this;
|
||||
}
|
||||
|
||||
int index = this.entries.FindIndex((DistributedContextEntry entry) => entry.Key == key);
|
||||
int index = this.entries.FindIndex(entry => entry.Key == key);
|
||||
if (index >= 0)
|
||||
{
|
||||
this.entries.RemoveAt(index);
|
||||
|
|
@ -196,7 +191,7 @@ namespace OpenTelemetry.Context
|
|||
return DistributedContext.Empty;
|
||||
}
|
||||
|
||||
DistributedContext context = new DistributedContext(this.entries);
|
||||
var context = new DistributedContext(this.entries);
|
||||
this.entries = null; // empty current builder entries.
|
||||
return context;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,27 +96,13 @@ namespace OpenTelemetry.Context
|
|||
/// <inheritdoc/>
|
||||
public override bool Equals(object o)
|
||||
{
|
||||
if (o is DistributedContextEntry that)
|
||||
{
|
||||
return this.Key == that.Key && this.Value == that.Value;
|
||||
}
|
||||
|
||||
return false;
|
||||
return o is DistributedContextEntry that && (this.Key == that.Key && this.Value == that.Value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
if (this.Key is null)
|
||||
{
|
||||
return "{}";
|
||||
}
|
||||
|
||||
return nameof(DistributedContextEntry)
|
||||
+ "{"
|
||||
+ nameof(this.Key) + "=" + this.Key + ", "
|
||||
+ nameof(this.Value) + "=" + this.Value
|
||||
+ "}";
|
||||
return this.Key is null ? "{}" : $"{nameof(DistributedContextEntry)}{{{nameof(this.Key)}={this.Key}, {nameof(this.Value)}={this.Value}}}";
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
|
@ -21,17 +22,20 @@ namespace OpenTelemetry.Context.Test
|
|||
{
|
||||
public class DistributedContextBuilderTest
|
||||
{
|
||||
private static readonly string KEY_1 = "key 1";
|
||||
private static readonly string KEY_2 = "key 2";
|
||||
private const string KEY_1 = "key 1";
|
||||
private const string KEY_2 = "key 2";
|
||||
|
||||
private static readonly string VALUE_1 = "value 1";
|
||||
private static readonly string VALUE_2 = "value 2";
|
||||
private const string VALUE_1 = "value 1";
|
||||
private const string VALUE_2 = "value 2";
|
||||
|
||||
private static readonly List<DistributedContextEntry> list1 = new List<DistributedContextEntry>(1) { new DistributedContextEntry(KEY_1, VALUE_1) };
|
||||
private static readonly List<DistributedContextEntry> list2 = new List<DistributedContextEntry>(2) {
|
||||
new DistributedContextEntry(KEY_1, VALUE_1),
|
||||
new DistributedContextEntry(KEY_2, VALUE_2),
|
||||
};
|
||||
private static readonly List<DistributedContextEntry> List1 = new List<DistributedContextEntry>(1)
|
||||
{new DistributedContextEntry(KEY_1, VALUE_1)};
|
||||
|
||||
private static readonly List<DistributedContextEntry> List2 = new List<DistributedContextEntry>(2)
|
||||
{
|
||||
new DistributedContextEntry(KEY_1, VALUE_1),
|
||||
new DistributedContextEntry(KEY_2, VALUE_2),
|
||||
};
|
||||
|
||||
public DistributedContextBuilderTest()
|
||||
{
|
||||
|
|
@ -48,7 +52,7 @@ namespace OpenTelemetry.Context.Test
|
|||
Assert.Equal(DistributedContext.Empty, dc);
|
||||
|
||||
dc = DistributedContextBuilder.CreateContext(KEY_1, VALUE_1);
|
||||
Assert.Equal(DistributedContextBuilder.CreateContext(list1), dc);
|
||||
Assert.Equal(DistributedContextBuilder.CreateContext(List1), dc);
|
||||
|
||||
Assert.Equal(dc, new DistributedContextBuilder(dc).Build());
|
||||
}
|
||||
|
|
@ -57,60 +61,77 @@ namespace OpenTelemetry.Context.Test
|
|||
public void AddEntries()
|
||||
{
|
||||
Assert.Equal(DistributedContext.Empty, new DistributedContextBuilder(inheritCurrentContext: false).Build());
|
||||
Assert.Equal(DistributedContextBuilder.CreateContext(list1), new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(KEY_1, VALUE_1)
|
||||
.Build());
|
||||
|
||||
Assert.Equal(DistributedContextBuilder.CreateContext(list1), new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(new DistributedContextEntry(KEY_1, VALUE_1))
|
||||
.Build());
|
||||
Assert.Equal(
|
||||
DistributedContextBuilder.CreateContext(List1), new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(KEY_1, VALUE_1)
|
||||
.Build()
|
||||
);
|
||||
|
||||
Assert.Equal(DistributedContextBuilder.CreateContext(list2), new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(KEY_1, VALUE_1)
|
||||
.Add(KEY_2, VALUE_2)
|
||||
.Build());
|
||||
Assert.Equal(
|
||||
DistributedContextBuilder.CreateContext(List1), new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(new DistributedContextEntry(KEY_1, VALUE_1))
|
||||
.Build()
|
||||
);
|
||||
|
||||
Assert.Equal(DistributedContextBuilder.CreateContext(list2), new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(new DistributedContextEntry(KEY_1, VALUE_1))
|
||||
.Add(new DistributedContextEntry(KEY_2, VALUE_2))
|
||||
.Build());
|
||||
Assert.Equal(
|
||||
DistributedContextBuilder.CreateContext(List2), new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(KEY_1, VALUE_1)
|
||||
.Add(KEY_2, VALUE_2)
|
||||
.Build()
|
||||
);
|
||||
|
||||
Assert.Equal(DistributedContextBuilder.CreateContext(list1), new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(list1)
|
||||
.Build());
|
||||
Assert.Equal(
|
||||
DistributedContextBuilder.CreateContext(List2), new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(new DistributedContextEntry(KEY_1, VALUE_1))
|
||||
.Add(new DistributedContextEntry(KEY_2, VALUE_2))
|
||||
.Build()
|
||||
);
|
||||
|
||||
Assert.Equal(DistributedContextBuilder.CreateContext(list2), new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(list2)
|
||||
.Build());
|
||||
Assert.Equal(
|
||||
DistributedContextBuilder.CreateContext(List1), new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(List1)
|
||||
.Build()
|
||||
);
|
||||
|
||||
Assert.Equal(
|
||||
DistributedContextBuilder.CreateContext(List2), new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(List2)
|
||||
.Build()
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveEntries()
|
||||
{
|
||||
Assert.Equal(DistributedContextBuilder.CreateContext(list1), new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(list2)
|
||||
.Remove(KEY_2)
|
||||
.Build());
|
||||
Assert.Equal(
|
||||
DistributedContextBuilder.CreateContext(List1), new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(List2)
|
||||
.Remove(KEY_2)
|
||||
.Build()
|
||||
);
|
||||
|
||||
Assert.Equal(DistributedContext.Empty, new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(list2)
|
||||
.Remove(KEY_2)
|
||||
.Remove(KEY_1)
|
||||
.Build());
|
||||
Assert.Equal(
|
||||
DistributedContext.Empty, new DistributedContextBuilder(inheritCurrentContext: false)
|
||||
.Add(List2)
|
||||
.Remove(KEY_2)
|
||||
.Remove(KEY_1)
|
||||
.Build()
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsureEmptyListAfterBuild()
|
||||
{
|
||||
DistributedContextBuilder dcb = new DistributedContextBuilder(inheritCurrentContext: false);
|
||||
var dcb = new DistributedContextBuilder(inheritCurrentContext: false);
|
||||
Assert.Equal(DistributedContext.Empty, dcb.Build());
|
||||
|
||||
dcb.Add(list2);
|
||||
Assert.Equal(DistributedContextBuilder.CreateContext(list2), dcb.Build());
|
||||
dcb.Add(List2);
|
||||
Assert.Equal(DistributedContextBuilder.CreateContext(List2), dcb.Build());
|
||||
Assert.Equal(DistributedContext.Empty, dcb.Build());
|
||||
|
||||
DistributedContext dc = dcb.Add(list1).Build();
|
||||
Assert.Equal(dc, dcb.Add(list1).Build());
|
||||
var dc = dcb.Add(List1).Build();
|
||||
Assert.Equal(dc, dcb.Add(List1).Build());
|
||||
|
||||
dcb = new DistributedContextBuilder(dc);
|
||||
Assert.Equal(dc, dcb.Build());
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ namespace OpenTelemetry.Context.Test
|
|||
{
|
||||
public class DistributedContextTest
|
||||
{
|
||||
private static readonly string K1 = "k1";
|
||||
private static readonly string K2 = "k2";
|
||||
private const string K1 = "k1";
|
||||
private const string K2 = "k2";
|
||||
|
||||
private static readonly string V1 = "v1";
|
||||
private static readonly string V2 = "v2";
|
||||
private const string V1 = "v1";
|
||||
private const string V2 = "v2";
|
||||
|
||||
public DistributedContextTest()
|
||||
{
|
||||
|
|
@ -35,7 +35,7 @@ namespace OpenTelemetry.Context.Test
|
|||
[Fact]
|
||||
public void EmptyContext()
|
||||
{
|
||||
DistributedContext dc = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>());
|
||||
var dc = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>());
|
||||
Assert.Empty(dc.Entries);
|
||||
Assert.Equal(DistributedContext.Empty, dc);
|
||||
}
|
||||
|
|
@ -43,28 +43,28 @@ namespace OpenTelemetry.Context.Test
|
|||
[Fact]
|
||||
public void NonEmptyContext()
|
||||
{
|
||||
List<DistributedContextEntry> list = new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K2, V2) };
|
||||
DistributedContext dc = DistributedContextBuilder.CreateContext(list);
|
||||
var list = new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K2, V2) };
|
||||
var dc = DistributedContextBuilder.CreateContext(list);
|
||||
Assert.Equal(list, dc.Entries);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddExtraKey()
|
||||
{
|
||||
List<DistributedContextEntry> list = new List<DistributedContextEntry>(1) { new DistributedContextEntry(K1, V1)};
|
||||
DistributedContext dc = DistributedContextBuilder.CreateContext(list);
|
||||
var list = new List<DistributedContextEntry>(1) { new DistributedContextEntry(K1, V1)};
|
||||
var dc = DistributedContextBuilder.CreateContext(list);
|
||||
Assert.Equal(list, dc.Entries);
|
||||
|
||||
list.Add(new DistributedContextEntry(K2, V2));
|
||||
DistributedContext dc1 = DistributedContextBuilder.CreateContext(list);
|
||||
var dc1 = DistributedContextBuilder.CreateContext(list);
|
||||
Assert.Equal(list, dc1.Entries);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddExistingKey()
|
||||
{
|
||||
List<DistributedContextEntry> list = new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K1, V2) };
|
||||
DistributedContext dc = DistributedContextBuilder.CreateContext(list);
|
||||
var list = new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K1, V2) };
|
||||
var dc = DistributedContextBuilder.CreateContext(list);
|
||||
Assert.Equal(new List<DistributedContextEntry>(1) { new DistributedContextEntry(K1, V2) }, dc.Entries);
|
||||
}
|
||||
|
||||
|
|
@ -78,8 +78,8 @@ namespace OpenTelemetry.Context.Test
|
|||
[Fact]
|
||||
public void RemoveExistingKey()
|
||||
{
|
||||
List<DistributedContextEntry> list = new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K2, V2) };
|
||||
DistributedContext dc = DistributedContextBuilder.CreateContext(list);
|
||||
var list = new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K2, V2) };
|
||||
var dc = DistributedContextBuilder.CreateContext(list);
|
||||
Assert.Equal(list, dc.Entries);
|
||||
|
||||
list.RemoveAt(0);
|
||||
|
|
@ -95,8 +95,8 @@ namespace OpenTelemetry.Context.Test
|
|||
[Fact]
|
||||
public void TestIterator()
|
||||
{
|
||||
List<DistributedContextEntry> list = new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K2, V2) };
|
||||
DistributedContext dc = DistributedContextBuilder.CreateContext(list);
|
||||
var list = new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K2, V2) };
|
||||
var dc = DistributedContextBuilder.CreateContext(list);
|
||||
|
||||
var i = dc.Entries.GetEnumerator();
|
||||
Assert.True(i.MoveNext());
|
||||
|
|
@ -104,17 +104,17 @@ namespace OpenTelemetry.Context.Test
|
|||
Assert.True(i.MoveNext());
|
||||
var tag2 = i.Current;
|
||||
Assert.False(i.MoveNext());
|
||||
Assert.Equal(new List<DistributedContextEntry>() { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K2, V2)}, new List<DistributedContextEntry>() { tag1, tag2 });
|
||||
Assert.Equal(new List<DistributedContextEntry> { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K2, V2)}, new List<DistributedContextEntry> { tag1, tag2 });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestEquals()
|
||||
{
|
||||
DistributedContext dc1 = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K2, V2) });
|
||||
DistributedContext dc2 = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K2, V2) });
|
||||
DistributedContext dc3 = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(2) { new DistributedContextEntry(K2, V2), new DistributedContextEntry(K1, V1) });
|
||||
DistributedContext dc4 = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K2, V1) });
|
||||
DistributedContext dc5 = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V2), new DistributedContextEntry(K2, V1) });
|
||||
var dc1 = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K2, V2) });
|
||||
var dc2 = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K2, V2) });
|
||||
var dc3 = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(2) { new DistributedContextEntry(K2, V2), new DistributedContextEntry(K1, V1) });
|
||||
var dc4 = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V1), new DistributedContextEntry(K2, V1) });
|
||||
var dc5 = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(2) { new DistributedContextEntry(K1, V2), new DistributedContextEntry(K2, V1) });
|
||||
|
||||
Assert.True(dc1.Equals(dc2));
|
||||
Assert.True(dc1.Equals(dc3));
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ namespace OpenTelemetry.Context.Test
|
|||
{
|
||||
public class DistributedContextsScopeTest
|
||||
{
|
||||
private static readonly string KEY_1 = "key 1";
|
||||
private static readonly string KEY_2 = "key 2";
|
||||
private const string KEY_1 = "key 1";
|
||||
private const string KEY_2 = "key 2";
|
||||
|
||||
private static readonly string VALUE_1 = "value 1";
|
||||
private static readonly string VALUE_2 = "value 2";
|
||||
private const string VALUE_1 = "value 1";
|
||||
private const string VALUE_2 = "value 2";
|
||||
|
||||
[Fact]
|
||||
public void NoopContextCarrier()
|
||||
|
|
@ -85,8 +85,8 @@ namespace OpenTelemetry.Context.Test
|
|||
public async void TestContextInheritance()
|
||||
{
|
||||
DistributedContext.Carrier = AsyncLocalDistributedContextCarrier.Instance;
|
||||
List<DistributedContextEntry> list1 = new List<DistributedContextEntry>(1) { new DistributedContextEntry(KEY_1, VALUE_1)};
|
||||
List<DistributedContextEntry> list2 = new List<DistributedContextEntry>(2) { new DistributedContextEntry(KEY_1, VALUE_1), new DistributedContextEntry(KEY_2, VALUE_2), };
|
||||
var list1 = new List<DistributedContextEntry>(1) { new DistributedContextEntry(KEY_1, VALUE_1)};
|
||||
var list2 = new List<DistributedContextEntry>(2) { new DistributedContextEntry(KEY_1, VALUE_1), new DistributedContextEntry(KEY_2, VALUE_2), };
|
||||
|
||||
DistributedContext.SetCurrent(DistributedContext.Empty);
|
||||
await Task.Run(() => Assert.Equal(DistributedContext.Empty, DistributedContext.Current));
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenTelemetry.Internal;
|
||||
using Xunit;
|
||||
|
|
@ -45,10 +45,10 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
[Fact]
|
||||
public void TestNoTagsSerialization()
|
||||
{
|
||||
DistributedContext dc = serializer.FromByteArray(serializer.ToByteArray(DistributedContext.Empty));
|
||||
var dc = serializer.FromByteArray(serializer.ToByteArray(DistributedContext.Empty));
|
||||
Assert.Empty(dc.Entries);
|
||||
|
||||
dc = serializer.FromByteArray(new byte[] { SerializationUtils.VersionId }); // One byte that represents Version ID.
|
||||
|
||||
dc = serializer.FromByteArray(new byte[] {SerializationUtils.VersionId}); // One byte that represents Version ID.
|
||||
Assert.Empty(dc.Entries);
|
||||
}
|
||||
|
||||
|
|
@ -63,33 +63,19 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var output = new MemoryStream();
|
||||
output.WriteByte(SerializationUtils.VersionId);
|
||||
for (var i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8 - 1; i++) {
|
||||
|
||||
for (var i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8 - 1; i++)
|
||||
{
|
||||
// Each tag will be with format {key : "0123", value : "0123"}, so the length of it is 8.
|
||||
String str;
|
||||
if (i < 10)
|
||||
{
|
||||
str = "000" + i;
|
||||
}
|
||||
else if (i < 100)
|
||||
{
|
||||
str = "00" + i;
|
||||
}
|
||||
else if (i < 1000)
|
||||
{
|
||||
str = "0" + i;
|
||||
}
|
||||
else
|
||||
{
|
||||
str = i.ToString();
|
||||
}
|
||||
string str = i.ToString("0000");
|
||||
EncodeTagToOutPut(str, str, output);
|
||||
}
|
||||
|
||||
// The last tag will be of size 9, so the total size of the TagContext (8193) will be one byte
|
||||
// more than limit.
|
||||
EncodeTagToOutPut("last", "last1", output);
|
||||
|
||||
var bytes = output.ToArray();
|
||||
|
||||
Assert.Equal(DistributedContext.Empty, serializer.FromByteArray(bytes));
|
||||
}
|
||||
|
||||
|
|
@ -100,33 +86,18 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var output = new MemoryStream();
|
||||
output.WriteByte(SerializationUtils.VersionId);
|
||||
for (var i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8 - 1; i++) {
|
||||
|
||||
for (var i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8 - 1; i++)
|
||||
{
|
||||
// Each tag will be with format {key : "key_", value : "0123"}, so the length of it is 8.
|
||||
String str;
|
||||
if (i < 10)
|
||||
{
|
||||
str = "000" + i;
|
||||
}
|
||||
else if (i < 100)
|
||||
{
|
||||
str = "00" + i;
|
||||
}
|
||||
else if (i < 1000)
|
||||
{
|
||||
str = "0" + i;
|
||||
}
|
||||
else
|
||||
{
|
||||
str = i.ToString();
|
||||
}
|
||||
EncodeTagToOutPut("key_", str, output);
|
||||
EncodeTagToOutPut("key_", i.ToString("0000"), output);
|
||||
}
|
||||
|
||||
// The last tag will be of size 9, so the total size of the TagContext (8193) will be one byte
|
||||
// more than limit.
|
||||
EncodeTagToOutPut("key_", "last1", output);
|
||||
|
||||
var bytes = output.ToArray();
|
||||
|
||||
Assert.Equal(DistributedContext.Empty, serializer.FromByteArray(bytes));
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +107,8 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
var output = new MemoryStream();
|
||||
output.WriteByte(SerializationUtils.VersionId);
|
||||
EncodeTagToOutPut("Key", "Value", output);
|
||||
DistributedContext expected = DistributedContextBuilder.CreateContext("Key", "Value");
|
||||
|
||||
var expected = DistributedContextBuilder.CreateContext("Key", "Value");
|
||||
Assert.Equal(expected, serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
|
|
@ -147,7 +119,10 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
output.WriteByte(SerializationUtils.VersionId);
|
||||
EncodeTagToOutPut("Key1", "Value1", output);
|
||||
EncodeTagToOutPut("Key2", "Value2", output);
|
||||
DistributedContext expected = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(2) { new DistributedContextEntry("Key1", "Value1"), new DistributedContextEntry("Key2", "Value2") });
|
||||
|
||||
var expected = DistributedContextBuilder.CreateContext(
|
||||
new List<DistributedContextEntry>(2) {new DistributedContextEntry("Key1", "Value1"), new DistributedContextEntry("Key2", "Value2")}
|
||||
);
|
||||
Assert.Equal(expected, serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
|
|
@ -158,7 +133,8 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
output.WriteByte(SerializationUtils.VersionId);
|
||||
EncodeTagToOutPut("Key1", "Value1", output);
|
||||
EncodeTagToOutPut("Key1", "Value2", output);
|
||||
DistributedContext expected = DistributedContextBuilder.CreateContext("Key1", "Value2");
|
||||
|
||||
var expected = DistributedContextBuilder.CreateContext("Key1", "Value2");
|
||||
Assert.Equal(expected, serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
|
|
@ -173,11 +149,14 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
EncodeTagToOutPut("Key1", "Value4", output);
|
||||
EncodeTagToOutPut("Key2", "Value5", output);
|
||||
|
||||
DistributedContext expected = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(3) {
|
||||
new DistributedContextEntry("Key1", "Value4"),
|
||||
new DistributedContextEntry("Key2", "Value5"),
|
||||
new DistributedContextEntry("Key3", "Value3"),
|
||||
});
|
||||
var expected = DistributedContextBuilder.CreateContext(
|
||||
new List<DistributedContextEntry>(3)
|
||||
{
|
||||
new DistributedContextEntry("Key1", "Value4"),
|
||||
new DistributedContextEntry("Key2", "Value5"),
|
||||
new DistributedContextEntry("Key3", "Value3"),
|
||||
}
|
||||
);
|
||||
Assert.Equal(expected, serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
|
|
@ -188,7 +167,8 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
output.WriteByte(SerializationUtils.VersionId);
|
||||
EncodeTagToOutPut("Key1", "Value1", output);
|
||||
EncodeTagToOutPut("Key1", "Value2", output);
|
||||
DistributedContext expected = DistributedContextBuilder.CreateContext("Key1", "Value2");
|
||||
|
||||
var expected = DistributedContextBuilder.CreateContext("Key1", "Value2");
|
||||
Assert.Equal(expected, serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
|
|
@ -203,12 +183,14 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
EncodeTagToOutPut("Key1", "Value1", output);
|
||||
EncodeTagToOutPut("Key2", "Value2", output);
|
||||
|
||||
DistributedContext expected = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(3) {
|
||||
new DistributedContextEntry("Key1", "Value1"),
|
||||
new DistributedContextEntry("Key2", "Value2"),
|
||||
new DistributedContextEntry("Key3", "Value3"),
|
||||
});
|
||||
|
||||
var expected = DistributedContextBuilder.CreateContext(
|
||||
new List<DistributedContextEntry>(3)
|
||||
{
|
||||
new DistributedContextEntry("Key1", "Value1"),
|
||||
new DistributedContextEntry("Key2", "Value2"),
|
||||
new DistributedContextEntry("Key3", "Value3"),
|
||||
}
|
||||
);
|
||||
Assert.Equal(expected, serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
|
|
@ -222,15 +204,17 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
|
||||
// Write unknown field ID 1.
|
||||
output.WriteByte(1);
|
||||
output.Write(new byte[] { 1, 2, 3, 4 }, 0, 4);
|
||||
output.Write(new byte[] {1, 2, 3, 4}, 0, 4);
|
||||
|
||||
EncodeTagToOutPut("Key3", "Value3", output);
|
||||
|
||||
DistributedContext expected = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(2) {
|
||||
new DistributedContextEntry("Key1", "Value1"),
|
||||
new DistributedContextEntry("Key2", "Value2"),
|
||||
});
|
||||
|
||||
var expected = DistributedContextBuilder.CreateContext(
|
||||
new List<DistributedContextEntry>(2)
|
||||
{
|
||||
new DistributedContextEntry("Key1", "Value1"),
|
||||
new DistributedContextEntry("Key2", "Value2"),
|
||||
}
|
||||
);
|
||||
Assert.Equal(expected, serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +226,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
|
||||
// Write unknown field ID 1.
|
||||
output.WriteByte(1);
|
||||
output.Write(new byte[] { 1, 2, 3, 4 }, 0, 4);
|
||||
output.Write(new byte[] {1, 2, 3, 4}, 0, 4);
|
||||
|
||||
EncodeTagToOutPut("Key", "Value", output);
|
||||
Assert.Equal(DistributedContext.Empty, serializer.FromByteArray(output.ToArray()));
|
||||
|
|
@ -258,14 +242,13 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
[Fact]
|
||||
public void TestDeserializeWrongVersionId()
|
||||
{
|
||||
|
||||
Assert.Equal(DistributedContext.Empty, serializer.FromByteArray(new byte[] { SerializationUtils.VersionId + 1 }));
|
||||
Assert.Equal(DistributedContext.Empty, serializer.FromByteArray(new byte[] {SerializationUtils.VersionId + 1}));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDeserializeNegativeVersionId()
|
||||
{
|
||||
Assert.Equal(DistributedContext.Empty, serializer.FromByteArray(new byte[] { 0xff }));
|
||||
Assert.Equal(DistributedContext.Empty, serializer.FromByteArray(new byte[] {0xff}));
|
||||
}
|
||||
|
||||
// <tag_encoding> ==
|
||||
|
|
@ -287,7 +270,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
var bytes = new byte[VarInt.VarIntSize(length)];
|
||||
VarInt.PutVarInt(length, bytes, 0);
|
||||
output.Write(bytes, 0, bytes.Length);
|
||||
var inPutBytes = Encoding.UTF8.GetBytes(input);
|
||||
var inPutBytes= Encoding.UTF8.GetBytes(input);
|
||||
output.Write(inPutBytes, 0, inPutBytes.Length);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
using System;
|
||||
|
||||
using Xunit;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
|
@ -21,76 +21,62 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
public class DistributedContextRoundtripTest
|
||||
{
|
||||
private const string K1 = "k1";
|
||||
private const string K2 = "k2";
|
||||
private const string K3 = "k3";
|
||||
|
||||
private static readonly string K1 = "k1";
|
||||
private static readonly string K2 = "k2";
|
||||
private static readonly string K3 = "k3";
|
||||
|
||||
private static readonly string V_EMPTY = "";
|
||||
private static readonly string V1 = "v1";
|
||||
private static readonly string V2 = "v2";
|
||||
private static readonly string V3 = "v3";
|
||||
private const string V_EMPTY = "";
|
||||
private const string V1 = "v1";
|
||||
private const string V2 = "v2";
|
||||
private const string V3 = "v3";
|
||||
|
||||
private readonly DistributedContextBinarySerializer serializer;
|
||||
|
||||
public DistributedContextRoundtripTest()
|
||||
{
|
||||
DistributedContext.Carrier = AsyncLocalDistributedContextCarrier.Instance;
|
||||
serializer = new DistributedContextBinarySerializer();
|
||||
this.serializer = new DistributedContextBinarySerializer();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestRoundtripSerialization_NormalTagContext()
|
||||
{
|
||||
TestRoundtripSerialization(DistributedContext.Empty);
|
||||
TestRoundtripSerialization(DistributedContextBuilder.CreateContext(K1, V1));
|
||||
this.TestRoundtripSerialization(DistributedContext.Empty);
|
||||
this.TestRoundtripSerialization(DistributedContextBuilder.CreateContext(K1, V1));
|
||||
|
||||
DistributedContext expected = DistributedContextBuilder.CreateContext(new List<DistributedContextEntry>(3) {
|
||||
new DistributedContextEntry(K1, V1),
|
||||
new DistributedContextEntry(K2, V2),
|
||||
new DistributedContextEntry(K3, V3),
|
||||
});
|
||||
TestRoundtripSerialization(expected);
|
||||
var expected = DistributedContextBuilder.CreateContext(
|
||||
new List<DistributedContextEntry>(3)
|
||||
{
|
||||
new DistributedContextEntry(K1, V1),
|
||||
new DistributedContextEntry(K2, V2),
|
||||
new DistributedContextEntry(K3, V3),
|
||||
}
|
||||
);
|
||||
this.TestRoundtripSerialization(expected);
|
||||
|
||||
TestRoundtripSerialization(DistributedContextBuilder.CreateContext(K1, V_EMPTY));
|
||||
this.TestRoundtripSerialization(DistributedContextBuilder.CreateContext(K1, V_EMPTY));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestRoundtrip_TagContextWithMaximumSize()
|
||||
{
|
||||
List<DistributedContextEntry> list = new List<DistributedContextEntry>();
|
||||
var list = new List<DistributedContextEntry>();
|
||||
|
||||
for (var i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8; i++)
|
||||
{
|
||||
// Each tag will be with format {key : "0123", value : "0123"}, so the length of it is 8.
|
||||
// Add 1024 tags, the total size should just be 8192.
|
||||
String str;
|
||||
if (i < 10)
|
||||
{
|
||||
str = "000" + i;
|
||||
}
|
||||
else if (i < 100)
|
||||
{
|
||||
str = "00" + i;
|
||||
}
|
||||
else if (i < 1000)
|
||||
{
|
||||
str = "0" + i;
|
||||
}
|
||||
else
|
||||
{
|
||||
str = "" + i;
|
||||
}
|
||||
|
||||
var str = i.ToString("0000");
|
||||
list.Add(new DistributedContextEntry(str, str));
|
||||
}
|
||||
|
||||
TestRoundtripSerialization(DistributedContextBuilder.CreateContext(list));
|
||||
this.TestRoundtripSerialization(DistributedContextBuilder.CreateContext(list));
|
||||
}
|
||||
|
||||
private void TestRoundtripSerialization(DistributedContext expected)
|
||||
{
|
||||
var bytes = serializer.ToByteArray(expected);
|
||||
var actual = serializer.FromByteArray(bytes);
|
||||
var bytes= this.serializer.ToByteArray(expected);
|
||||
var actual = this.serializer.FromByteArray(bytes);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -26,15 +27,15 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
public class DistributedContextSerializationTest
|
||||
{
|
||||
private static readonly string K1 = "k1";
|
||||
private static readonly string K2 = "k2";
|
||||
private static readonly string K3 = "k3";
|
||||
private static readonly string K4 = "k4";
|
||||
private const string K1 = "k1";
|
||||
private const string K2 = "k2";
|
||||
private const string K3 = "k3";
|
||||
private const string K4 = "k4";
|
||||
|
||||
private static readonly string V1 = "v1";
|
||||
private static readonly string V2 = "v2";
|
||||
private static readonly string V3 = "v3";
|
||||
private static readonly string V4 = "v4";
|
||||
private const string V1 = "v1";
|
||||
private const string V2 = "v2";
|
||||
private const string V3 = "v3";
|
||||
private const string V4 = "v4";
|
||||
|
||||
private static readonly DistributedContextEntry T1 = new DistributedContextEntry(K1, V1);
|
||||
private static readonly DistributedContextEntry T2 = new DistributedContextEntry(K2, V2);
|
||||
|
|
@ -70,81 +71,68 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
[Fact]
|
||||
public void TestSerializeTooLargeTagContext()
|
||||
{
|
||||
List<DistributedContextEntry> list = new List<DistributedContextEntry>();
|
||||
var list = new List<DistributedContextEntry>();
|
||||
|
||||
for (var i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8 - 1; i++) {
|
||||
for (var i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8 - 1; i++)
|
||||
{
|
||||
// Each tag will be with format {key : "0123", value : "0123"}, so the length of it is 8.
|
||||
String str;
|
||||
if (i < 10)
|
||||
{
|
||||
str = "000" + i;
|
||||
}
|
||||
else if (i < 100)
|
||||
{
|
||||
str = "00" + i;
|
||||
}
|
||||
else if (i < 1000)
|
||||
{
|
||||
str = "0" + i;
|
||||
}
|
||||
else
|
||||
{
|
||||
str = i.ToString();
|
||||
}
|
||||
var str = i.ToString("0000");
|
||||
list.Add(new DistributedContextEntry(str, str));
|
||||
}
|
||||
|
||||
// The last tag will be of size 9, so the total size of the TagContext (8193) will be one byte
|
||||
// more than limit.
|
||||
list.Add(new DistributedContextEntry("last", "last1"));
|
||||
|
||||
DistributedContext dc = DistributedContextBuilder.CreateContext(list);
|
||||
|
||||
var dc = DistributedContextBuilder.CreateContext(list);
|
||||
Assert.Empty(serializer.ToByteArray(dc));
|
||||
}
|
||||
|
||||
private void TestSerialize(params DistributedContextEntry[] tags)
|
||||
{
|
||||
List<DistributedContextEntry> list = new List<DistributedContextEntry>();
|
||||
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
list.Add(tag);
|
||||
}
|
||||
var list = new List<DistributedContextEntry>(tags);
|
||||
|
||||
var actual = serializer.ToByteArray(DistributedContextBuilder.CreateContext(list));
|
||||
var tagsList = tags.ToList();
|
||||
var tagPermutation = Permutate(tagsList, tagsList.Count);
|
||||
ISet<String> possibleOutPuts = new HashSet<String>();
|
||||
foreach (List<DistributedContextEntry> l in tagPermutation) {
|
||||
var tagPermutation= Permutate(tagsList, tagsList.Count);
|
||||
ISet<string> possibleOutPuts = new HashSet<string>();
|
||||
|
||||
foreach (var distributedContextEntries in tagPermutation)
|
||||
{
|
||||
var l = (List<DistributedContextEntry>) distributedContextEntries;
|
||||
var expected = new MemoryStream();
|
||||
expected.WriteByte(SerializationUtils.VersionId);
|
||||
foreach (var tag in l) {
|
||||
|
||||
foreach (var tag in l)
|
||||
{
|
||||
expected.WriteByte(SerializationUtils.TagFieldId);
|
||||
EncodeString(tag.Key, expected);
|
||||
EncodeString(tag.Value, expected);
|
||||
}
|
||||
|
||||
var bytes = expected.ToArray();
|
||||
possibleOutPuts.Add(Encoding.UTF8.GetString(bytes));
|
||||
}
|
||||
|
||||
var exp = Encoding.UTF8.GetString(actual);
|
||||
Assert.Contains(exp, possibleOutPuts);
|
||||
}
|
||||
|
||||
private static void EncodeString(String input, MemoryStream byteArrayOutPutStream)
|
||||
private static void EncodeString(string input, MemoryStream byteArrayOutPutStream)
|
||||
{
|
||||
VarInt.PutVarInt(input.Length, byteArrayOutPutStream);
|
||||
var inpBytes = Encoding.UTF8.GetBytes(input);
|
||||
byteArrayOutPutStream.Write(inpBytes, 0, inpBytes.Length);
|
||||
}
|
||||
|
||||
internal static void RotateRight(IList<DistributedContextEntry> sequence, int count)
|
||||
private static void RotateRight(IList<DistributedContextEntry> sequence, int count)
|
||||
{
|
||||
var tmp = sequence[count - 1];
|
||||
sequence.RemoveAt(count - 1);
|
||||
sequence.Insert(0, tmp);
|
||||
}
|
||||
|
||||
internal static IEnumerable<IList<DistributedContextEntry>> Permutate(IList<DistributedContextEntry> sequence, int count)
|
||||
private static IEnumerable<IList<DistributedContextEntry>> Permutate(IList<DistributedContextEntry> sequence, int count)
|
||||
{
|
||||
if (count == 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace OpenTelemetry.Tests
|
|||
{
|
||||
var expectedKeyValuePairs = expectedAttributes as KeyValuePair<string, object>[] ?? expectedAttributes.ToArray();
|
||||
var actualKeyValuePairs = attributes as KeyValuePair<string, object>[] ?? attributes.ToArray();
|
||||
Assert.Equal(actualKeyValuePairs.Count(), expectedKeyValuePairs.Count());
|
||||
Assert.Equal(actualKeyValuePairs.Length, expectedKeyValuePairs.Length);
|
||||
|
||||
foreach (var attr in actualKeyValuePairs)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,34 +24,35 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
public class B3FormatTest
|
||||
{
|
||||
private static readonly string TraceIdBase16 = "ff000000000000000000000000000041";
|
||||
private const string TraceIdBase16 = "ff000000000000000000000000000041";
|
||||
private static readonly ActivityTraceId TraceId = ActivityTraceId.CreateFromString(TraceIdBase16.AsSpan());
|
||||
private static readonly string TraceIdBase16EightBytes = "0000000000000041";
|
||||
private const string TraceIdBase16EightBytes = "0000000000000041";
|
||||
private static readonly ActivityTraceId TraceIdEightBytes = ActivityTraceId.CreateFromString(("0000000000000000" + TraceIdBase16EightBytes).AsSpan());
|
||||
private static readonly string SpanIdBase16 = "ff00000000000041";
|
||||
private const string SpanIdBase16 = "ff00000000000041";
|
||||
private static readonly ActivitySpanId SpanId = ActivitySpanId.CreateFromString(SpanIdBase16.AsSpan());
|
||||
|
||||
private static readonly ActivityTraceFlags TraceOptions = ActivityTraceFlags.Recorded;
|
||||
private const string InvalidId = "abcdefghijklmnop";
|
||||
private const string InvalidSizeId = "0123456789abcdef00";
|
||||
|
||||
private const ActivityTraceFlags TraceOptions = ActivityTraceFlags.Recorded;
|
||||
private readonly B3Format b3Format = new B3Format();
|
||||
private readonly B3Format b3FormatSingleHeader = new B3Format(true);
|
||||
|
||||
|
||||
private static readonly Action<IDictionary<string, string>, string, string> setter = (d, k, v) => d[k] = v;
|
||||
private static readonly Func<IDictionary<string, string>, string, IEnumerable<string>> getter = (d, k) => { d.TryGetValue(k, out var v); return new string[] { v }; };
|
||||
readonly ITestOutputHelper _output;
|
||||
private static readonly Action<IDictionary<string, string>, string, string> Setter = (d, k, v) => d[k] = v;
|
||||
private static readonly Func<IDictionary<string, string>, string, IEnumerable<string>> Getter = (d, k) => { d.TryGetValue(k, out var v); return new string[] { v }; };
|
||||
private readonly ITestOutputHelper output;
|
||||
|
||||
public B3FormatTest(ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_SampledContext()
|
||||
{
|
||||
var carrier = new Dictionary<string, string>();
|
||||
b3Format.Inject(new SpanContext(TraceId, SpanId, TraceOptions), carrier, setter);
|
||||
ContainsExactly(carrier, new Dictionary<string, string>() { { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Sampled, "1" } });
|
||||
b3Format.Inject(new SpanContext(TraceId, SpanId, TraceOptions), carrier, Setter);
|
||||
ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Sampled, "1" } });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -59,9 +60,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var carrier = new Dictionary<string, string>();
|
||||
var context = new SpanContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||
_output.WriteLine(context.ToString());
|
||||
b3Format.Inject(context, carrier, setter);
|
||||
ContainsExactly(carrier, new Dictionary<string, string>() { { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 } });
|
||||
output.WriteLine(context.ToString());
|
||||
b3Format.Inject(context, carrier, Setter);
|
||||
ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 } });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -72,7 +73,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, SpanIdBase16},
|
||||
};
|
||||
var spanContext = new SpanContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||
Assert.Equal(spanContext, b3Format.Extract(headersNotSampled, getter));
|
||||
Assert.Equal(spanContext, b3Format.Extract(headersNotSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -82,7 +83,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, SpanIdBase16}, {B3Format.XB3Sampled, "1"},
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), b3Format.Extract(headersSampled, getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), b3Format.Extract(headersSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -92,7 +93,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, SpanIdBase16}, {B3Format.XB3Sampled, "0"},
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), b3Format.Extract(headersNotSampled, getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), b3Format.Extract(headersNotSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -102,7 +103,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, SpanIdBase16}, {B3Format.XB3Flags, "1"},
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), b3Format.Extract(headersFlagSampled, getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), b3Format.Extract(headersFlagSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -112,7 +113,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, SpanIdBase16}, {B3Format.XB3Flags, "0"},
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), b3Format.Extract(headersFlagNotSampled, getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), b3Format.Extract(headersFlagNotSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -124,7 +125,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{B3Format.XB3SpanId, SpanIdBase16},
|
||||
{B3Format.XB3Sampled, "1"},
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, TraceOptions), b3Format.Extract(headersEightBytes, getter));
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, TraceOptions), b3Format.Extract(headersEightBytes, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -134,7 +135,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16EightBytes}, {B3Format.XB3SpanId, SpanIdBase16},
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, ActivityTraceFlags.None), b3Format.Extract(headersEightBytes, getter));
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, ActivityTraceFlags.None), b3Format.Extract(headersEightBytes, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -142,9 +143,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, "abcdefghijklmnop"}, {B3Format.XB3SpanId, SpanIdBase16},
|
||||
{B3Format.XB3TraceId, InvalidId}, {B3Format.XB3SpanId, SpanIdBase16},
|
||||
};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -152,17 +153,17 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, "0123456789abcdef00"}, {B3Format.XB3SpanId, SpanIdBase16},
|
||||
{B3Format.XB3TraceId, InvalidSizeId}, {B3Format.XB3SpanId, SpanIdBase16},
|
||||
};
|
||||
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseMissingTraceId()
|
||||
{
|
||||
var invalidHeaders = new Dictionary<string, string> {{B3Format.XB3SpanId, SpanIdBase16},};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -170,9 +171,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, "abcdefghijklmnop"},
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, InvalidId},
|
||||
};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -180,24 +181,24 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, "0123456789abcdef00"},
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, InvalidSizeId},
|
||||
};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseMissingSpanId()
|
||||
{
|
||||
var invalidHeaders = new Dictionary<string, string> {{B3Format.XB3TraceId, TraceIdBase16}};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_SampledContext_SingleHeader()
|
||||
{
|
||||
var carrier = new Dictionary<string, string>();
|
||||
b3FormatSingleHeader.Inject(new SpanContext(TraceId, SpanId, TraceOptions), carrier, setter);
|
||||
ContainsExactly(carrier, new Dictionary<string, string>() { { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" } });
|
||||
b3FormatSingleHeader.Inject(new SpanContext(TraceId, SpanId, TraceOptions), carrier, Setter);
|
||||
ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" } });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -205,9 +206,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var carrier = new Dictionary<string, string>();
|
||||
var context = new SpanContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||
_output.WriteLine(context.ToString());
|
||||
b3FormatSingleHeader.Inject(context, carrier, setter);
|
||||
ContainsExactly(carrier, new Dictionary<string, string>() { { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}" } });
|
||||
output.WriteLine(context.ToString());
|
||||
b3FormatSingleHeader.Inject(context, carrier, Setter);
|
||||
ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}" } });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -218,7 +219,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}"},
|
||||
};
|
||||
var spanContext = new SpanContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||
Assert.Equal(spanContext, b3FormatSingleHeader.Extract(headersNotSampled, getter));
|
||||
Assert.Equal(spanContext, b3FormatSingleHeader.Extract(headersNotSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -228,7 +229,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1"},
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), b3FormatSingleHeader.Extract(headersSampled, getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), b3FormatSingleHeader.Extract(headersSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -238,7 +239,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-0"},
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), b3FormatSingleHeader.Extract(headersNotSampled, getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), b3FormatSingleHeader.Extract(headersNotSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -248,7 +249,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1"},
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), b3FormatSingleHeader.Extract(headersFlagSampled, getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), b3FormatSingleHeader.Extract(headersFlagSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -258,7 +259,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-0"},
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), b3FormatSingleHeader.Extract(headersFlagNotSampled, getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), b3FormatSingleHeader.Extract(headersFlagNotSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -268,7 +269,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16EightBytes}-{SpanIdBase16}-1"},
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, TraceOptions), b3FormatSingleHeader.Extract(headersEightBytes, getter));
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, TraceOptions), b3FormatSingleHeader.Extract(headersEightBytes, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -278,7 +279,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16EightBytes}-{SpanIdBase16}"},
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, ActivityTraceFlags.None), b3FormatSingleHeader.Extract(headersEightBytes, getter));
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, ActivityTraceFlags.None), b3FormatSingleHeader.Extract(headersEightBytes, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -286,9 +287,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"abcdefghijklmnop-{SpanIdBase16}"},
|
||||
{B3Format.XB3Combined, $"{InvalidId}-{SpanIdBase16}"},
|
||||
};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -296,17 +297,17 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"0123456789abcdef00-{SpanIdBase16}"},
|
||||
{B3Format.XB3Combined, $"{InvalidSizeId}-{SpanIdBase16}"},
|
||||
};
|
||||
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseMissingTraceId_SingleHeader()
|
||||
{
|
||||
var invalidHeaders = new Dictionary<string, string> {{B3Format.XB3Combined, $"-{SpanIdBase16}"}};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -314,9 +315,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-abcdefghijklmnop"},
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-{InvalidId}"},
|
||||
};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -324,23 +325,23 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-0123456789abcdef00"},
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-{InvalidSizeId}"},
|
||||
};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseMissingSpanId_SingleHeader()
|
||||
{
|
||||
var invalidHeaders = new Dictionary<string, string> {{B3Format.XB3Combined, $"{TraceIdBase16}-"}};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Fields_list()
|
||||
{
|
||||
ContainsExactly(b3Format.Fields,
|
||||
new List<string>() { B3Format.XB3TraceId, B3Format.XB3SpanId, B3Format.XB3ParentSpanId, B3Format.XB3Sampled, B3Format.XB3Flags });
|
||||
new List<string> { B3Format.XB3TraceId, B3Format.XB3SpanId, B3Format.XB3ParentSpanId, B3Format.XB3Sampled, B3Format.XB3Flags });
|
||||
}
|
||||
|
||||
private void ContainsExactly(ISet<string> list, List<string> items)
|
||||
|
|
@ -356,7 +357,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
foreach (var d in dict)
|
||||
{
|
||||
_output.WriteLine(d.Key + "=" + d.Value);
|
||||
output.WriteLine(d.Key + "=" + d.Value);
|
||||
}
|
||||
|
||||
Assert.Equal(items.Count, dict.Count);
|
||||
|
|
|
|||
|
|
@ -24,34 +24,36 @@ namespace OpenTelemetry.Impl.Trace.Propagation
|
|||
{
|
||||
public class TraceContextTest
|
||||
{
|
||||
private static readonly string[] empty = new string[0];
|
||||
private static readonly Func<IDictionary<string, string>, string, IEnumerable<string>> getter = (headers, name) =>
|
||||
private const string TraceParent = "traceparent";
|
||||
private const string TraceState = "tracestate";
|
||||
private const string TraceId = "0af7651916cd43dd8448eb211c80319c";
|
||||
private const string SpanId = "b9c7c989f97918e1";
|
||||
|
||||
private static readonly string[] Empty = new string[0];
|
||||
private static readonly Func<IDictionary<string, string>, string, IEnumerable<string>> Getter = (headers, name) =>
|
||||
{
|
||||
if (headers.TryGetValue(name, out var value))
|
||||
{
|
||||
return new [] { value };
|
||||
}
|
||||
|
||||
return empty;
|
||||
return Empty;
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void TraceContextFormatCanParseExampleFromSpec()
|
||||
{
|
||||
var headers = new Dictionary<string, string>()
|
||||
var headers = new Dictionary<string, string>
|
||||
{
|
||||
{"traceparent", "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"},
|
||||
{
|
||||
"tracestate",
|
||||
"congo=lZWRzIHRoNhcm5hbCBwbGVhc3VyZS4,rojo=00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01"
|
||||
},
|
||||
{TraceParent, $"00-{TraceId}-{SpanId}-01"},
|
||||
{TraceState, $"congo=lZWRzIHRoNhcm5hbCBwbGVhc3VyZS4,rojo=00-{TraceId}-00f067aa0ba902b7-01"},
|
||||
};
|
||||
|
||||
var f = new TraceContextFormat();
|
||||
var ctx = f.Extract(headers, getter);
|
||||
var ctx = f.Extract(headers, Getter);
|
||||
|
||||
Assert.Equal(ActivityTraceId.CreateFromString("0af7651916cd43dd8448eb211c80319c".AsSpan()), ctx.TraceId);
|
||||
Assert.Equal(ActivitySpanId.CreateFromString("b9c7c989f97918e1".AsSpan()), ctx.SpanId);
|
||||
Assert.Equal(ActivityTraceId.CreateFromString(TraceId.AsSpan()), ctx.TraceId);
|
||||
Assert.Equal(ActivitySpanId.CreateFromString(SpanId.AsSpan()), ctx.SpanId);
|
||||
Assert.True(ctx.IsRemote);
|
||||
Assert.True(ctx.IsValid);
|
||||
Assert.True((ctx.TraceOptions & ActivityTraceFlags.Recorded) != 0);
|
||||
|
|
@ -66,22 +68,22 @@ namespace OpenTelemetry.Impl.Trace.Propagation
|
|||
var last = ctx.Tracestate.Last();
|
||||
|
||||
Assert.Equal("rojo", last.Key);
|
||||
Assert.Equal("00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01", last.Value);
|
||||
Assert.Equal($"00-{TraceId}-00f067aa0ba902b7-01", last.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TraceContextFormatNotSampled()
|
||||
{
|
||||
var headers = new Dictionary<string, string>()
|
||||
var headers = new Dictionary<string, string>
|
||||
{
|
||||
{"traceparent", "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-00"},
|
||||
{TraceParent, $"00-{TraceId}-{SpanId}-00"},
|
||||
};
|
||||
|
||||
var f = new TraceContextFormat();
|
||||
var ctx = f.Extract(headers, getter);
|
||||
var ctx = f.Extract(headers, Getter);
|
||||
|
||||
Assert.Equal(ActivityTraceId.CreateFromString("0af7651916cd43dd8448eb211c80319c".AsSpan()), ctx.TraceId);
|
||||
Assert.Equal(ActivitySpanId.CreateFromString("b9c7c989f97918e1".AsSpan()), ctx.SpanId);
|
||||
Assert.Equal(ActivityTraceId.CreateFromString(TraceId.AsSpan()), ctx.TraceId);
|
||||
Assert.Equal(ActivitySpanId.CreateFromString(SpanId.AsSpan()), ctx.SpanId);
|
||||
Assert.True((ctx.TraceOptions & ActivityTraceFlags.Recorded) == 0);
|
||||
Assert.True(ctx.IsRemote);
|
||||
Assert.True(ctx.IsValid);
|
||||
|
|
@ -93,7 +95,7 @@ namespace OpenTelemetry.Impl.Trace.Propagation
|
|||
var headers = new Dictionary<string, string>();
|
||||
|
||||
var f = new TraceContextFormat();
|
||||
var ctx = f.Extract(headers, getter);
|
||||
var ctx = f.Extract(headers, Getter);
|
||||
|
||||
Assert.False(ctx.IsValid);
|
||||
Assert.True(ctx.IsRemote);
|
||||
|
|
@ -104,11 +106,11 @@ namespace OpenTelemetry.Impl.Trace.Propagation
|
|||
{
|
||||
var headers = new Dictionary<string, string>
|
||||
{
|
||||
{ "traceparent", "00-xyz7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01" },
|
||||
{TraceParent, $"00-xyz7651916cd43dd8448eb211c80319c-{SpanId}-01"},
|
||||
};
|
||||
|
||||
var f = new TraceContextFormat();
|
||||
var ctx = f.Extract(headers, getter);
|
||||
var ctx = f.Extract(headers, Getter);
|
||||
|
||||
Assert.False(ctx.IsValid);
|
||||
Assert.True(ctx.IsRemote);
|
||||
|
|
@ -119,11 +121,11 @@ namespace OpenTelemetry.Impl.Trace.Propagation
|
|||
{
|
||||
var headers = new Dictionary<string, string>
|
||||
{
|
||||
{"traceparent", "00-abc7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"},
|
||||
{TraceParent, $"00-{TraceId}-{SpanId}-01"},
|
||||
};
|
||||
|
||||
var f = new TraceContextFormat();
|
||||
var ctx = f.Extract(headers, getter);
|
||||
var ctx = f.Extract(headers, Getter);
|
||||
|
||||
Assert.Empty(ctx.Tracestate);
|
||||
Assert.Equal(string.Empty, TracestateUtils.GetString(ctx.Tracestate));
|
||||
|
|
@ -134,12 +136,12 @@ namespace OpenTelemetry.Impl.Trace.Propagation
|
|||
{
|
||||
var headers = new Dictionary<string, string>
|
||||
{
|
||||
{"traceparent", "00-abc7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"},
|
||||
{"tracestate", "k1=v1,k2=v2,k3=v3" },
|
||||
{TraceParent, $"00-{TraceId}-{SpanId}-01"},
|
||||
{TraceState, "k1=v1,k2=v2,k3=v3" },
|
||||
};
|
||||
|
||||
var f = new TraceContextFormat();
|
||||
var ctx = f.Extract(headers, getter);
|
||||
var ctx = f.Extract(headers, Getter);
|
||||
|
||||
var entries = ctx.Tracestate.ToArray();
|
||||
Assert.Equal(3, entries.Length);
|
||||
|
|
|
|||
|
|
@ -22,11 +22,10 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
{
|
||||
public class SamplersTest
|
||||
{
|
||||
private static readonly string SpanName = "MySpanName";
|
||||
private static readonly int NUM_SAMPLE_TRIES = 1000;
|
||||
private const string SpanName = "MySpanName";
|
||||
private const int NUM_SAMPLE_TRIES = 1000;
|
||||
private static readonly SpanKind SpanKindServer = SpanKind.Server;
|
||||
private readonly ActivityTraceId traceId;
|
||||
private readonly ActivitySpanId parentSpanId;
|
||||
private readonly ActivitySpanId spanId;
|
||||
private readonly SpanContext sampledSpanContext;
|
||||
private readonly SpanContext notSampledSpanContext;
|
||||
|
|
@ -35,8 +34,8 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
public SamplersTest()
|
||||
{
|
||||
traceId = ActivityTraceId.CreateRandom();
|
||||
parentSpanId = ActivitySpanId.CreateRandom();
|
||||
spanId = ActivitySpanId.CreateRandom();
|
||||
var parentSpanId = ActivitySpanId.CreateRandom();
|
||||
sampledSpanContext = new SpanContext(traceId, parentSpanId, ActivityTraceFlags.Recorded);
|
||||
notSampledSpanContext = new SpanContext(traceId, parentSpanId, ActivityTraceFlags.None);
|
||||
sampledLink = new Link(sampledSpanContext);
|
||||
|
|
@ -122,7 +121,6 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
Assert.Throws<ArgumentOutOfRangeException>(() => new ProbabilitySampler(-0.00001));
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void ProbabilitySampler_DifferentProbabilities_NotSampledParent()
|
||||
{
|
||||
|
|
@ -191,7 +189,7 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
// is not less than probability * Long.MAX_VALUE;
|
||||
var notSampledtraceId =
|
||||
ActivityTraceId.CreateFromBytes(
|
||||
new byte[]
|
||||
new byte[]
|
||||
{
|
||||
0x8F,
|
||||
0xFF,
|
||||
|
|
@ -212,7 +210,7 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
});
|
||||
Assert.False(
|
||||
defaultProbability.ShouldSample(
|
||||
default,
|
||||
default,
|
||||
notSampledtraceId,
|
||||
ActivitySpanId.CreateRandom(),
|
||||
SpanName,
|
||||
|
|
@ -223,7 +221,7 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
// is less than probability * Long.MAX_VALUE;
|
||||
var sampledtraceId =
|
||||
ActivityTraceId.CreateFromBytes(
|
||||
new byte[]
|
||||
new byte[]
|
||||
{
|
||||
0x00,
|
||||
0x00,
|
||||
|
|
|
|||
|
|
@ -22,22 +22,21 @@ namespace OpenTelemetry.Trace.Test
|
|||
{
|
||||
public class SpanContextTest
|
||||
{
|
||||
private static readonly byte[] firstTraceIdBytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte)'a' };
|
||||
private static readonly byte[] FirstTraceIdBytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte)'a' };
|
||||
private static readonly byte[] SecondTraceIdBytes = { 0, 0, 0, 0, 0, 0, 0, (byte)'0', 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
private static readonly byte[] FirstSpanIdBytes = { 0, 0, 0, 0, 0, 0, 0, (byte)'a' };
|
||||
private static readonly byte[] SecondSpanIdBytes = { (byte)'0', 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
private static readonly byte[] secondTraceIdBytes = { 0, 0, 0, 0, 0, 0, 0, (byte)'0', 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
private static readonly byte[] firstSpanIdBytes = { 0, 0, 0, 0, 0, 0, 0, (byte)'a' };
|
||||
private static readonly byte[] secondSpanIdBytes = { (byte)'0', 0, 0, 0, 0, 0, 0, 0 };
|
||||
private static readonly SpanContext first =
|
||||
private static readonly SpanContext First =
|
||||
new SpanContext(
|
||||
ActivityTraceId.CreateFromBytes(firstTraceIdBytes),
|
||||
ActivitySpanId.CreateFromBytes(firstSpanIdBytes),
|
||||
ActivityTraceId.CreateFromBytes(FirstTraceIdBytes),
|
||||
ActivitySpanId.CreateFromBytes(FirstSpanIdBytes),
|
||||
ActivityTraceFlags.None);
|
||||
|
||||
private static readonly SpanContext second =
|
||||
private static readonly SpanContext Second =
|
||||
new SpanContext(
|
||||
ActivityTraceId.CreateFromBytes(secondTraceIdBytes),
|
||||
ActivitySpanId.CreateFromBytes(secondSpanIdBytes),
|
||||
ActivityTraceId.CreateFromBytes(SecondTraceIdBytes),
|
||||
ActivitySpanId.CreateFromBytes(SecondSpanIdBytes),
|
||||
ActivityTraceFlags.Recorded);
|
||||
|
||||
[Fact]
|
||||
|
|
@ -54,35 +53,35 @@ namespace OpenTelemetry.Trace.Test
|
|||
Assert.False(default(SpanContext).IsValid);
|
||||
Assert.False(
|
||||
new SpanContext(
|
||||
ActivityTraceId.CreateFromBytes(firstTraceIdBytes), default, ActivityTraceFlags.None)
|
||||
ActivityTraceId.CreateFromBytes(FirstTraceIdBytes), default, ActivityTraceFlags.None)
|
||||
.IsValid);
|
||||
Assert.False(
|
||||
new SpanContext(
|
||||
default, ActivitySpanId.CreateFromBytes(firstSpanIdBytes), ActivityTraceFlags.None)
|
||||
default, ActivitySpanId.CreateFromBytes(FirstSpanIdBytes), ActivityTraceFlags.None)
|
||||
.IsValid);
|
||||
Assert.True(first.IsValid);
|
||||
Assert.True(second.IsValid);
|
||||
Assert.True(First.IsValid);
|
||||
Assert.True(Second.IsValid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTraceId()
|
||||
{
|
||||
Assert.Equal(ActivityTraceId.CreateFromBytes(firstTraceIdBytes), first.TraceId);
|
||||
Assert.Equal(ActivityTraceId.CreateFromBytes(secondTraceIdBytes), second.TraceId);
|
||||
Assert.Equal(ActivityTraceId.CreateFromBytes(FirstTraceIdBytes), First.TraceId);
|
||||
Assert.Equal(ActivityTraceId.CreateFromBytes(SecondTraceIdBytes), Second.TraceId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetSpanId()
|
||||
{
|
||||
Assert.Equal(ActivitySpanId.CreateFromBytes(firstSpanIdBytes), first.SpanId);
|
||||
Assert.Equal(ActivitySpanId.CreateFromBytes(secondSpanIdBytes), second.SpanId);
|
||||
Assert.Equal(ActivitySpanId.CreateFromBytes(FirstSpanIdBytes), First.SpanId);
|
||||
Assert.Equal(ActivitySpanId.CreateFromBytes(SecondSpanIdBytes), Second.SpanId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTraceOptions()
|
||||
{
|
||||
Assert.Equal(ActivityTraceFlags.None, first.TraceOptions);
|
||||
Assert.Equal(ActivityTraceFlags.Recorded, second.TraceOptions);
|
||||
Assert.Equal(ActivityTraceFlags.None, First.TraceOptions);
|
||||
Assert.Equal(ActivityTraceFlags.Recorded, Second.TraceOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -103,7 +103,6 @@ namespace OpenTelemetry.Tests.Impl.Trace
|
|||
Assert.Empty(spanData.Links);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void SpanData_FromSpan_ReflectsSpanChanges()
|
||||
{
|
||||
|
|
@ -114,7 +113,7 @@ namespace OpenTelemetry.Tests.Impl.Trace
|
|||
Assert.Empty(spanData.Attributes);
|
||||
Assert.Empty(spanData.Events);
|
||||
Assert.Equal(default, spanData.EndTimestamp);
|
||||
|
||||
|
||||
span.AddEvent(new Event("event"));
|
||||
span.SetAttribute("key", "value");
|
||||
|
||||
|
|
|
|||
|
|
@ -1022,17 +1022,17 @@ namespace OpenTelemetry.Trace.Test
|
|||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(new bool[] {true, false, true})]
|
||||
[InlineData(new long[] {1L, 2L, 3L})]
|
||||
[InlineData(new ulong[] {1UL, 2UL, 3UL})]
|
||||
[InlineData(new uint[] {1U, 2U, 3U})]
|
||||
[InlineData(new int[] {1, 2, 3})]
|
||||
[InlineData(new sbyte[] {(sbyte)1, (sbyte)2, (sbyte)3})]
|
||||
[InlineData(new byte[] {(byte)1, (byte)2, (byte)3})]
|
||||
[InlineData(new short[] {(short)1, (short)2, (short)3})]
|
||||
[InlineData(new ushort[] {(ushort)1, (ushort)2, (ushort)3})]
|
||||
[InlineData(new double[] {1.1d,2.2d,3.3d})]
|
||||
[InlineData(new float[] {1.1f,2.2f,3.3f})]
|
||||
[InlineData(new[] {true, false, true})]
|
||||
[InlineData(new[] {1L, 2L, 3L})]
|
||||
[InlineData(new[] {1UL, 2UL, 3UL})]
|
||||
[InlineData(new[] {1U, 2U, 3U})]
|
||||
[InlineData(new[] {1, 2, 3})]
|
||||
[InlineData(new sbyte[] {1, 2, 3})]
|
||||
[InlineData(new byte[] {1, 2, 3})]
|
||||
[InlineData(new short[] {1, 2, 3})]
|
||||
[InlineData(new ushort[] {1, 2, 3})]
|
||||
[InlineData(new[] {1.1d,2.2d,3.3d})]
|
||||
[InlineData(new[] {1.1f,2.2f,3.3f})]
|
||||
public void SetAttribute_Array(object array)
|
||||
{
|
||||
var tracer = tracerFactory.GetTracer(null);
|
||||
|
|
@ -1052,7 +1052,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
var tracer = tracerFactory.GetTracer(null);
|
||||
var span = (SpanSdk)tracer.StartRootSpan(SpanName);
|
||||
|
||||
var array = new string[] {"1","2","3"};
|
||||
var array = new[] {"1","2","3"};
|
||||
span.SetAttribute("array", array);
|
||||
|
||||
Assert.Single(span.Attributes);
|
||||
|
|
@ -1068,7 +1068,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
var tracer = tracerFactory.GetTracer(null);
|
||||
var span = (SpanSdk)tracer.StartRootSpan(SpanName);
|
||||
|
||||
var array = new Decimal[] {1.1M, 2.2M, 3.3M};
|
||||
var array = new[] {1.1M, 2.2M, 3.3M};
|
||||
span.SetAttribute("array", array);
|
||||
|
||||
Assert.Single(span.Attributes);
|
||||
|
|
@ -1283,13 +1283,12 @@ namespace OpenTelemetry.Trace.Test
|
|||
Assert.True(span.Context.IsValid);
|
||||
Assert.NotNull(span);
|
||||
Assert.Equal(SpanKind.Producer, span.Kind);
|
||||
Assert.Equal(parentSpan.Context.SpanId, ((SpanSdk)span).ParentSpanId);
|
||||
Assert.Equal(parentSpan.Context.SpanId, span.ParentSpanId);
|
||||
}
|
||||
|
||||
Assert.False(tracer.CurrentSpan.Context.IsValid);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void StartActiveSpan_ParentSpan_Kind_Timestamp()
|
||||
{
|
||||
|
|
@ -1308,7 +1307,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
Assert.True(span.Context.IsValid);
|
||||
Assert.Equal(SpanKind.Producer, span.Kind);
|
||||
Assert.Equal(startTimestamp, span.StartTimestamp);
|
||||
Assert.Equal(parentSpan.Context.SpanId, ((SpanSdk)span).ParentSpanId);
|
||||
Assert.Equal(parentSpan.Context.SpanId, span.ParentSpanId);
|
||||
}
|
||||
|
||||
Assert.False(tracer.CurrentSpan.Context.IsValid);
|
||||
|
|
@ -1334,7 +1333,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
Assert.Equal(SpanKind.Producer, span.Kind);
|
||||
Assert.Equal(startTimestamp, span.StartTimestamp);
|
||||
Assert.Single(span.Links);
|
||||
Assert.Equal(parentSpan.Context.SpanId, ((SpanSdk)span).ParentSpanId);
|
||||
Assert.Equal(parentSpan.Context.SpanId, span.ParentSpanId);
|
||||
}
|
||||
|
||||
Assert.False(tracer.CurrentSpan.Context.IsValid);
|
||||
|
|
@ -1377,7 +1376,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
Assert.NotNull(span);
|
||||
|
||||
Assert.Equal(SpanKind.Producer, span.Kind);
|
||||
Assert.Equal(parentContext.SpanId, ((SpanSdk)span).ParentSpanId);
|
||||
Assert.Equal(parentContext.SpanId, span.ParentSpanId);
|
||||
}
|
||||
|
||||
Assert.False(tracer.CurrentSpan.Context.IsValid);
|
||||
|
|
@ -1402,7 +1401,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
Assert.True(span.Context.IsValid);
|
||||
Assert.Equal(SpanKind.Producer, span.Kind);
|
||||
Assert.Equal(startTimestamp, span.StartTimestamp);
|
||||
Assert.Equal(parentContext.SpanId, ((SpanSdk)span).ParentSpanId);
|
||||
Assert.Equal(parentContext.SpanId, span.ParentSpanId);
|
||||
}
|
||||
|
||||
Assert.False(tracer.CurrentSpan.Context.IsValid);
|
||||
|
|
@ -1428,7 +1427,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
Assert.Equal(SpanKind.Producer, span.Kind);
|
||||
Assert.Equal(startTimestamp, span.StartTimestamp);
|
||||
Assert.Single(span.Links);
|
||||
Assert.Equal(parentContext.SpanId, ((SpanSdk)span).ParentSpanId);
|
||||
Assert.Equal(parentContext.SpanId, span.ParentSpanId);
|
||||
}
|
||||
|
||||
Assert.False(tracer.CurrentSpan.Context.IsValid);
|
||||
|
|
@ -1472,7 +1471,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
Assert.Same(childSpan, span);
|
||||
|
||||
Assert.Equal(SpanKind.Producer, span.Kind);
|
||||
Assert.NotEqual(default, ((SpanSdk)span).ParentSpanId);
|
||||
Assert.NotEqual(default, span.ParentSpanId);
|
||||
}
|
||||
|
||||
Assert.False(tracer.CurrentSpan.Context.IsValid);
|
||||
|
|
@ -1498,7 +1497,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
|
||||
Assert.Equal(SpanKind.Producer, span.Kind);
|
||||
Assert.Equal(startTimestamp, span.StartTimestamp);
|
||||
Assert.NotEqual(default, ((SpanSdk)span).ParentSpanId);
|
||||
Assert.NotEqual(default, span.ParentSpanId);
|
||||
}
|
||||
|
||||
Assert.False(tracer.CurrentSpan.Context.IsValid);
|
||||
|
|
@ -1525,7 +1524,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
Assert.Equal(SpanKind.Producer, span.Kind);
|
||||
Assert.Equal(startTimestamp, span.StartTimestamp);
|
||||
Assert.Single(span.Links);
|
||||
Assert.NotEqual(default, ((SpanSdk)span).ParentSpanId);
|
||||
Assert.NotEqual(default, span.ParentSpanId);
|
||||
}
|
||||
|
||||
Assert.False(tracer.CurrentSpan.Context.IsValid);
|
||||
|
|
@ -1661,7 +1660,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
It.IsAny<IEnumerable<Link>>()), Times.Once);
|
||||
}
|
||||
|
||||
private void AssertApproxSameTimestamp(DateTimeOffset one, DateTimeOffset two)
|
||||
private static void AssertApproxSameTimestamp(DateTimeOffset one, DateTimeOffset two)
|
||||
{
|
||||
var timeShift = Math.Abs((one - two).TotalMilliseconds);
|
||||
Assert.InRange(timeShift, 0, 40);
|
||||
|
|
|
|||
|
|
@ -355,7 +355,6 @@ namespace OpenTelemetry.Trace.Test
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void DroppingAttributes()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue