From bfb4228092486ea432dfb6cfd49b8096e89469a6 Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Thu, 20 Aug 2020 19:35:55 -0300 Subject: [PATCH 1/9] Updating to use SpanAttributes --- src/OpenTelemetry.Api/Trace/Link.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Api/Trace/Link.cs b/src/OpenTelemetry.Api/Trace/Link.cs index ac494fef1fa..2ad4a163099 100644 --- a/src/OpenTelemetry.Api/Trace/Link.cs +++ b/src/OpenTelemetry.Api/Trace/Link.cs @@ -40,9 +40,9 @@ public Link(in SpanContext spanContext) /// /// Span context of a linked span. /// Link attributes. - public Link(in SpanContext spanContext, ActivityTagsCollection attributes) + public Link(in SpanContext spanContext, SpanAttributes attributes) { - this.ActivityLink = new ActivityLink(spanContext.ActivityContext, attributes); + this.ActivityLink = new ActivityLink(spanContext.ActivityContext, attributes.Attributes); } /// From aad66ef7c1d30432f6287bdc3fb3d481f0e02697 Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Thu, 20 Aug 2020 19:39:10 -0300 Subject: [PATCH 2/9] updating link tests --- test/OpenTelemetry.Tests/Trace/LinkTest.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/OpenTelemetry.Tests/Trace/LinkTest.cs b/test/OpenTelemetry.Tests/Trace/LinkTest.cs index 5673c61a887..2a9b93bb9e6 100644 --- a/test/OpenTelemetry.Tests/Trace/LinkTest.cs +++ b/test/OpenTelemetry.Tests/Trace/LinkTest.cs @@ -24,7 +24,7 @@ public class LinkTest : IDisposable { private readonly IDictionary attributesMap = new Dictionary(); private readonly SpanContext spanContext; - private readonly ActivityTagsCollection tags; + private readonly SpanAttributes tags; public LinkTest() { @@ -34,7 +34,11 @@ public LinkTest() this.attributesMap.Add("MyAttributeKey1", 10L); this.attributesMap.Add("MyAttributeKey2", true); this.attributesMap.Add("MyAttributeKey3", 0.005); - this.tags = new ActivityTagsCollection(this.attributesMap); + this.tags = new SpanAttributes(); + this.tags.Add("MyAttributeKey0", "MyStringAttribute"); + this.tags.Add("MyAttributeKey1", 10L); + this.tags.Add("MyAttributeKey2", true); + this.tags.Add("MyAttributeKey3", 0.005); } [Fact] @@ -91,7 +95,7 @@ public void NotEquality() [Fact] public void NotEquality_WithAttributes() { - var tag1 = new ActivityTagsCollection(new Dictionary()); + var tag1 = new SpanAttributes(); var tag2 = this.tags; var link1 = new Link(this.spanContext, tag1); var link2 = new Link(this.spanContext, tag2); From c83eaeb7654d8cdef43288e3e9ed3a873993db1b Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Thu, 20 Aug 2020 20:20:20 -0300 Subject: [PATCH 3/9] adding changelog and testing all supported types --- src/OpenTelemetry.Api/CHANGELOG.md | 2 ++ test/OpenTelemetry.Tests/Trace/LinkTest.cs | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Api/CHANGELOG.md b/src/OpenTelemetry.Api/CHANGELOG.md index 1d93745268b..1ada43c91fe 100644 --- a/src/OpenTelemetry.Api/CHANGELOG.md +++ b/src/OpenTelemetry.Api/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +* `Link` is using `SpanAttributes` instead of `ActivityCollect` + ([#1120](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1120)) * `PropagationContext` is now used instead of `ActivityContext` in the `ITextFormat` API ([#1048](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1048)) diff --git a/test/OpenTelemetry.Tests/Trace/LinkTest.cs b/test/OpenTelemetry.Tests/Trace/LinkTest.cs index 2a9b93bb9e6..465eea877e9 100644 --- a/test/OpenTelemetry.Tests/Trace/LinkTest.cs +++ b/test/OpenTelemetry.Tests/Trace/LinkTest.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using Xunit; namespace OpenTelemetry.Trace.Tests @@ -34,11 +35,19 @@ public LinkTest() this.attributesMap.Add("MyAttributeKey1", 10L); this.attributesMap.Add("MyAttributeKey2", true); this.attributesMap.Add("MyAttributeKey3", 0.005); + this.attributesMap.Add("MyAttributeKey4", new long[] { 1, 2 }); + this.attributesMap.Add("MyAttributeKey5", new string[] { "a", "b" }); + this.attributesMap.Add("MyAttributeKey6", new bool[] { true, false }); + this.attributesMap.Add("MyAttributeKey7", new double[] { 0.1, -0.1 }); this.tags = new SpanAttributes(); this.tags.Add("MyAttributeKey0", "MyStringAttribute"); this.tags.Add("MyAttributeKey1", 10L); this.tags.Add("MyAttributeKey2", true); this.tags.Add("MyAttributeKey3", 0.005); + this.tags.Add("MyAttributeKey4", new long[] { 1, 2 }); + this.tags.Add("MyAttributeKey5", new string[] { "a", "b" }); + this.tags.Add("MyAttributeKey6", new bool[] { true, false }); + this.tags.Add("MyAttributeKey7", new double[] { 0.1, -0.1 }); } [Fact] @@ -55,7 +64,11 @@ public void FromSpanContext_WithAttributes() var link = new Link(this.spanContext, this.tags); Assert.Equal(this.spanContext.TraceId, link.Context.TraceId); Assert.Equal(this.spanContext.SpanId, link.Context.SpanId); - Assert.Equal(this.attributesMap, link.Attributes); + + foreach (var attributemap in this.attributesMap) + { + Assert.Equal(attributemap.Value, link.Attributes.FirstOrDefault(a => a.Key == attributemap.Key).Value); + } } [Fact] From a2dad3fb655431a44f5bbb1759b189c7b48a8269 Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Thu, 20 Aug 2020 21:18:08 -0300 Subject: [PATCH 4/9] Update CHANGELOG.md --- src/OpenTelemetry.Api/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Api/CHANGELOG.md b/src/OpenTelemetry.Api/CHANGELOG.md index 1ada43c91fe..c3593a0c1a9 100644 --- a/src/OpenTelemetry.Api/CHANGELOG.md +++ b/src/OpenTelemetry.Api/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -* `Link` is using `SpanAttributes` instead of `ActivityCollect` +* `Link` is using `SpanAttributes` instead of `ActivityTagsCollection ` ([#1120](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1120)) * `PropagationContext` is now used instead of `ActivityContext` in the `ITextFormat` API From 001b8250f8652107417296aa2f3753ade4f98c6c Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Thu, 20 Aug 2020 21:19:43 -0300 Subject: [PATCH 5/9] updating changelog --- src/OpenTelemetry.Api/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Api/CHANGELOG.md b/src/OpenTelemetry.Api/CHANGELOG.md index c3593a0c1a9..b2373b69e9b 100644 --- a/src/OpenTelemetry.Api/CHANGELOG.md +++ b/src/OpenTelemetry.Api/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -* `Link` is using `SpanAttributes` instead of `ActivityTagsCollection ` +* `Link` is using `SpanAttributes` instead of `ActivityTagsCollection` ([#1120](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1120)) * `PropagationContext` is now used instead of `ActivityContext` in the `ITextFormat` API From 3c51b29e3640ede9c01363e06500976f82d25f3a Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Thu, 20 Aug 2020 21:35:46 -0300 Subject: [PATCH 6/9] updating TelemetrySpan --- src/OpenTelemetry.Api/Trace/TelemetrySpan.cs | 10 ++--- .../SpanShim.cs | 39 ++++++++++++++++++- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/OpenTelemetry.Api/Trace/TelemetrySpan.cs b/src/OpenTelemetry.Api/Trace/TelemetrySpan.cs index 11e97a8e26a..11226eb778c 100644 --- a/src/OpenTelemetry.Api/Trace/TelemetrySpan.cs +++ b/src/OpenTelemetry.Api/Trace/TelemetrySpan.cs @@ -236,10 +236,9 @@ public TelemetrySpan AddEvent(string name, DateTimeOffset timestamp) /// Attributes for the event. /// The instance for chaining. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TelemetrySpan AddEvent(string name, IDictionary attributes) + public TelemetrySpan AddEvent(string name, SpanAttributes attributes) { - ActivityTagsCollection eventTags = new ActivityTagsCollection(attributes); - this.Activity?.AddEvent(new ActivityEvent(name, default, eventTags)); + this.Activity?.AddEvent(new ActivityEvent(name, default, attributes.Attributes)); return this; } @@ -251,10 +250,9 @@ public TelemetrySpan AddEvent(string name, IDictionary attribute /// Attributes for the event. /// The instance for chaining. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TelemetrySpan AddEvent(string name, DateTimeOffset timestamp, IDictionary attributes) + public TelemetrySpan AddEvent(string name, DateTimeOffset timestamp, SpanAttributes attributes) { - var eventTags = new ActivityTagsCollection(attributes); - this.Activity?.AddEvent(new ActivityEvent(name, timestamp, eventTags)); + this.Activity?.AddEvent(new ActivityEvent(name, timestamp, attributes.Attributes)); return this; } diff --git a/src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs b/src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs index 6022e9c1cad..f804ebc3d31 100644 --- a/src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs +++ b/src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs @@ -94,13 +94,48 @@ public string GetBaggageItem(string key) var eventName = payload.Item1; var eventAttributes = payload.Item2; + var spanAttributes = new SpanAttributes(); + foreach (var field in fields) + { + switch (field.Value) + { + case long value: + spanAttributes.Add(field.Key, value); + break; + case long[] value: + spanAttributes.Add(field.Key, value); + break; + case bool value: + spanAttributes.Add(field.Key, value); + break; + case bool[] value: + spanAttributes.Add(field.Key, value); + break; + case double value: + spanAttributes.Add(field.Key, value); + break; + case double[] value: + spanAttributes.Add(field.Key, value); + break; + case string value: + spanAttributes.Add(field.Key, value); + break; + case string[] value: + spanAttributes.Add(field.Key, value); + break; + + default: + break; + } + } + if (timestamp == DateTimeOffset.MinValue) { - this.Span.AddEvent(eventName, eventAttributes); + this.Span.AddEvent(eventName, spanAttributes); } else { - this.Span.AddEvent(eventName, timestamp, eventAttributes); + this.Span.AddEvent(eventName, timestamp, spanAttributes); } return this; From 383442710c489387c62c82fda3e91179e2861ff3 Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Thu, 20 Aug 2020 21:38:00 -0300 Subject: [PATCH 7/9] updating changelog --- src/OpenTelemetry.Api/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Api/CHANGELOG.md b/src/OpenTelemetry.Api/CHANGELOG.md index b2373b69e9b..64bf8438970 100644 --- a/src/OpenTelemetry.Api/CHANGELOG.md +++ b/src/OpenTelemetry.Api/CHANGELOG.md @@ -2,7 +2,8 @@ ## Unreleased -* `Link` is using `SpanAttributes` instead of `ActivityTagsCollection` +* `Link` and `TelemetrySpan` are using `SpanAttributes` instead of + `ActivityTagsCollection` or `Dictionary` ([#1120](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1120)) * `PropagationContext` is now used instead of `ActivityContext` in the `ITextFormat` API From 53f8aa0cd5efe1d9517365d17b41b05b58877b26 Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Thu, 20 Aug 2020 21:50:48 -0300 Subject: [PATCH 8/9] updating to pass in tests --- src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs b/src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs index f804ebc3d31..356d7803627 100644 --- a/src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs +++ b/src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs @@ -92,10 +92,9 @@ public string GetBaggageItem(string key) var payload = ConvertToEventPayload(fields); var eventName = payload.Item1; - var eventAttributes = payload.Item2; var spanAttributes = new SpanAttributes(); - foreach (var field in fields) + foreach (var field in payload.Item2) { switch (field.Value) { From e0fc0c5edbb0da5e2adaa074e101e69e28f34c19 Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Fri, 21 Aug 2020 11:31:44 -0300 Subject: [PATCH 9/9] changing to spanAttributes --- src/OpenTelemetry.Api/Trace/TelemetrySpan.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/OpenTelemetry.Api/Trace/TelemetrySpan.cs b/src/OpenTelemetry.Api/Trace/TelemetrySpan.cs index 61036f09d10..29fb6266153 100644 --- a/src/OpenTelemetry.Api/Trace/TelemetrySpan.cs +++ b/src/OpenTelemetry.Api/Trace/TelemetrySpan.cs @@ -327,8 +327,7 @@ public TelemetrySpan RecordException(Exception ex) /// The instance for chaining. public TelemetrySpan RecordException(string type, string message, string stacktrace) { - Dictionary attributes = new Dictionary(); - + SpanAttributes attributes = new SpanAttributes(); if (!string.IsNullOrWhiteSpace(type)) { attributes.Add(SemanticConventions.AttributeExceptionType, type); @@ -344,7 +343,7 @@ public TelemetrySpan RecordException(string type, string message, string stacktr attributes.Add(SemanticConventions.AttributeExceptionMessage, message); } - if (attributes.Count != 0) + if (attributes.Attributes.Count != 0) { this.AddEvent(SemanticConventions.AttributeExceptionEventName, attributes); }