Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Instrumentation.GrpcCore] Remove usage of "otel.status_code" and "otel.status_description" #1799

Merged
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Instrumentation.GrpcCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions src/OpenTelemetry.Instrumentation.GrpcCore/RpcScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Google.Protobuf;
using Grpc.Core;
using OpenTelemetry.Trace;
using StatusCode = Grpc.Core.StatusCode;

namespace OpenTelemetry.Instrumentation.GrpcCore;

Expand Down Expand Up @@ -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);
}

/// <summary>
Expand All @@ -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);
}

/// <summary>
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -504,7 +504,7 @@ private static async Task TestHandlerSuccess(Func<Foobar.FoobarClient, Metadata,

if (validateErrorDescription)
{
Assert.Contains(activity.TagObjects, t => t.Key == SemanticConventions.AttributeOtelStatusDescription && ((string)t.Value).Contains("fubar"));
Assert.Contains("fubar", activity.StatusDescription);
}
}

Expand Down