Skip to content

Commit

Permalink
[Instrumentation.GrpcCore] Remove usage of "otel.status_code" and "ot…
Browse files Browse the repository at this point in the history
…el.status_description" (#1799)
  • Loading branch information
IliaBrahinets committed May 20, 2024
1 parent 2ed2276 commit 6687875
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
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

0 comments on commit 6687875

Please sign in to comment.