SpanCreationOptions.Attributes changed to IEnumerable from IDictionary (#626)
* Remove non-working example from readme * revert unintended changes * SpanCreationOptions.Attributes changed to IEnumerable Fix 588 * try tareks suggestion * Fix builds * revert unwanted changes Co-authored-by: Sergey Kanzhelev <S.Kanzhelev@live.com>
This commit is contained in:
parent
78324b98df
commit
e56ee5d46b
|
|
@ -38,7 +38,7 @@ namespace OpenTelemetry.Trace
|
|||
/// <summary>
|
||||
/// Gets or sets attributes known prior to span creation.
|
||||
/// </summary>
|
||||
public IDictionary<string, object> Attributes { get; set; }
|
||||
public IEnumerable<KeyValuePair<string, object>> Attributes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets Links factory. Use it to deserialize list of <see cref="Link"/> lazily
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
// <copyright file="TagsCollection.cs" company="OpenTelemetry Authors">
|
||||
// Copyright 2018, 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -43,6 +43,6 @@ namespace OpenTelemetry.Trace
|
|||
/// <param name="attributes">Initial set of Attributes for the Span being constructed.</param>
|
||||
/// <param name="links">Links associated with the span.</param>
|
||||
/// <returns>Sampling decision on whether Span needs to be sampled or not.</returns>
|
||||
public abstract SamplingResult ShouldSample(in SpanContext parentContext, in ActivityTraceId traceId, in ActivitySpanId spanId, string name, SpanKind spanKind, IDictionary<string, object> attributes, IEnumerable<Link> links);
|
||||
public abstract SamplingResult ShouldSample(in SpanContext parentContext, in ActivityTraceId traceId, in ActivitySpanId spanId, string name, SpanKind spanKind, IEnumerable<KeyValuePair<string, object>> attributes, IEnumerable<Link> links);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace OpenTelemetry.Trace.Samplers
|
|||
public override string Description { get; } = nameof(AlwaysOffSampler);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SamplingResult ShouldSample(in SpanContext parentContext, in ActivityTraceId traceId, in ActivitySpanId spanId, string name, SpanKind spanKind, IDictionary<string, object> attributes, IEnumerable<Link> links)
|
||||
public override SamplingResult ShouldSample(in SpanContext parentContext, in ActivityTraceId traceId, in ActivitySpanId spanId, string name, SpanKind spanKind, IEnumerable<KeyValuePair<string, object>> attributes, IEnumerable<Link> links)
|
||||
{
|
||||
return new SamplingResult(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace OpenTelemetry.Trace.Samplers
|
|||
public override string Description { get; } = nameof(AlwaysOnSampler);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SamplingResult ShouldSample(in SpanContext parentContext, in ActivityTraceId traceId, in ActivitySpanId spanId, string name, SpanKind spanKind, IDictionary<string, object> attributes, IEnumerable<Link> parentLinks)
|
||||
public override SamplingResult ShouldSample(in SpanContext parentContext, in ActivityTraceId traceId, in ActivitySpanId spanId, string name, SpanKind spanKind, IEnumerable<KeyValuePair<string, object>> attributes, IEnumerable<Link> parentLinks)
|
||||
{
|
||||
return new SamplingResult(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace OpenTelemetry.Trace.Samplers
|
|||
public override string Description { get; } = nameof(AlwaysParentSampler);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SamplingResult ShouldSample(in SpanContext parentContext, in ActivityTraceId traceId, in ActivitySpanId spanId, string name, SpanKind spanKind, IDictionary<string, object> attributes, IEnumerable<Link> parentLinks)
|
||||
public override SamplingResult ShouldSample(in SpanContext parentContext, in ActivityTraceId traceId, in ActivitySpanId spanId, string name, SpanKind spanKind, IEnumerable<KeyValuePair<string, object>> attributes, IEnumerable<Link> parentLinks)
|
||||
{
|
||||
if (parentContext.IsValid && parentContext.TraceFlags.HasFlag(ActivityTraceFlags.Recorded))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ namespace OpenTelemetry.Trace.Samplers
|
|||
public override string Description { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SamplingResult ShouldSample(in SpanContext parentContext, in ActivityTraceId traceId, in ActivitySpanId spanId, string name, SpanKind spanKind, IDictionary<string, object> attributes, IEnumerable<Link> links)
|
||||
public override SamplingResult ShouldSample(in SpanContext parentContext, in ActivityTraceId traceId, in ActivitySpanId spanId, string name, SpanKind spanKind, IEnumerable<KeyValuePair<string, object>> attributes, IEnumerable<Link> links)
|
||||
{
|
||||
// If the parent is sampled keep the sampling decision.
|
||||
if (parentContext.IsValid &&
|
||||
|
|
|
|||
|
|
@ -620,7 +620,7 @@ namespace OpenTelemetry.Trace
|
|||
{
|
||||
spanCreationOptions = new SpanCreationOptions
|
||||
{
|
||||
Attributes = activity.Tags.ToDictionary(k => k.Key, v => (object)v.Value),
|
||||
Attributes = new TagsCollection(activity.Tags),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -674,7 +674,7 @@ namespace OpenTelemetry.Trace
|
|||
SpanContext parent,
|
||||
string name,
|
||||
SpanKind spanKind,
|
||||
IDictionary<string, object> attributes,
|
||||
IEnumerable<KeyValuePair<string, object>> attributes,
|
||||
IEnumerable<Link> parentLinks,
|
||||
ActivityTraceId traceId,
|
||||
ActivitySpanId spanId,
|
||||
|
|
|
|||
Loading…
Reference in New Issue