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

GrpcNetClient Instrumentation to leverage native Activity Status. #3569

Merged
merged 5 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

* Updated to use Activity native support from `System.Diagnostics.DiagnosticSource`
to set activity status.
([#3118](https://github.com/open-telemetry/opentelemetry-dotnet/issues/3118))
([#3569](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3569))

## 1.0.0-rc9.5

Released 2022-Aug-02
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ public static bool TryParseRpcServiceAndRpcMethod(string grpcMethod, out string
/// </summary>
/// <param name="statusCode">RPC status code.</param>
/// <returns>Resolved span <see cref="Status"/> for the Grpc status code.</returns>
public static Status ResolveSpanStatusForGrpcStatusCode(int statusCode)
public static ActivityStatusCode ResolveSpanStatusForGrpcStatusCode(int statusCode)
{
var status = Status.Error;
var status = ActivityStatusCode.Error;

if (typeof(StatusCanonicalCode).IsEnumDefined(statusCode))
{
status = ((StatusCanonicalCode)statusCode) switch
{
StatusCanonicalCode.Ok => Status.Unset,
_ => Status.Error,
StatusCanonicalCode.Ok => ActivityStatusCode.Unset,
_ => ActivityStatusCode.Error,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public override void OnStopActivity(Activity activity, object payload)
bool validConversion = GrpcTagHelper.TryGetGrpcStatusCodeFromActivity(activity, out int status);
if (validConversion)
{
if (activity.GetStatus().StatusCode == StatusCode.Unset)
if (activity.Status == ActivityStatusCode.Unset)
{
activity.SetStatus(GrpcTagHelper.ResolveSpanStatusForGrpcStatusCode(status));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void GrpcTagHelper_GetGrpcStatusCodeFromActivity()
var statusCode = GrpcTagHelper.ResolveSpanStatusForGrpcStatusCode(status);
activity.SetTag(SemanticConventions.AttributeRpcGrpcStatusCode, status);

Assert.Equal(StatusCode.Unset, statusCode.StatusCode);
Assert.Equal(ActivityStatusCode.Unset, statusCode);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surprised that we had no tests with status being Error?

Assert.Equal(status, activity.GetTagValue(SemanticConventions.AttributeRpcGrpcStatusCode));
}

Expand Down