More cleanups. (#875)
* Rename samplers * Cleanups * typos * remove internal as it has nothing now * rename more
This commit is contained in:
parent
b91b45ae44
commit
13dd5d717e
|
|
@ -32,10 +32,10 @@ namespace Benchmarks
|
|||
public OpenTelemetrySdkBenchmarks()
|
||||
{
|
||||
using var openTelemetryAlwaysOnSample = OpenTelemetrySdk.EnableOpenTelemetry(
|
||||
(builder) => builder.AddActivitySource("AlwaysOnSample").SetSampler(new AlwaysOnActivitySampler()));
|
||||
(builder) => builder.AddActivitySource("AlwaysOnSample").SetSampler(new AlwaysOnSampler()));
|
||||
|
||||
using var openTelemetryAlwaysOffSample = OpenTelemetrySdk.EnableOpenTelemetry(
|
||||
(builder) => builder.AddActivitySource("AlwaysOffSample").SetSampler(new AlwaysOffActivitySampler()));
|
||||
(builder) => builder.AddActivitySource("AlwaysOffSample").SetSampler(new AlwaysOffSampler()));
|
||||
|
||||
using var openTelemetryNoOp = OpenTelemetrySdk.EnableOpenTelemetry(null);
|
||||
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ namespace OpenTelemetry.Trace
|
|||
/// <param name="key">Attribute key.</param>
|
||||
/// <param name="value">Attribute value. The value may be an <see cref="IEnumerable"/> of primitive types. An enumeration may be iterated multiple times.</param>
|
||||
/// <returns>The <see cref="TelemetrySpan"/> instance for chaining.</returns>
|
||||
/// <remarks>More types for value will be supported in the next release. (bool, int etc.)</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public TelemetrySpan SetAttribute(string key, string value)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,8 +10,11 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Implementation\**" />
|
||||
<Compile Remove="Trace\Internal\**" />
|
||||
<EmbeddedResource Remove="Implementation\**" />
|
||||
<EmbeddedResource Remove="Trace\Internal\**" />
|
||||
<None Remove="Implementation\**" />
|
||||
<None Remove="Trace\Internal\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@ namespace OpenTelemetry.Trace
|
|||
/// </summary>
|
||||
public class ActivitySourceAdapter
|
||||
{
|
||||
private ActivitySampler activitySampler;
|
||||
private Sampler activitySampler;
|
||||
private ActivityProcessor activityProcessor;
|
||||
private Resource resource;
|
||||
|
||||
internal ActivitySourceAdapter(ActivitySampler activitySampler, ActivityProcessor activityProcessor, Resource resource)
|
||||
internal ActivitySourceAdapter(Sampler activitySampler, ActivityProcessor activityProcessor, Resource resource)
|
||||
{
|
||||
this.activitySampler = activitySampler;
|
||||
this.activityProcessor = activityProcessor;
|
||||
|
|
@ -85,7 +85,7 @@ namespace OpenTelemetry.Trace
|
|||
}
|
||||
}
|
||||
|
||||
var samplingParameters = new ActivitySamplingParameters(
|
||||
var samplingParameters = new SamplingParameters(
|
||||
parentContext,
|
||||
activity.TraceId,
|
||||
activity.DisplayName,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace OpenTelemetry.Trace.Configuration
|
|||
|
||||
internal List<InstrumentationFactory> InstrumentationFactories { get; private set; }
|
||||
|
||||
internal ActivitySampler Sampler { get; private set; }
|
||||
internal Sampler Sampler { get; private set; }
|
||||
|
||||
internal Resource Resource { get; private set; } = Resource.Empty;
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ namespace OpenTelemetry.Trace.Configuration
|
|||
/// </summary>
|
||||
/// <param name="sampler">Sampler instance.</param>
|
||||
/// <returns>Returns <see cref="OpenTelemetryBuilder"/> for chaining.</returns>
|
||||
public OpenTelemetryBuilder SetSampler(ActivitySampler sampler)
|
||||
public OpenTelemetryBuilder SetSampler(Sampler sampler)
|
||||
{
|
||||
this.Sampler = sampler ?? throw new ArgumentNullException(nameof(sampler));
|
||||
return this;
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ namespace OpenTelemetry.Trace.Configuration
|
|||
configureOpenTelemetryBuilder?.Invoke(openTelemetryBuilder);
|
||||
|
||||
var openTelemetrySDK = new OpenTelemetrySdk();
|
||||
ActivitySampler sampler = openTelemetryBuilder.Sampler ?? new AlwaysOnActivitySampler();
|
||||
Sampler sampler = openTelemetryBuilder.Sampler ?? new AlwaysOnSampler();
|
||||
|
||||
ActivityProcessor activityProcessor;
|
||||
if (openTelemetryBuilder.ProcessingPipelines == null || !openTelemetryBuilder.ProcessingPipelines.Any())
|
||||
|
|
@ -155,7 +155,7 @@ namespace OpenTelemetry.Trace.Configuration
|
|||
|
||||
internal static ActivityDataRequest ComputeActivityDataRequest(
|
||||
in ActivityCreationOptions<ActivityContext> options,
|
||||
ActivitySampler sampler)
|
||||
Sampler sampler)
|
||||
{
|
||||
var isRootSpan = options.Parent.TraceId == default;
|
||||
|
||||
|
|
@ -166,7 +166,7 @@ namespace OpenTelemetry.Trace.Configuration
|
|||
? options.Parent.TraceId
|
||||
: ActivityTraceId.CreateRandom();
|
||||
|
||||
var samplingParameters = new ActivitySamplingParameters(
|
||||
var samplingParameters = new SamplingParameters(
|
||||
options.Parent,
|
||||
traceId,
|
||||
options.Name,
|
||||
|
|
|
|||
|
|
@ -1,139 +0,0 @@
|
|||
// <copyright file="EvictingQueue.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace OpenTelemetry.Trace.Internal
|
||||
{
|
||||
internal class EvictingQueue<T> : IEnumerable<T>
|
||||
{
|
||||
private readonly int maxNumItems;
|
||||
private readonly T[] items;
|
||||
private int totalRecorded;
|
||||
private int tail;
|
||||
|
||||
public EvictingQueue(int maxNumItems)
|
||||
{
|
||||
if (maxNumItems < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(maxNumItems), $"{nameof(maxNumItems)} must be >= 0.");
|
||||
}
|
||||
|
||||
this.maxNumItems = maxNumItems;
|
||||
this.tail = 0;
|
||||
this.items = new T[maxNumItems];
|
||||
}
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public int DroppedItems => this.totalRecorded - this.Count;
|
||||
|
||||
public Enumerator GetEnumerator()
|
||||
{
|
||||
return new Enumerator(this);
|
||||
}
|
||||
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator()
|
||||
{
|
||||
return new Enumerator(this);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return new Enumerator(this);
|
||||
}
|
||||
|
||||
internal void Replace(T item, T newItem)
|
||||
{
|
||||
Debug.Assert(item != null, "Item must not be null");
|
||||
Debug.Assert(newItem != null, "Item must not be null");
|
||||
|
||||
var index = Array.IndexOf(this.items, item);
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.items[index] = newItem;
|
||||
}
|
||||
|
||||
internal void Add(T item)
|
||||
{
|
||||
Debug.Assert(item != null, "Item must not be null");
|
||||
|
||||
this.totalRecorded++;
|
||||
if (this.maxNumItems == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.Count < this.maxNumItems)
|
||||
{
|
||||
this.Count++;
|
||||
}
|
||||
|
||||
this.items[this.tail % this.maxNumItems] = item;
|
||||
this.tail++;
|
||||
}
|
||||
|
||||
public struct Enumerator : IEnumerator<T>, IEnumerator
|
||||
{
|
||||
private readonly EvictingQueue<T> evictingQueue;
|
||||
private readonly int head;
|
||||
private int index;
|
||||
private T current;
|
||||
|
||||
internal Enumerator(EvictingQueue<T> evictingQueue)
|
||||
{
|
||||
this.evictingQueue = evictingQueue;
|
||||
this.head = this.evictingQueue.tail - this.evictingQueue.Count;
|
||||
this.index = this.head;
|
||||
this.current = default;
|
||||
}
|
||||
|
||||
public T Current { get => this.current; }
|
||||
|
||||
object IEnumerator.Current { get => this.Current; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (this.index < this.evictingQueue.Count + this.head)
|
||||
{
|
||||
this.current = this.evictingQueue.items[this.index++ % this.evictingQueue.maxNumItems];
|
||||
return true;
|
||||
}
|
||||
|
||||
this.index = this.evictingQueue.tail + 1;
|
||||
this.current = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
void IEnumerator.Reset()
|
||||
{
|
||||
this.index = this.head;
|
||||
this.current = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
// <copyright file="TagsCollection.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenTelemetry.Trace.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Tags collection.
|
||||
/// </summary>
|
||||
internal struct TagsCollection : IEnumerable<KeyValuePair<string, object>>
|
||||
{
|
||||
private IEnumerable<KeyValuePair<string, string>> enumerable;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TagsCollection"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="tags">the tags.</param>
|
||||
public TagsCollection(IEnumerable<KeyValuePair<string, string>> tags)
|
||||
{
|
||||
this.enumerable = tags;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IEnumerator GetEnumerator() => new TagsEnumerator(this.enumerable.GetEnumerator());
|
||||
|
||||
IEnumerator<KeyValuePair<string, object>> IEnumerable<KeyValuePair<string, object>>.GetEnumerator() => new TagsEnumerator(this.enumerable.GetEnumerator());
|
||||
|
||||
private struct TagsEnumerator : IDisposable, IEnumerator<KeyValuePair<string, object>>
|
||||
{
|
||||
private IEnumerator<KeyValuePair<string, string>> enumerator;
|
||||
|
||||
public TagsEnumerator(IEnumerator<KeyValuePair<string, string>> enumerator) => this.enumerator = enumerator;
|
||||
|
||||
KeyValuePair<string, object> IEnumerator<KeyValuePair<string, object>>.Current => new KeyValuePair<string, object>(this.enumerator.Current.Key, (object)this.enumerator.Current.Value);
|
||||
|
||||
object IEnumerator.Current => new KeyValuePair<string, object>(this.enumerator.Current.Key, (object)this.enumerator.Current.Value);
|
||||
|
||||
public void Dispose() => this.enumerator.Dispose();
|
||||
|
||||
public bool MoveNext() => this.enumerator.MoveNext();
|
||||
|
||||
public void Reset() => this.enumerator.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="ActivitySampler.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="Sampler.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -20,7 +20,7 @@ namespace OpenTelemetry.Trace
|
|||
/// <summary>
|
||||
/// Sampler to select data to be exported. This sampler executes before Activity object is created.
|
||||
/// </summary>
|
||||
public abstract class ActivitySampler
|
||||
public abstract class Sampler
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the sampler description.
|
||||
|
|
@ -31,10 +31,10 @@ namespace OpenTelemetry.Trace
|
|||
/// Checks whether activity needs to be created and tracked.
|
||||
/// </summary>
|
||||
/// <param name="samplingParameters">
|
||||
/// The <see cref="ActivitySamplingParameters"/> used by the <see cref="ActivitySampler"/>
|
||||
/// The <see cref="SamplingParameters"/> used by the <see cref="Sampler"/>
|
||||
/// to decide if the <see cref="Activity"/> to be created is going to be sampled or not.
|
||||
/// </param>
|
||||
/// <returns>Sampling decision on whether activity needs to be sampled or not.</returns>
|
||||
public abstract SamplingResult ShouldSample(in ActivitySamplingParameters samplingParameters);
|
||||
public abstract SamplingResult ShouldSample(in SamplingParameters samplingParameters);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="AlwaysOffActivitySampler.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="AlwaysOffSampler.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -19,13 +19,13 @@ namespace OpenTelemetry.Trace.Samplers
|
|||
/// <summary>
|
||||
/// Sampler implementation which never samples any activity.
|
||||
/// </summary>
|
||||
public sealed class AlwaysOffActivitySampler : ActivitySampler
|
||||
public sealed class AlwaysOffSampler : Sampler
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Description { get; } = "AlwaysOffSampler";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SamplingResult ShouldSample(in ActivitySamplingParameters samplingParameters)
|
||||
public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
|
||||
{
|
||||
return new SamplingResult(false);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="AlwaysOnActivitySampler.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="AlwaysOnSampler.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -20,13 +20,13 @@ namespace OpenTelemetry.Trace.Samplers
|
|||
/// Sampler implementation which samples every activity.
|
||||
/// This sampler will be used as the default Sampler, if no other Sampler is configured.
|
||||
/// </summary>
|
||||
public sealed class AlwaysOnActivitySampler : ActivitySampler
|
||||
public sealed class AlwaysOnSampler : Sampler
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Description { get; } = "AlwaysOnSampler";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SamplingResult ShouldSample(in ActivitySamplingParameters samplingParameters)
|
||||
public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
|
||||
{
|
||||
return new SamplingResult(true);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="ParentOrElseActivitySampler.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="ParentOrElseSampler.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -22,15 +22,15 @@ namespace OpenTelemetry.Trace.Samplers
|
|||
/// Sampler implementation which will take a sample if parent Activity or any linked Activity is sampled.
|
||||
/// Otherwise, samples root traces according to the specified delegate sampler.
|
||||
/// </summary>
|
||||
public sealed class ParentOrElseActivitySampler : ActivitySampler
|
||||
public sealed class ParentOrElseSampler : Sampler
|
||||
{
|
||||
private readonly ActivitySampler delegateSampler;
|
||||
private readonly Sampler delegateSampler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ParentOrElseActivitySampler"/> class.
|
||||
/// Initializes a new instance of the <see cref="ParentOrElseSampler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="delegateSampler">The <see cref="ActivitySampler"/> to be called to decide whether or not to sample a root trace.</param>
|
||||
public ParentOrElseActivitySampler(ActivitySampler delegateSampler)
|
||||
/// <param name="delegateSampler">The <see cref="Sampler"/> to be called to decide whether or not to sample a root trace.</param>
|
||||
public ParentOrElseSampler(Sampler delegateSampler)
|
||||
{
|
||||
this.delegateSampler = delegateSampler ?? throw new ArgumentNullException(nameof(delegateSampler));
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ namespace OpenTelemetry.Trace.Samplers
|
|||
public override string Description { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SamplingResult ShouldSample(in ActivitySamplingParameters samplingParameters)
|
||||
public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
|
||||
{
|
||||
var parentContext = samplingParameters.ParentContext;
|
||||
if (parentContext == default)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="ProbabilityActivitySampler.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="ProbabilitySampler.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -21,18 +21,18 @@ namespace OpenTelemetry.Trace.Samplers
|
|||
/// <summary>
|
||||
/// Samples traces according to the specified probability.
|
||||
/// </summary>
|
||||
public sealed class ProbabilityActivitySampler : ActivitySampler
|
||||
public sealed class ProbabilitySampler : Sampler
|
||||
{
|
||||
private readonly long idUpperBound;
|
||||
private readonly double probability;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ProbabilityActivitySampler"/> class.
|
||||
/// Initializes a new instance of the <see cref="ProbabilitySampler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="probability">The desired probability of sampling. This must be between 0.0 and 1.0.
|
||||
/// Higher the value, higher is the probability of a given Activity to be sampled in.
|
||||
/// </param>
|
||||
public ProbabilityActivitySampler(double probability)
|
||||
public ProbabilitySampler(double probability)
|
||||
{
|
||||
if (probability < 0.0 || probability > 1.0)
|
||||
{
|
||||
|
|
@ -66,7 +66,7 @@ namespace OpenTelemetry.Trace.Samplers
|
|||
public override string Description { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SamplingResult ShouldSample(in ActivitySamplingParameters samplingParameters)
|
||||
public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
|
||||
{
|
||||
// Always sample if we are within probability range. This is true even for child activities (that
|
||||
// may have had a different sampling decision made) to allow for different sampling policies,
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="ActivitySamplingParameters.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="SamplingParameters.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -19,12 +19,12 @@ using System.Diagnostics;
|
|||
namespace OpenTelemetry.Trace
|
||||
{
|
||||
/// <summary>
|
||||
/// Sampling parameters passed to an <see cref="ActivitySampler"/> for it to make a sampling decision.
|
||||
/// Sampling parameters passed to an <see cref="Sampler"/> for it to make a sampling decision.
|
||||
/// </summary>
|
||||
public readonly struct ActivitySamplingParameters
|
||||
public readonly struct SamplingParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ActivitySamplingParameters"/> struct.
|
||||
/// Initializes a new instance of the <see cref="SamplingParameters"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="parentContext">Parent activity context. Typically taken from the wire.</param>
|
||||
/// <param name="traceId">Trace ID of a activity to be created.</param>
|
||||
|
|
@ -36,7 +36,7 @@ namespace OpenTelemetry.Trace
|
|||
/// <param name="kind">The kind of the Activity to be created.</param>
|
||||
/// <param name="tags">Initial set of Tags for the Activity being constructed.</param>
|
||||
/// <param name="links">Links associated with the activity.</param>
|
||||
public ActivitySamplingParameters(
|
||||
public SamplingParameters(
|
||||
ActivityContext parentContext,
|
||||
ActivityTraceId traceId,
|
||||
string name,
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
// <copyright file="EvictingQueueTests.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System.Linq;
|
||||
using OpenTelemetry.Trace.Internal;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Tests
|
||||
{
|
||||
public class EvictingQueueTests
|
||||
{
|
||||
[Fact]
|
||||
public void NoEviction_Max()
|
||||
{
|
||||
var eq = new EvictingQueue<int>(4);
|
||||
Assert.Equal(0, eq.Count);
|
||||
Assert.Equal(0, eq.DroppedItems);
|
||||
|
||||
eq.Add(0);
|
||||
Assert.Equal(1, eq.Count);
|
||||
Assert.Equal(0, eq.DroppedItems);
|
||||
eq.Add(1);
|
||||
Assert.Equal(2, eq.Count);
|
||||
Assert.Equal(0, eq.DroppedItems);
|
||||
eq.Add(2);
|
||||
Assert.Equal(3, eq.Count);
|
||||
Assert.Equal(0, eq.DroppedItems);
|
||||
eq.Add(3);
|
||||
Assert.Equal(4, eq.Count);
|
||||
Assert.Equal(0, eq.DroppedItems);
|
||||
|
||||
var items = eq.ToArray();
|
||||
Assert.Equal(4, items.Length);
|
||||
Assert.Equal(0, items[0]);
|
||||
Assert.Equal(1, items[1]);
|
||||
Assert.Equal(2, items[2]);
|
||||
Assert.Equal(3, items[3]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoEviction()
|
||||
{
|
||||
var eq = new EvictingQueue<int>(4) { 0, 1, 2 };
|
||||
|
||||
var items = eq.ToArray();
|
||||
Assert.Equal(3, items.Length);
|
||||
Assert.Equal(0, items[0]);
|
||||
Assert.Equal(1, items[1]);
|
||||
Assert.Equal(2, items[2]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Eviction()
|
||||
{
|
||||
var eq = new EvictingQueue<int>(4) { 0, 1, 2, 3, 4 };
|
||||
Assert.Equal(4, eq.Count);
|
||||
Assert.Equal(1, eq.DroppedItems);
|
||||
|
||||
var items = eq.ToArray();
|
||||
Assert.Equal(4, items.Length);
|
||||
Assert.Equal(1, items[0]);
|
||||
Assert.Equal(2, items[1]);
|
||||
Assert.Equal(3, items[2]);
|
||||
Assert.Equal(4, items[3]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MaxItems0()
|
||||
{
|
||||
var eq = new EvictingQueue<int>(0) { 0 };
|
||||
Assert.Equal(0, eq.Count);
|
||||
Assert.Equal(1, eq.DroppedItems);
|
||||
|
||||
Assert.Empty(eq);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Replacing()
|
||||
{
|
||||
var eq = new EvictingQueue<int>(1) { 0 };
|
||||
eq.Replace(0, 1);
|
||||
|
||||
var items = eq.ToArray();
|
||||
|
||||
Assert.Equal(1, items[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoReplacing()
|
||||
{
|
||||
var eq = new EvictingQueue<int>(1) { 0 };
|
||||
eq.Replace(1, 1);
|
||||
|
||||
var items = eq.ToArray();
|
||||
|
||||
Assert.Equal(0, items[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -95,15 +95,15 @@ namespace OpenTelemetry.Tests.Implementation.Trace
|
|||
}
|
||||
}
|
||||
|
||||
private class TestSampler : ActivitySampler
|
||||
private class TestSampler : Sampler
|
||||
{
|
||||
public SamplingResult DesiredSamplingResult { get; set; }
|
||||
|
||||
public ActivitySamplingParameters LatestSamplingParameters { get; private set; }
|
||||
public SamplingParameters LatestSamplingParameters { get; private set; }
|
||||
|
||||
public override string Description { get; } = nameof(TestSampler);
|
||||
|
||||
public override SamplingResult ShouldSample(in ActivitySamplingParameters samplingParameters)
|
||||
public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
|
||||
{
|
||||
this.LatestSamplingParameters = samplingParameters;
|
||||
return this.DesiredSamplingResult;
|
||||
|
|
|
|||
|
|
@ -181,13 +181,13 @@ namespace OpenTelemetry.Tests.Implementation.Trace
|
|||
Activity.Current = null;
|
||||
}
|
||||
|
||||
private class TestSampler : ActivitySampler
|
||||
private class TestSampler : Sampler
|
||||
{
|
||||
public Func<ActivitySamplingParameters, SamplingResult> SamplingAction { get; set; }
|
||||
public Func<SamplingParameters, SamplingResult> SamplingAction { get; set; }
|
||||
|
||||
public override string Description { get; } = nameof(TestSampler);
|
||||
|
||||
public override SamplingResult ShouldSample(in ActivitySamplingParameters samplingParameters)
|
||||
public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
|
||||
{
|
||||
return this.SamplingAction?.Invoke(samplingParameters) ?? new SamplingResult(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
using var activityProcessor = new BatchingActivityProcessor(activityExporter, 128, TimeSpan.FromMilliseconds(0), TimeSpan.FromMilliseconds(0), 1);
|
||||
using var openTelemetrySdk = OpenTelemetrySdk.EnableOpenTelemetry(b => b
|
||||
.AddActivitySource(ActivitySourceName)
|
||||
.SetSampler(new AlwaysOnActivitySampler())
|
||||
.SetSampler(new AlwaysOnSampler())
|
||||
.AddProcessorPipeline(pp => pp.AddProcessor(ap => activityProcessor)));
|
||||
|
||||
var activity1 = this.CreateActivity(ActivityName1);
|
||||
|
|
@ -95,7 +95,7 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
using var activityProcessor = new BatchingActivityProcessor(activityExporter, 128, DefaultDelay, DefaultTimeout, 128);
|
||||
using var openTelemetrySdk = OpenTelemetrySdk.EnableOpenTelemetry(b => b
|
||||
.AddActivitySource(ActivitySourceName)
|
||||
.SetSampler(new AlwaysOnActivitySampler())
|
||||
.SetSampler(new AlwaysOnSampler())
|
||||
.AddProcessorPipeline(pp => pp.AddProcessor(ap => activityProcessor)));
|
||||
|
||||
var activity1 = this.CreateActivity(ActivityName1);
|
||||
|
|
@ -123,7 +123,7 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
using var activityProcessor = new BatchingActivityProcessor(activityExporter, 128, TimeSpan.FromMilliseconds(30), DefaultTimeout, 10);
|
||||
using var openTelemetrySdk = OpenTelemetrySdk.EnableOpenTelemetry(b => b
|
||||
.AddActivitySource(ActivitySourceName)
|
||||
.SetSampler(new AlwaysOnActivitySampler())
|
||||
.SetSampler(new AlwaysOnSampler())
|
||||
.AddProcessorPipeline(pp => pp.AddProcessor(ap => activityProcessor)));
|
||||
|
||||
var activities = new List<Activity>();
|
||||
|
|
@ -151,7 +151,7 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
using var activityProcessor = new BatchingActivityProcessor(activityExporter, 1, TimeSpan.FromMilliseconds(100), DefaultTimeout, 1);
|
||||
using var openTelemetrySdk = OpenTelemetrySdk.EnableOpenTelemetry(b => b
|
||||
.AddActivitySource(ActivitySourceName)
|
||||
.SetSampler(new AlwaysOnActivitySampler())
|
||||
.SetSampler(new AlwaysOnSampler())
|
||||
.AddProcessorPipeline(pp => pp.AddProcessor(ap => activityProcessor)));
|
||||
|
||||
var activities = new List<Activity>();
|
||||
|
|
@ -181,7 +181,7 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
using var activityProcessor = new BatchingActivityProcessor(activityExporter, 128, DefaultDelay, DefaultTimeout, 3);
|
||||
using var openTelemetrySdk = OpenTelemetrySdk.EnableOpenTelemetry(b => b
|
||||
.AddActivitySource(ActivitySourceName)
|
||||
.SetSampler(new AlwaysOnActivitySampler())
|
||||
.SetSampler(new AlwaysOnSampler())
|
||||
.AddProcessorPipeline(pp => pp.AddProcessor(ap => activityProcessor)));
|
||||
|
||||
var activity1 = this.CreateActivity(ActivityName1);
|
||||
|
|
@ -214,7 +214,7 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
var activityExporter = new TestActivityExporter(_ => Interlocked.Increment(ref exportCalledCount));
|
||||
using var activityProcessor = new BatchingActivityProcessor(activityExporter, 128, DefaultDelay, DefaultTimeout, 1);
|
||||
using var openTelemetrySdk = OpenTelemetrySdk.EnableOpenTelemetry(b => b
|
||||
.SetSampler(new AlwaysOffActivitySampler())
|
||||
.SetSampler(new AlwaysOffSampler())
|
||||
.AddActivitySource(ActivitySourceName)
|
||||
.AddProcessorPipeline(pp => pp.AddProcessor(ap => activityProcessor)));
|
||||
|
||||
|
|
@ -243,7 +243,7 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
|
||||
using var openTelemetrySdk = OpenTelemetrySdk.EnableOpenTelemetry(b => b
|
||||
.AddActivitySource(ActivitySourceName)
|
||||
.SetSampler(new AlwaysOnActivitySampler())
|
||||
.SetSampler(new AlwaysOnSampler())
|
||||
.AddProcessorPipeline(pp => pp.AddProcessor(ap => activityProcessor)));
|
||||
|
||||
var activity = Source.StartActivity("foo");
|
||||
|
|
@ -272,7 +272,7 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
new BatchingActivityProcessor(activityExporter, 128, TimeSpan.FromMilliseconds(100), DefaultTimeout, batchSize);
|
||||
using (var openTelemetrySdk = OpenTelemetrySdk.EnableOpenTelemetry(b => b
|
||||
.AddActivitySource(ActivitySourceName)
|
||||
.SetSampler(new AlwaysOnActivitySampler())
|
||||
.SetSampler(new AlwaysOnSampler())
|
||||
.AddProcessorPipeline(pp => pp.AddProcessor(ap => activityProcessor))))
|
||||
{
|
||||
using var inMemoryEventListener = new InMemoryEventListener();
|
||||
|
|
@ -324,7 +324,7 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
new BatchingActivityProcessor(activityExporter, 128, TimeSpan.FromMilliseconds(100), DefaultTimeout, batchSize);
|
||||
using (var openTelemetrySdk = OpenTelemetrySdk.EnableOpenTelemetry(b => b
|
||||
.AddActivitySource(ActivitySourceName)
|
||||
.SetSampler(new AlwaysOnActivitySampler())
|
||||
.SetSampler(new AlwaysOnSampler())
|
||||
.AddProcessorPipeline(pp => pp.AddProcessor(ap => activityProcessor))))
|
||||
{
|
||||
var activities = new List<Activity>();
|
||||
|
|
@ -355,7 +355,7 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
using var activityProcessor = new BatchingActivityProcessor(activityExporter, 128, TimeSpan.FromMilliseconds(100), DefaultTimeout, batchSize);
|
||||
using (var openTelemetrySdk = OpenTelemetrySdk.EnableOpenTelemetry(b => b
|
||||
.AddActivitySource(ActivitySourceName)
|
||||
.SetSampler(new AlwaysOnActivitySampler())
|
||||
.SetSampler(new AlwaysOnSampler())
|
||||
.AddProcessorPipeline(pp => pp.AddProcessor(ap => activityProcessor))))
|
||||
{
|
||||
using var inMemoryEventListener = new InMemoryEventListener();
|
||||
|
|
@ -400,7 +400,7 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
{
|
||||
using var openTelemetrySdk = OpenTelemetrySdk.EnableOpenTelemetry(b => b
|
||||
.AddActivitySource(ActivitySourceName)
|
||||
.SetSampler(new AlwaysOnActivitySampler())
|
||||
.SetSampler(new AlwaysOnSampler())
|
||||
.AddProcessorPipeline(pp => pp.AddProcessor(ap => batchingActivityProcessor)));
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
.AddProcessorPipeline(p => p
|
||||
.SetExporter(this.activityExporter)
|
||||
.SetExportingProcessor(e => new SimpleActivityProcessor(e)))
|
||||
.SetSampler(new AlwaysOnActivitySampler()));
|
||||
.SetSampler(new AlwaysOnSampler()));
|
||||
this.activitySource = new ActivitySource(ActivitySourceName);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
var link = new ActivityLink(parentContext);
|
||||
|
||||
Assert.True(
|
||||
new AlwaysOnActivitySampler()
|
||||
.ShouldSample(new ActivitySamplingParameters(
|
||||
new AlwaysOnSampler()
|
||||
.ShouldSample(new SamplingParameters(
|
||||
parentContext,
|
||||
this.traceId,
|
||||
"Another name",
|
||||
|
|
@ -55,7 +55,7 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
[Fact]
|
||||
public void AlwaysOnSampler_GetDescription()
|
||||
{
|
||||
Assert.Equal("AlwaysOnSampler", new AlwaysOnActivitySampler().Description);
|
||||
Assert.Equal("AlwaysOnSampler", new AlwaysOnSampler().Description);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -67,8 +67,8 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
var link = new ActivityLink(parentContext);
|
||||
|
||||
Assert.False(
|
||||
new AlwaysOffActivitySampler()
|
||||
.ShouldSample(new ActivitySamplingParameters(
|
||||
new AlwaysOffSampler()
|
||||
.ShouldSample(new SamplingParameters(
|
||||
parentContext,
|
||||
this.traceId,
|
||||
"Another name",
|
||||
|
|
@ -80,7 +80,7 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
[Fact]
|
||||
public void AlwaysOffSampler_GetDescription()
|
||||
{
|
||||
Assert.Equal("AlwaysOffSampler", new AlwaysOffActivitySampler().Description);
|
||||
Assert.Equal("AlwaysOffSampler", new AlwaysOffSampler().Description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
{
|
||||
public class ParentOrElseSamplerTests
|
||||
{
|
||||
private readonly ParentOrElseActivitySampler parentOrElseAlwaysOnSampler = new ParentOrElseActivitySampler(new AlwaysOnActivitySampler());
|
||||
private readonly ParentOrElseActivitySampler parentOrElseAlwaysOffSampler = new ParentOrElseActivitySampler(new AlwaysOffActivitySampler());
|
||||
private readonly ParentOrElseSampler parentOrElseAlwaysOnSampler = new ParentOrElseSampler(new AlwaysOnSampler());
|
||||
private readonly ParentOrElseSampler parentOrElseAlwaysOffSampler = new ParentOrElseSampler(new AlwaysOffSampler());
|
||||
|
||||
[Fact]
|
||||
public void ParentOrElseSampler_SampledParent()
|
||||
|
|
@ -42,7 +42,7 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
Assert.Equal(
|
||||
new SamplingResult(false),
|
||||
this.parentOrElseAlwaysOnSampler.ShouldSample(
|
||||
new ActivitySamplingParameters(
|
||||
new SamplingParameters(
|
||||
parentContext: new ActivityContext(
|
||||
ActivityTraceId.CreateRandom(),
|
||||
ActivitySpanId.CreateRandom(),
|
||||
|
|
@ -55,7 +55,7 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
Assert.Equal(
|
||||
new SamplingResult(true),
|
||||
this.parentOrElseAlwaysOffSampler.ShouldSample(
|
||||
new ActivitySamplingParameters(
|
||||
new SamplingParameters(
|
||||
parentContext: new ActivityContext(
|
||||
ActivityTraceId.CreateRandom(),
|
||||
ActivitySpanId.CreateRandom(),
|
||||
|
|
@ -95,7 +95,7 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
Assert.Equal(
|
||||
new SamplingResult(false),
|
||||
this.parentOrElseAlwaysOnSampler.ShouldSample(
|
||||
new ActivitySamplingParameters(
|
||||
new SamplingParameters(
|
||||
parentContext: notSampledParent,
|
||||
traceId: default,
|
||||
name: "Span",
|
||||
|
|
@ -106,7 +106,7 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
Assert.Equal(
|
||||
new SamplingResult(true),
|
||||
this.parentOrElseAlwaysOffSampler.ShouldSample(
|
||||
new ActivitySamplingParameters(
|
||||
new SamplingParameters(
|
||||
parentContext: notSampledParent,
|
||||
traceId: default,
|
||||
name: "Span",
|
||||
|
|
|
|||
|
|
@ -27,19 +27,19 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
[Fact]
|
||||
public void ProbabilitySampler_OutOfRangeHighProbability()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new ProbabilityActivitySampler(1.01));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new ProbabilitySampler(1.01));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProbabilitySampler_OutOfRangeLowProbability()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new ProbabilityActivitySampler(-0.00001));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new ProbabilitySampler(-0.00001));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProbabilitySampler_SampleBasedOnTraceId()
|
||||
{
|
||||
ActivitySampler defaultProbability = new ProbabilityActivitySampler(0.0001);
|
||||
Sampler defaultProbability = new ProbabilitySampler(0.0001);
|
||||
|
||||
// This traceId will not be sampled by the ProbabilityActivitySampler because the first 8 bytes as long
|
||||
// is not less than probability * Long.MAX_VALUE;
|
||||
|
|
@ -65,7 +65,7 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
0,
|
||||
});
|
||||
Assert.False(
|
||||
defaultProbability.ShouldSample(new ActivitySamplingParameters(
|
||||
defaultProbability.ShouldSample(new SamplingParameters(
|
||||
default,
|
||||
notSampledtraceId,
|
||||
ActivityDisplayName,
|
||||
|
|
@ -97,7 +97,7 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
0,
|
||||
});
|
||||
Assert.True(
|
||||
defaultProbability.ShouldSample(new ActivitySamplingParameters(
|
||||
defaultProbability.ShouldSample(new SamplingParameters(
|
||||
default,
|
||||
sampledtraceId,
|
||||
ActivityDisplayName,
|
||||
|
|
@ -110,7 +110,7 @@ namespace OpenTelemetry.Trace.Samplers.Test
|
|||
public void ProbabilitySampler_GetDescription()
|
||||
{
|
||||
var expectedDescription = "ProbabilityActivitySampler{0.500000}";
|
||||
Assert.Equal(expectedDescription, new ProbabilityActivitySampler(0.5).Description);
|
||||
Assert.Equal(expectedDescription, new ProbabilitySampler(0.5).Description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue