Skip to content

#1465 break change: not support OpenTelemetry.Instrumentation.GrpcNetClient #1558

@pengweiqhca

Description

@pengweiqhca

Solution

Move ActivityStartData and ActivityStopData from GrpcCall.cs to GrpcCall.NonGeneric.cs

Reason

GrpcClientDiagnosticListener use PropertyFetcher read Request property. PropertyFetcher use TypedPropertyFetch to improve performance, but in different methods, ActivityStartData and ActivityStopData are not of the same type. so, obj is TDeclaredObject o is false after the first call.

Sample

var services = new ServiceCollection();

services.AddGrpcClient<Greeter.GreeterClient>(options => options.Address = new Uri("http://localhost"))
    .ConfigurePrimaryHttpMessageHandler(_ => new TestHandler());

using var _ = Sdk.CreateTracerProviderBuilder()
    .AddGrpcClientInstrumentation(options => options.SuppressDownstreamInstrumentation = true)
    .SetSampler(new AlwaysOnSampler())
    .Build();
await using var root = services.BuildServiceProvider();
await using var scope = root.CreateAsyncScope();

var client = scope.ServiceProvider.GetRequiredService<Greeter.GreeterClient>();

try
{
    await client.SayHelloAsync(new HelloRequest());
}
catch (RpcException ex) when (ex.Status.StatusCode == StatusCode.OK) { }

try
{
    await client.SayHello2Async(new HelloRequest2());
}
catch (RpcException ex) when (ex.Status.StatusCode == StatusCode.OK) { }

class TestHandler : DelegatingHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        if (request.Headers.Contains("traceparent")) //Should never false
            throw new RpcException(Status.DefaultSuccess);

        throw new UnauthorizedAccessException();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions