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

[OpenTelemetry.Instrumentation.AspNetCore] Implement gRPC server instrumentation with use of Interceptor instead or extend ResolveSpanStatusForGrpcStatusCode method #1725

Open
prybski opened this issue Mar 12, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@prybski
Copy link

prybski commented Mar 12, 2024

Feature Request

Last time, when migrating to OpenTelemetry in our team we have encountered a problem with experimental instrumentation for gRPC server from this C# project: https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/src/OpenTelemetry.Instrumentation.AspNetCore. The problem is that ActivityStatus is not being set with respect to this semantics for gRPC status codes: https://opentelemetry.io/docs/specs/semconv/rpc/grpc/#grpc-status - below source code of the .ResolveSpanStatusForGrpcStatusCode(...) method is implemented in a way it should be implemented for ActivityKind being Client:

/// <summary>
/// Helper method that populates span properties from RPC status code according
/// to https://github.com/open-telemetry/semantic-conventions/blob/main/docs/rpc/grpc.md#grpc-attributes.
/// </summary>
/// <param name="statusCode">RPC status code.</param>
/// <returns>Resolved span <see cref="Status"/> for the Grpc status code.</returns>
public static ActivityStatusCode ResolveSpanStatusForGrpcStatusCode(int statusCode)
{
    var status = ActivityStatusCode.Error;

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

    return status;
}

Describe the solution you'd like:

I think that we would have two possible solutions:

  • Implement instrumentation of gRPC server with use of Interceptor, which allows easily handle exceptions and set appropriate ActivityStatus based on the gRPC status code (that is something what we have right now, to have proper mapping between gRPC status code and ActivityStatus)
  • Extend .ResolveSpanStatusForGrpcStatusCode(...) method to properly resolve ActivityStatus for ActivityKind being Server based on the gRPC status code (I have linked semantics for ActivityKind being Server earlier).
@prybski prybski added the enhancement New feature or request label Mar 12, 2024
@prybski prybski changed the title Implement gRPC server instrumentation with use of Interceptor instead or extend ResolveSpanStatusForGrpcStatusCode method [OpenTelemetry.Instrumentation.AspNetCore] Implement gRPC server instrumentation with use of Interceptor instead or extend ResolveSpanStatusForGrpcStatusCode method Mar 12, 2024
@reyang reyang transferred this issue from open-telemetry/opentelemetry-dotnet May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant