From 66878751c958dd1c993e57816cc013910ae881ff Mon Sep 17 00:00:00 2001 From: Ilia Brahinets Date: Mon, 20 May 2024 14:33:31 +0300 Subject: [PATCH] [Instrumentation.GrpcCore] Remove usage of "otel.status_code" and "otel.status_description" (#1799) --- src/OpenTelemetry.Instrumentation.GrpcCore/CHANGELOG.md | 3 +++ src/OpenTelemetry.Instrumentation.GrpcCore/RpcScope.cs | 9 +++++---- .../SemanticConventions.cs | 2 -- .../GrpcCoreClientInterceptorTests.cs | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.GrpcCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.GrpcCore/CHANGELOG.md index 4a2053ded6..8f737f68dd 100644 --- a/src/OpenTelemetry.Instrumentation.GrpcCore/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.GrpcCore/CHANGELOG.md @@ -12,6 +12,9 @@ ([#1668](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1668)) * `RecordException` option for both client and server interceptors. ([#1648](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1648)) +* Use `Activity.Status` and `Activity.StatusDescription` + instead of `otel.status_code` and `otel.status_description` tags. + ([#1799](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1799)) ## 1.0.0-beta.5 diff --git a/src/OpenTelemetry.Instrumentation.GrpcCore/RpcScope.cs b/src/OpenTelemetry.Instrumentation.GrpcCore/RpcScope.cs index 3b01fdaf96..889a761fa2 100644 --- a/src/OpenTelemetry.Instrumentation.GrpcCore/RpcScope.cs +++ b/src/OpenTelemetry.Instrumentation.GrpcCore/RpcScope.cs @@ -8,6 +8,7 @@ using Google.Protobuf; using Grpc.Core; using OpenTelemetry.Trace; +using StatusCode = Grpc.Core.StatusCode; namespace OpenTelemetry.Instrumentation.GrpcCore; @@ -111,7 +112,7 @@ public void Complete() } // The overall Span status should remain unset however the grpc status code attribute is required - this.StopActivity((int)Grpc.Core.StatusCode.OK); + this.StopActivity((int)StatusCode.OK); } /// @@ -137,7 +138,7 @@ public void Dispose() } // If not already completed this will mark the Activity as cancelled. - this.StopActivity((int)Grpc.Core.StatusCode.Cancelled); + this.StopActivity((int)StatusCode.Cancelled); } /// @@ -197,7 +198,7 @@ private void StopActivity(Exception exception) return; } - var grpcStatusCode = Grpc.Core.StatusCode.Unknown; + var grpcStatusCode = StatusCode.Unknown; var description = exception.Message; if (exception is RpcException rpcException) @@ -208,7 +209,7 @@ private void StopActivity(Exception exception) if (!string.IsNullOrEmpty(description)) { - this.activity.SetStatus(Trace.Status.Error.WithDescription(description)); + this.activity.SetStatus(ActivityStatusCode.Error, description); } if (this.activity.IsAllDataRequested && this.recordException) diff --git a/src/OpenTelemetry.Instrumentation.GrpcCore/SemanticConventions.cs b/src/OpenTelemetry.Instrumentation.GrpcCore/SemanticConventions.cs index 57fac3c010..b4463adc93 100644 --- a/src/OpenTelemetry.Instrumentation.GrpcCore/SemanticConventions.cs +++ b/src/OpenTelemetry.Instrumentation.GrpcCore/SemanticConventions.cs @@ -17,8 +17,6 @@ internal static class SemanticConventions public const string AttributeMessageID = "message.id"; public const string AttributeMessageCompressedSize = "message.compressed_size"; public const string AttributeMessageUncompressedSize = "message.uncompressed_size"; - public const string AttributeOtelStatusCode = "otel.status_code"; - public const string AttributeOtelStatusDescription = "otel.status_description"; // Used for unit testing only. internal const string AttributeActivityIdentifier = "activityidentifier"; diff --git a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs index 5c670dffe4..a8fd94ac87 100644 --- a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs +++ b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs @@ -329,7 +329,7 @@ static void ValidateNewTagOnActivity(InterceptorActivityListener listener) // Cancelled is not an error. if (expectedStatusCode != StatusCode.OK && expectedStatusCode != StatusCode.Cancelled) { - Assert.Contains(activity.TagObjects, t => t.Key == SemanticConventions.AttributeOtelStatusCode && (string)t.Value == "ERROR"); + Assert.Equal(ActivityStatusCode.Error, activity.Status); } if (recordedMessages) @@ -504,7 +504,7 @@ private static async Task TestHandlerSuccess(Func t.Key == SemanticConventions.AttributeOtelStatusDescription && ((string)t.Value).Contains("fubar")); + Assert.Contains("fubar", activity.StatusDescription); } }