From 8c0aa8369a74ee5c266806ce3cd004d9244b2232 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Tue, 22 Mar 2022 17:37:55 -0700 Subject: [PATCH 1/7] initial --- .../JaegerActivityExtensions.cs | 114 ++++++++++++------ 1 file changed, 75 insertions(+), 39 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Jaeger/Implementation/JaegerActivityExtensions.cs b/src/OpenTelemetry.Exporter.Jaeger/Implementation/JaegerActivityExtensions.cs index d2c2d0876cc..8190e41dadc 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/Implementation/JaegerActivityExtensions.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/Implementation/JaegerActivityExtensions.cs @@ -54,6 +54,42 @@ public static JaegerSpan ToJaegerSpan(this Activity activity) activity.EnumerateTags(ref jaegerTags); + if (activity.Status != ActivityStatusCode.Unset) + { + if (activity.Status == ActivityStatusCode.Ok) + { + PooledList.Add( + ref jaegerTags.Tags, + new JaegerTag(SpanAttributeConstants.StatusCodeKey, JaegerTagType.STRING, vStr: "OK")); + } + else + { + PooledList.Add( + ref jaegerTags.Tags, + new JaegerTag(SpanAttributeConstants.StatusCodeKey, JaegerTagType.STRING, vStr: "ERROR")); + + PooledList.Add( + ref jaegerTags.Tags, + new JaegerTag(JaegerErrorFlagTagName, JaegerTagType.BOOL, vBool: true)); + } + } + else if (jaegerTags.StatusCode.HasValue && jaegerTags.StatusCode != StatusCode.Unset) + { + PooledList.Add( + ref jaegerTags.Tags, + new JaegerTag( + SpanAttributeConstants.StatusCodeKey, + JaegerTagType.STRING, + vStr: StatusHelper.GetTagValueForStatusCode(jaegerTags.StatusCode.Value))); + + if (jaegerTags.StatusCode == StatusCode.Error) + { + PooledList.Add( + ref jaegerTags.Tags, + new JaegerTag(JaegerErrorFlagTagName, JaegerTagType.BOOL, vBool: true)); + } + } + string peerServiceName = null; if (activity.Kind == ActivityKind.Client || activity.Kind == ActivityKind.Producer) { @@ -252,44 +288,6 @@ private static void ProcessJaegerTagArray(ref PooledList tags, KeyVal } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void ProcessJaegerTag(ref TagEnumerationState state, string key, JaegerTag jaegerTag) - { - if (jaegerTag.VStr != null) - { - PeerServiceResolver.InspectTag(ref state, key, jaegerTag.VStr); - - if (key == SpanAttributeConstants.StatusCodeKey) - { - StatusCode? statusCode = StatusHelper.GetStatusCodeForTagValue(jaegerTag.VStr); - if (statusCode == StatusCode.Error) - { - // Error flag: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/jaeger.md#error-flag - PooledList.Add(ref state.Tags, new JaegerTag(JaegerErrorFlagTagName, JaegerTagType.BOOL, vBool: true)); - } - else if (!statusCode.HasValue || statusCode == StatusCode.Unset) - { - // Unset Status is not sent: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/jaeger.md#status - return; - } - - // Normalize status since it is user-driven. - jaegerTag = new JaegerTag(key, JaegerTagType.STRING, vStr: StatusHelper.GetTagValueForStatusCode(statusCode.Value)); - } - else if (key == JaegerErrorFlagTagName) - { - // Ignore `error` tag if it exists, it will be added based on StatusCode + StatusDescription. - return; - } - } - else if (jaegerTag.VLong.HasValue) - { - PeerServiceResolver.InspectTag(ref state, key, jaegerTag.VLong.Value); - } - - PooledList.Add(ref state.Tags, jaegerTag); - } - private struct TagEnumerationState : IActivityEnumerator>, PeerServiceResolver.IPeerServiceState { public PooledList Tags; @@ -304,6 +302,8 @@ private struct TagEnumerationState : IActivityEnumerator activityTag) { if (activityTag.Value is Array) @@ -312,7 +312,43 @@ public bool ForEach(KeyValuePair activityTag) } else if (activityTag.Value != null) { - ProcessJaegerTag(ref this, activityTag.Key, activityTag.ToJaegerTag()); + var key = activityTag.Key; + var jaegerTag = activityTag.ToJaegerTag(); + if (jaegerTag.VStr != null) + { + PeerServiceResolver.InspectTag(ref this, key, jaegerTag.VStr); + + if (key == SpanAttributeConstants.StatusCodeKey) + { + StatusCode? statusCode = StatusHelper.GetStatusCodeForTagValue(jaegerTag.VStr); + + if (statusCode == Trace.StatusCode.Error) + { + // Error flag: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/jaeger.md#error-flag + this.StatusCode = statusCode; + return true; + } + else if (!statusCode.HasValue || statusCode == Trace.StatusCode.Unset) + { + // Unset Status is not sent: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/jaeger.md#status + return true; + } + + this.StatusCode = statusCode; + return true; + } + else if (key == JaegerErrorFlagTagName) + { + // Ignore `error` tag if it exists, it will be added based on StatusCode + StatusDescription. + return true; + } + } + else if (jaegerTag.VLong.HasValue) + { + PeerServiceResolver.InspectTag(ref this, key, jaegerTag.VLong.Value); + } + + PooledList.Add(ref this.Tags, jaegerTag); } return true; From 037743d0c2df02bfe0ddd9fe45c8d392de9f92c1 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Tue, 22 Mar 2022 18:16:10 -0700 Subject: [PATCH 2/7] test --- .../JaegerActivityConversionTest.cs | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs b/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs index 3da21d1d589..f0c0e75cf73 100644 --- a/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs +++ b/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs @@ -472,6 +472,106 @@ public void JaegerActivityConverterTest_Status_ErrorFlagTest(StatusCode expected } } + [Theory] + [InlineData(ActivityStatusCode.Unset)] + [InlineData(ActivityStatusCode.Ok)] + [InlineData(ActivityStatusCode.Error)] + public void ToJaegerSpan_Activity_Status_And_StatusDescription_is_Set(ActivityStatusCode expectedStatusCode) + { + // Arrange + var activity = CreateTestActivity(); + activity.SetStatus(expectedStatusCode); + + // Act + var jaegerSpan = activity.ToJaegerSpan(); + + // Assert + + if (expectedStatusCode == ActivityStatusCode.Unset) + { + Assert.DoesNotContain(jaegerSpan.Tags, t => t.Key == SpanAttributeConstants.StatusCodeKey); + } + else if (expectedStatusCode == ActivityStatusCode.Ok) + { + Assert.Equal("OK", jaegerSpan.Tags.FirstOrDefault(t => t.Key == SpanAttributeConstants.StatusCodeKey).VStr); + } + + // expectedStatusCode is Error + else + { + Assert.Equal("ERROR", jaegerSpan.Tags.FirstOrDefault(t => t.Key == SpanAttributeConstants.StatusCodeKey).VStr); + } + + if (expectedStatusCode == ActivityStatusCode.Error) + { + Assert.Contains( + jaegerSpan.Tags, t => + t.Key == JaegerActivityExtensions.JaegerErrorFlagTagName && + t.VType == JaegerTagType.BOOL && (t.VBool ?? false)); + } + else + { + Assert.DoesNotContain( + jaegerSpan.Tags, t => + t.Key == JaegerActivityExtensions.JaegerErrorFlagTagName); + } + } + + [Fact] + public void ActivityStatus_Takes_precedence_Over_Status_Tags_ActivityStatusCodeIsOk() + { + // Arrange. + var activity = CreateTestActivity(); + activity.SetStatus(ActivityStatusCode.Ok); + activity.SetTag(SpanAttributeConstants.StatusCodeKey, "ERROR"); + + // Enrich activity with additional tags. + activity.SetTag("myCustomTag", "myCustomTagValue"); + + // Act. + var jaegerSpan = activity.ToJaegerSpan(); + + // Assert. + Assert.Equal("OK", jaegerSpan.Tags.FirstOrDefault(t => t.Key == SpanAttributeConstants.StatusCodeKey).VStr); + + Assert.Contains(jaegerSpan.Tags, t => t.Key == "otel.status_code" && t.VStr == "OK"); + Assert.DoesNotContain(jaegerSpan.Tags, t => t.Key == "otel.status_code" && t.VStr == "ERROR"); + Assert.DoesNotContain(jaegerSpan.Tags, t => t.Key == JaegerActivityExtensions.JaegerErrorFlagTagName); + + // Ensure additional Activity tags were being converted. + Assert.Contains(jaegerSpan.Tags, t => t.Key == "myCustomTag" && t.VStr == "myCustomTagValue"); + } + + [Fact] + public void ActivityStatus_Takes_precedence_Over_Status_Tags_ActivityStatusCodeIsError() + { + // Arrange. + var activity = CreateTestActivity(); + + activity.SetStatus(ActivityStatusCode.Error); + activity.SetTag(SpanAttributeConstants.StatusCodeKey, "OK"); + + // Enrich activity with additional tags. + activity.SetTag("myCustomTag", "myCustomTagValue"); + + // Act. + var jaegerSpan = activity.ToJaegerSpan(); + + // Assert. + Assert.Equal("ERROR", jaegerSpan.Tags.FirstOrDefault(t => t.Key == SpanAttributeConstants.StatusCodeKey).VStr); + + // ActivityStatusDescription takes higher precedence. + Assert.Equal("ERROR", jaegerSpan.Tags.FirstOrDefault(t => t.Key == SpanAttributeConstants.StatusCodeKey).VStr); + + Assert.Contains( + jaegerSpan.Tags, t => + t.Key == JaegerActivityExtensions.JaegerErrorFlagTagName && + t.VType == JaegerTagType.BOOL && (t.VBool ?? false)); + + // Ensure additional Activity tags were being converted. + Assert.Contains(jaegerSpan.Tags, t => t.Key == "myCustomTag" && t.VStr == "myCustomTagValue"); + } + internal static Activity CreateTestActivity( bool setAttributes = true, Dictionary additionalAttributes = null, From 84455bb8fb40c954d6e9adbe239632ed890317ac Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Tue, 22 Mar 2022 18:29:01 -0700 Subject: [PATCH 3/7] changelog --- src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md b/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md index 4a54261cd43..4ff60447049 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +* Added support for Activity Status and StatusDescription which were + added to Activity from version 6.0. To maintain backward + compatibility, the exporter falls back to checking status inside + the tag "otel.status_code". + ([#3073](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3073)) + ## 1.2.0-rc3 Released 2022-Mar-04 From a4e14bd43284f97c204ae214a667469f906135a2 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Tue, 22 Mar 2022 19:30:04 -0700 Subject: [PATCH 4/7] comment --- .../Implementation/JaegerActivityConversionTest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs b/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs index f0c0e75cf73..0a5a73e2161 100644 --- a/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs +++ b/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs @@ -486,7 +486,6 @@ public void ToJaegerSpan_Activity_Status_And_StatusDescription_is_Set(ActivitySt var jaegerSpan = activity.ToJaegerSpan(); // Assert - if (expectedStatusCode == ActivityStatusCode.Unset) { Assert.DoesNotContain(jaegerSpan.Tags, t => t.Key == SpanAttributeConstants.StatusCodeKey); From eb71b9fdafcdfebf8690a51fdc89242fcc3e1d44 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Wed, 23 Mar 2022 12:31:00 -0700 Subject: [PATCH 5/7] support status description --- .../Implementation/JaegerActivityExtensions.cs | 16 +++++++++++++++- .../JaegerActivityConversionTest.cs | 12 +++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Jaeger/Implementation/JaegerActivityExtensions.cs b/src/OpenTelemetry.Exporter.Jaeger/Implementation/JaegerActivityExtensions.cs index 8190e41dadc..498ee2c1020 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/Implementation/JaegerActivityExtensions.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/Implementation/JaegerActivityExtensions.cs @@ -71,6 +71,10 @@ public static JaegerSpan ToJaegerSpan(this Activity activity) PooledList.Add( ref jaegerTags.Tags, new JaegerTag(JaegerErrorFlagTagName, JaegerTagType.BOOL, vBool: true)); + + PooledList.Add( + ref jaegerTags.Tags, + new JaegerTag(SpanAttributeConstants.StatusDescriptionKey, JaegerTagType.STRING, vStr: activity.StatusDescription ?? string.Empty)); } } else if (jaegerTags.StatusCode.HasValue && jaegerTags.StatusCode != StatusCode.Unset) @@ -87,6 +91,10 @@ public static JaegerSpan ToJaegerSpan(this Activity activity) PooledList.Add( ref jaegerTags.Tags, new JaegerTag(JaegerErrorFlagTagName, JaegerTagType.BOOL, vBool: true)); + + PooledList.Add( + ref jaegerTags.Tags, + new JaegerTag(SpanAttributeConstants.StatusDescriptionKey, JaegerTagType.STRING, vStr: jaegerTags.StatusDescription ?? string.Empty)); } } @@ -304,6 +312,8 @@ private struct TagEnumerationState : IActivityEnumerator activityTag) { if (activityTag.Value is Array) @@ -321,7 +331,6 @@ public bool ForEach(KeyValuePair activityTag) if (key == SpanAttributeConstants.StatusCodeKey) { StatusCode? statusCode = StatusHelper.GetStatusCodeForTagValue(jaegerTag.VStr); - if (statusCode == Trace.StatusCode.Error) { // Error flag: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/jaeger.md#error-flag @@ -342,6 +351,11 @@ public bool ForEach(KeyValuePair activityTag) // Ignore `error` tag if it exists, it will be added based on StatusCode + StatusDescription. return true; } + else if (key == SpanAttributeConstants.StatusDescriptionKey) + { + this.StatusDescription = jaegerTag.VStr; + return true; + } } else if (jaegerTag.VLong.HasValue) { diff --git a/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs b/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs index 0a5a73e2161..880a5286918 100644 --- a/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs +++ b/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs @@ -434,15 +434,16 @@ public void JaegerActivityConverterTest_NullTagValueTest() } [Theory] - [InlineData(StatusCode.Unset, "unset")] - [InlineData(StatusCode.Ok, "Ok")] - [InlineData(StatusCode.Error, "ERROR")] - [InlineData(StatusCode.Unset, "iNvAlId")] - public void JaegerActivityConverterTest_Status_ErrorFlagTest(StatusCode expectedStatusCode, string statusCodeTagValue) + [InlineData(StatusCode.Unset, "unset", "")] + [InlineData(StatusCode.Ok, "Ok", "")] + [InlineData(StatusCode.Error, "ERROR", "error description")] + [InlineData(StatusCode.Unset, "iNvAlId", "")] + public void JaegerActivityConverterTest_Status_ErrorFlagTest(StatusCode expectedStatusCode, string statusCodeTagValue, string statusDescription) { // Arrange var activity = CreateTestActivity(); activity.SetTag(SpanAttributeConstants.StatusCodeKey, statusCodeTagValue); + activity.SetTag(SpanAttributeConstants.StatusDescriptionKey, statusDescription); // Act var jaegerSpan = activity.ToJaegerSpan(); @@ -465,6 +466,7 @@ public void JaegerActivityConverterTest_Status_ErrorFlagTest(StatusCode expected if (expectedStatusCode == StatusCode.Error) { Assert.Contains(jaegerSpan.Tags, t => t.Key == JaegerActivityExtensions.JaegerErrorFlagTagName && t.VType == JaegerTagType.BOOL && (t.VBool ?? false)); + Assert.Contains(jaegerSpan.Tags, t => t.Key == SpanAttributeConstants.StatusDescriptionKey && t.VType == JaegerTagType.STRING && t.VStr.Equals(statusDescription)); } else { From 93fab264309c73a86383667d2f36357b5b35416e Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Wed, 23 Mar 2022 12:48:49 -0700 Subject: [PATCH 6/7] tests --- .../JaegerActivityConversionTest.cs | 54 ++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs b/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs index 880a5286918..92714ec1212 100644 --- a/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs +++ b/test/OpenTelemetry.Exporter.Jaeger.Tests/Implementation/JaegerActivityConversionTest.cs @@ -465,8 +465,14 @@ public void JaegerActivityConverterTest_Status_ErrorFlagTest(StatusCode expected if (expectedStatusCode == StatusCode.Error) { - Assert.Contains(jaegerSpan.Tags, t => t.Key == JaegerActivityExtensions.JaegerErrorFlagTagName && t.VType == JaegerTagType.BOOL && (t.VBool ?? false)); - Assert.Contains(jaegerSpan.Tags, t => t.Key == SpanAttributeConstants.StatusDescriptionKey && t.VType == JaegerTagType.STRING && t.VStr.Equals(statusDescription)); + Assert.Contains( + jaegerSpan.Tags, t => + t.Key == JaegerActivityExtensions.JaegerErrorFlagTagName && + t.VType == JaegerTagType.BOOL && (t.VBool ?? false)); + Assert.Contains( + jaegerSpan.Tags, t => + t.Key == SpanAttributeConstants.StatusDescriptionKey && + t.VType == JaegerTagType.STRING && t.VStr.Equals(statusDescription)); } else { @@ -523,8 +529,10 @@ public void ActivityStatus_Takes_precedence_Over_Status_Tags_ActivityStatusCodeI { // Arrange. var activity = CreateTestActivity(); + const string TagDescriptionOnError = "Description when TagStatusCode is Error."; activity.SetStatus(ActivityStatusCode.Ok); activity.SetTag(SpanAttributeConstants.StatusCodeKey, "ERROR"); + activity.SetTag(SpanAttributeConstants.StatusDescriptionKey, TagDescriptionOnError); // Enrich activity with additional tags. activity.SetTag("myCustomTag", "myCustomTagValue"); @@ -538,6 +546,8 @@ public void ActivityStatus_Takes_precedence_Over_Status_Tags_ActivityStatusCodeI Assert.Contains(jaegerSpan.Tags, t => t.Key == "otel.status_code" && t.VStr == "OK"); Assert.DoesNotContain(jaegerSpan.Tags, t => t.Key == "otel.status_code" && t.VStr == "ERROR"); Assert.DoesNotContain(jaegerSpan.Tags, t => t.Key == JaegerActivityExtensions.JaegerErrorFlagTagName); + Assert.DoesNotContain(jaegerSpan.Tags, t => t.Key == SpanAttributeConstants.StatusDescriptionKey && + t.VType == JaegerTagType.STRING && t.VStr.Equals(TagDescriptionOnError)); // Ensure additional Activity tags were being converted. Assert.Contains(jaegerSpan.Tags, t => t.Key == "myCustomTag" && t.VStr == "myCustomTagValue"); @@ -548,8 +558,8 @@ public void ActivityStatus_Takes_precedence_Over_Status_Tags_ActivityStatusCodeI { // Arrange. var activity = CreateTestActivity(); - - activity.SetStatus(ActivityStatusCode.Error); + const string StatusDescriptionOnError = "Description when ActivityStatusCode is Error."; + activity.SetStatus(ActivityStatusCode.Error, StatusDescriptionOnError); activity.SetTag(SpanAttributeConstants.StatusCodeKey, "OK"); // Enrich activity with additional tags. @@ -559,9 +569,36 @@ public void ActivityStatus_Takes_precedence_Over_Status_Tags_ActivityStatusCodeI var jaegerSpan = activity.ToJaegerSpan(); // Assert. - Assert.Equal("ERROR", jaegerSpan.Tags.FirstOrDefault(t => t.Key == SpanAttributeConstants.StatusCodeKey).VStr); + Assert.Contains(jaegerSpan.Tags, t => t.Key == "otel.status_code" && t.VStr == "ERROR"); + Assert.Contains(jaegerSpan.Tags, t => t.Key == JaegerActivityExtensions.JaegerErrorFlagTagName); + Assert.Contains(jaegerSpan.Tags, t => t.Key == SpanAttributeConstants.StatusDescriptionKey && + t.VType == JaegerTagType.STRING && t.VStr.Equals(StatusDescriptionOnError)); + + Assert.DoesNotContain(jaegerSpan.Tags, t => t.Key == "otel.status_code" && t.VStr == "OK"); + + // Ensure additional Activity tags were being converted. + Assert.Contains(jaegerSpan.Tags, t => t.Key == "myCustomTag" && t.VStr == "myCustomTagValue"); + } + + [Fact] + public void ActivityDescription_Takes_precedence_Over_Status_Tags_When_ActivityStatusCodeIsError() + { + // Arrange. + var activity = CreateTestActivity(); + + const string StatusDescriptionOnError = "Description when ActivityStatusCode is Error."; + const string TagDescriptionOnError = "Description when TagStatusCode is Error."; + activity.SetStatus(ActivityStatusCode.Error, StatusDescriptionOnError); + activity.SetTag(SpanAttributeConstants.StatusCodeKey, "ERROR"); + activity.SetTag(SpanAttributeConstants.StatusDescriptionKey, TagDescriptionOnError); + + // Enrich activity with additional tags. + activity.SetTag("myCustomTag", "myCustomTagValue"); - // ActivityStatusDescription takes higher precedence. + // Act. + var jaegerSpan = activity.ToJaegerSpan(); + + // Assert. Assert.Equal("ERROR", jaegerSpan.Tags.FirstOrDefault(t => t.Key == SpanAttributeConstants.StatusCodeKey).VStr); Assert.Contains( @@ -569,6 +606,11 @@ public void ActivityStatus_Takes_precedence_Over_Status_Tags_ActivityStatusCodeI t.Key == JaegerActivityExtensions.JaegerErrorFlagTagName && t.VType == JaegerTagType.BOOL && (t.VBool ?? false)); + Assert.Contains( + jaegerSpan.Tags, t => + t.Key == SpanAttributeConstants.StatusDescriptionKey && + t.VType == JaegerTagType.STRING && t.VStr.Equals(StatusDescriptionOnError)); + // Ensure additional Activity tags were being converted. Assert.Contains(jaegerSpan.Tags, t => t.Key == "myCustomTag" && t.VStr == "myCustomTagValue"); } From 0deb4bef930b65bcada8cb4bb68828c2325f16e0 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Wed, 23 Mar 2022 19:01:52 -0700 Subject: [PATCH 7/7] comment --- .../Implementation/JaegerActivityExtensions.cs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Jaeger/Implementation/JaegerActivityExtensions.cs b/src/OpenTelemetry.Exporter.Jaeger/Implementation/JaegerActivityExtensions.cs index 498ee2c1020..33a3f8ee332 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/Implementation/JaegerActivityExtensions.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/Implementation/JaegerActivityExtensions.cs @@ -331,26 +331,9 @@ public bool ForEach(KeyValuePair activityTag) if (key == SpanAttributeConstants.StatusCodeKey) { StatusCode? statusCode = StatusHelper.GetStatusCodeForTagValue(jaegerTag.VStr); - if (statusCode == Trace.StatusCode.Error) - { - // Error flag: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/jaeger.md#error-flag - this.StatusCode = statusCode; - return true; - } - else if (!statusCode.HasValue || statusCode == Trace.StatusCode.Unset) - { - // Unset Status is not sent: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/jaeger.md#status - return true; - } - this.StatusCode = statusCode; return true; } - else if (key == JaegerErrorFlagTagName) - { - // Ignore `error` tag if it exists, it will be added based on StatusCode + StatusDescription. - return true; - } else if (key == SpanAttributeConstants.StatusDescriptionKey) { this.StatusDescription = jaegerTag.VStr;