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

Add gRPC attributes for ASP.NET Core #803

Merged
merged 25 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b64eb1b
Change gRPC test project name and namespace
alanwest Jul 12, 2020
8d019fb
Use SpanAttributeConstants in GrpcClientTests
alanwest Jul 12, 2020
46fa7bb
Add test for Grpc.AspNetCore instrumentation
alanwest Jul 12, 2020
752e995
Add gRPC attributes for ASP.NET Core
alanwest Jul 12, 2020
9854dc4
Merge branch 'master' into alanwest/grpc-aspnetcore
cijothomas Jul 14, 2020
b002ed2
Merge branch 'master' into alanwest/grpc-aspnetcore
alanwest Jul 21, 2020
c41fba8
Prevent parallel execution of gRPC client and server test suites
alanwest Jul 22, 2020
d319068
Merge branch 'master' into alanwest/grpc-aspnetcore
alanwest Jul 22, 2020
144cbce
Add wait logic from AspNetCore tests ensuring end callback gets invoked
alanwest Jul 22, 2020
2e0e76d
Partial class for gRPC test to resolve test conflicts
alanwest Jul 22, 2020
9a76a77
Merge branch 'master' into alanwest/grpc-aspnetcore
alanwest Jul 24, 2020
219654a
Merge branch 'master' into alanwest/grpc-aspnetcore
alanwest Jul 27, 2020
2f9b16d
Make "grpc" a const
alanwest Jul 27, 2020
a638d3f
Set http.status_code attribute even on a gRPC invocation
alanwest Jul 27, 2020
8d57617
Fix GrpcFixture
alanwest Jul 27, 2020
8232d33
Add checks for http.* attributes to ASP.NET Core gRPC test
alanwest Jul 27, 2020
191401a
Merge branch 'master' into alanwest/grpc-aspnetcore
alanwest Jul 30, 2020
72257ca
Merge branch 'master' into alanwest/grpc-aspnetcore
alanwest Aug 3, 2020
f4c149c
Merge branch 'master' into alanwest/grpc-aspnetcore
cijothomas Aug 4, 2020
07f3625
Merge branch 'master' into alanwest/grpc-aspnetcore
alanwest Aug 4, 2020
234fafd
Merge branch 'alanwest/grpc-aspnetcore' of github.com:alanwest/opente…
alanwest Aug 4, 2020
863b8d2
Fix merge snafu
alanwest Aug 4, 2020
df6d428
Merge branch 'master' into alanwest/grpc-aspnetcore
alanwest Aug 5, 2020
cda4766
Update changelog
alanwest Aug 5, 2020
a9edc7a
Merge branch 'master' into alanwest/grpc-aspnetcore
cijothomas Aug 5, 2020
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
2 changes: 1 addition & 1 deletion OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D2E73927-5
test\Directory.Build.targets = test\Directory.Build.targets
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.GrpcClient.Tests", "test\OpenTelemetry.Instrumentation.GrpcClient.Tests\OpenTelemetry.Instrumentation.GrpcClient.Tests.csproj", "{305E9DFD-E73B-4A28-8769-795C25551020}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.Grpc.Tests", "test\OpenTelemetry.Instrumentation.Grpc.Tests\OpenTelemetry.Instrumentation.Grpc.Tests.csproj", "{305E9DFD-E73B-4A28-8769-795C25551020}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApp.AspNetCore.2.1", "test\TestApp.AspNetCore.2.1\TestApp.AspNetCore.2.1.csproj", "{7CDA3F85-EA6F-45C4-B432-2559303355D4}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Instrumentation.Grpc;
using OpenTelemetry.Trace;

namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
Expand Down Expand Up @@ -131,8 +132,15 @@ public override void OnStopActivity(Activity activity, object payload)
var response = context.Response;
activity.SetTag(SemanticConventions.AttributeHttpStatusCode, response.StatusCode.ToString());

Status status = SpanHelper.ResolveSpanStatusForHttpStatusCode(response.StatusCode);
activity.SetStatus(status.WithDescription(response.HttpContext.Features.Get<IHttpResponseFeature>()?.ReasonPhrase));
if (this.TryGetGrpcMethod(activity, out var grpcMethod))
Copy link
Member

Choose a reason for hiding this comment

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

It looks like different tags are added depending on whether the GrpcMethod can be retrieved, is that correct?

For example:
DisplayName (currently commented out, AttributeRpcSystem, service, method, etc
vs
AttributeHttpStatusCode, Status

Should we drop the else so the later tags are always added?

Copy link
Member Author

@alanwest alanwest Jul 27, 2020

Choose a reason for hiding this comment

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

My decision here was intentional, though I did raise the question earlier whether all the http.* attributes should be omitted from the span in the context of a gRPC invocation.

Two things occur in the else clause:

  1. The http.status_code attribute is set
  2. The Status of the span gets set

At a minimum we should not set the span's status based on the HTTP status because the gRPC status should be used instead. Though, I could see an argument for leaving the http.status_code attribute. Other http.* attributes are added in OnStartActivity. Given that this PR currently leaves those untouched, then it probably makes sense to leave http.status_code.

I'm ok coming back to this question of keeping vs. omitting the http.* attributes and iterating on this instrumentation later, though I think I need to make sure the test actually reflects these decisions.

Copy link
Member Author

Choose a reason for hiding this comment

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

I expanded the test to reflect this conversation.

// The following are http.* attributes that are also included on the span for the gRPC invocation.
Assert.Equal($"localhost:{this.fixture.Port}", span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeHttpHost).Value);
Assert.Equal("POST", span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeHttpMethod).Value);
Assert.Equal("/greet.Greeter/SayHello", span.Tags.FirstOrDefault(i => i.Key == SpanAttributeConstants.HttpPathKey).Value);
Assert.Equal($"http://localhost:{this.fixture.Port}/greet.Greeter/SayHello", span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeHttpUrl).Value);
Assert.StartsWith("grpc-dotnet", span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeHttpUserAgent).Value);
// This attribute is added by the gRPC for .NET library. There is a discussion of having the OTel instrumentation remove it.
// See: https://github.com/open-telemetry/opentelemetry-dotnet/issues/482#issuecomment-655753756
Assert.Equal($"0", span.Tags.FirstOrDefault(i => i.Key == "grpc.status_code").Value);

Copy link
Member

Choose a reason for hiding this comment

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

I think we discussed a long time ago, but I personally like having both the http and grpc tags in there. GRPC is not limited to working over HTTP, even though not many alternatives exist. I may be considered unnecessary details for now though 🤷
@cijothomas @CodeBlanch What are your thoughts?

Copy link
Member Author

@alanwest alanwest Jul 30, 2020

Choose a reason for hiding this comment

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

personally like having both the http and grpc tags in there

I agree that it probably makes sense to leave them in. I'm not necessarily advocating for one way or another at this point, but just to highlight some things for ongoing consideration:

  • For the client side grpc-dotnet instrumentation we discussed the possibility of allowing the suppression of the underlying HTTP span that is generated. There exist other examples where this is desired as well.
  • For the ASP.NET Core server side instrumentation, things are a bit different, there is no "other" span. Attributes are applied to the span (activity) that ASP.NET Core started. The library itself adds attributes here.

GRPC is not limited to working over HTTP

Yes, true, and I definitely see value in reflecting transport type on calls both server-side and client-side. This may be a thing that needs to be continued to be pushed at the spec level. I personally have experience with instrumenting WCF - which is a complex beast, and I've confronted a lot of these same considerations with it.

Slight tangent, but with WCF and perhaps eventually with gRPC, transport type used affects whether we can do auto-context propagation. For example, if the transport is a raw TCP channel, then there exist no structured headers mechanism to inject context - it has to be done manually.

{
this.AddGrpcAttributes(activity, grpcMethod, context);
}
else
{
Status status = SpanHelper.ResolveSpanStatusForHttpStatusCode(response.StatusCode);
activity.SetStatus(status.WithDescription(response.HttpContext.Features.Get<IHttpResponseFeature>()?.ReasonPhrase));
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved
}
}

if (activity.OperationName.Equals(ActivityNameByHttpInListener))
Expand Down Expand Up @@ -219,5 +227,30 @@ private static string GetUri(HttpRequest request)

return builder.ToString();
}

private bool TryGetGrpcMethod(Activity activity, out string grpcMethod)
{
grpcMethod = GrpcTagHelper.GetGrpcMethodFromActivity(activity);
return !string.IsNullOrEmpty(grpcMethod);
}

private void AddGrpcAttributes(Activity activity, string grpcMethod, HttpContext context)
{
// TODO: Should the leading slash be trimmed? Spec seems to suggest no leading slash: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/rpc.md#span-name
// Client instrumentation is trimming the leading slash. Whatever we decide here, should we apply the same to the client side?
// activity.DisplayName = grpcMethod?.Trim('/');

activity.AddTag(SemanticConventions.AttributeRpcSystem, GrpcTagHelper.RpcSystemGrpc);

if (GrpcTagHelper.TryParseRpcServiceAndRpcMethod(grpcMethod, out var rpcService, out var rpcMethod))
{
activity.AddTag(SemanticConventions.AttributeRpcService, rpcService);
activity.AddTag(SemanticConventions.AttributeRpcMethod, rpcMethod);
}

activity.AddTag(SemanticConventions.AttributeNetPeerIp, context.Connection.RemoteIpAddress.ToString());
activity.AddTag(SemanticConventions.AttributeNetPeerPort, context.Connection.RemotePort.ToString());
activity.SetStatus(GrpcTagHelper.GetGrpcStatusCodeFromActivity(activity));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<ItemGroup>
<Compile Include="..\OpenTelemetry.Api\Trace\SemanticConventions.cs" />
<Compile Include="..\OpenTelemetry.Instrumentation.Grpc\GrpcTagHelper.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry.Instrumentation.Grpc/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using System.Runtime.CompilerServices;

#if SIGNED
[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.GrpcClient.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")]
[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.Grpc.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")]
#else
[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.GrpcClient.Tests")]
[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.Grpc.Tests")]
#endif
2 changes: 2 additions & 0 deletions src/OpenTelemetry.Instrumentation.Grpc/GrpcTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace OpenTelemetry.Instrumentation.Grpc
{
internal static class GrpcTagHelper
{
public const string RpcSystemGrpc = "grpc";

// The Grpc.Net.Client library adds its own tags to the activity.
// These tags are used to source the tags added by the OpenTelemetry instrumentation.
public const string GrpcMethodTagName = "grpc.method";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override void OnStartActivity(Activity activity, object payload)

if (activity.IsAllDataRequested)
{
activity.SetTag(SemanticConventions.AttributeRpcSystem, "grpc");
activity.SetTag(SemanticConventions.AttributeRpcSystem, GrpcTagHelper.RpcSystemGrpc);

if (GrpcTagHelper.TryParseRpcServiceAndRpcMethod(grpcMethod, out var rpcService, out var rpcMethod))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Moq;
using OpenTelemetry.Trace;

namespace OpenTelemetry.Instrumentation.GrpcClient.Tests
namespace OpenTelemetry.Instrumentation.Grpc.Tests
{
public class GrpcFixture<TService> : IDisposable
where TService : class
Expand All @@ -29,8 +31,14 @@ public class GrpcFixture<TService> : IDisposable

private readonly IHost host;

private TracerProvider openTelemetrySdk = null;

public GrpcFixture()
{
// Allows gRPC client to call insecure gRPC services
// https://docs.microsoft.com/en-us/aspnet/core/grpc/troubleshoot?view=aspnetcore-3.1#call-insecure-grpc-services-with-net-core-client
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

this.Port = 0;

var retryCount = 5;
Expand All @@ -53,10 +61,13 @@ public GrpcFixture()

public int Port { get; }

public Mock<ActivityProcessor> GrpcServerSpanProcessor { get; } = new Mock<ActivityProcessor>();

public void Dispose()
{
this.host.StopAsync(TimeSpan.FromSeconds(5)).GetAwaiter().GetResult();
this.host.Dispose();
this.openTelemetrySdk.Dispose();
}

private IHost CreateServer()
Expand All @@ -70,6 +81,14 @@ private IHost CreateServer()
// Setup a HTTP/2 endpoint without TLS.
options.ListenLocalhost(this.Port, o => o.Protocols = HttpProtocols.Http2);
})
.ConfigureServices(serviceCollection =>
{
this.openTelemetrySdk = Sdk
.CreateTracerProvider(
(builder) => builder
.AddAspNetCoreInstrumentation()
.AddProcessorPipeline(p => p.AddProcessor(n => this.GrpcServerSpanProcessor.Object)));
})
.UseStartup<Startup>();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="GrpcClientTests.cs" company="OpenTelemetry Authors">
// <copyright file="GrpcTests.client.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,27 +19,14 @@
using Greet;
using Grpc.Net.Client;
using Moq;
using OpenTelemetry.Instrumentation.GrpcClient.Tests.Services;
using OpenTelemetry.Instrumentation.Grpc.Tests.Services;
using OpenTelemetry.Trace;
using Xunit;

namespace OpenTelemetry.Instrumentation.GrpcClient.Tests
namespace OpenTelemetry.Instrumentation.Grpc.Tests
{
public class GrpcClientTests : IClassFixture<GrpcFixture<GreeterService>>
public partial class GrpcTests : IClassFixture<GrpcFixture<GreeterService>>
{
private GrpcFixture<GreeterService> fixture;

public GrpcClientTests(GrpcFixture<GreeterService> fixture)
{
// Allows gRPC client to call insecure gRPC services
// https://docs.microsoft.com/en-us/aspnet/core/grpc/troubleshoot?view=aspnetcore-3.1#call-insecure-grpc-services-with-net-core-client
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

Activity.DefaultIdFormat = ActivityIdFormat.W3C;

this.fixture = fixture;
}

[Theory]
[InlineData("http://localhost")]
[InlineData("http://127.0.0.1")]
Expand Down Expand Up @@ -76,23 +63,23 @@ public void GrpcClientCallsAreCollectedSuccessfully(string baseAddress)

Assert.Equal($"greet.Greeter/SayHello", span.DisplayName);
Assert.Equal("Client", span.Kind.ToString());
Assert.Equal("grpc", span.Tags.FirstOrDefault(i => i.Key == "rpc.system").Value);
Assert.Equal("greet.Greeter", span.Tags.FirstOrDefault(i => i.Key == "rpc.service").Value);
Assert.Equal("SayHello", span.Tags.FirstOrDefault(i => i.Key == "rpc.method").Value);
Assert.Equal("grpc", span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeRpcSystem).Value);
Assert.Equal("greet.Greeter", span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeRpcService).Value);
Assert.Equal("SayHello", span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeRpcMethod).Value);

if (uriHostNameType == UriHostNameType.IPv4 || uriHostNameType == UriHostNameType.IPv6)
{
Assert.Equal(uri.Host, span.Tags.FirstOrDefault(i => i.Key == "net.peer.ip").Value);
Assert.Null(span.Tags.FirstOrDefault(i => i.Key == "net.peer.name").Value);
Assert.Equal(uri.Host, span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeNetPeerIp).Value);
Assert.Null(span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeNetPeerName).Value);
}
else
{
Assert.Null(span.Tags.FirstOrDefault(i => i.Key == "net.peer.ip").Value);
Assert.Equal(uri.Host, span.Tags.FirstOrDefault(i => i.Key == "net.peer.name").Value);
Assert.Null(span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeNetPeerIp).Value);
Assert.Equal(uri.Host, span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeNetPeerName).Value);
}

Assert.Equal(uri.Port.ToString(), span.Tags.FirstOrDefault(i => i.Key == "net.peer.port").Value);
Assert.Equal("Ok", span.Tags.FirstOrDefault(i => i.Key == SpanAttributeConstants.StatusCodeKey).Value);
Assert.Equal(uri.Port.ToString(), span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeNetPeerPort).Value);
Assert.Equal(Status.Ok, span.GetStatus());
Assert.Equal(expectedResource, span.GetResource());
}

Expand Down
89 changes: 89 additions & 0 deletions test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.server.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// <copyright file="GrpcTests.server.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Threading;
using Greet;
using Grpc.Net.Client;
using Moq;
using OpenTelemetry.Instrumentation.Grpc.Tests.Services;
using OpenTelemetry.Trace;
using Xunit;

namespace OpenTelemetry.Instrumentation.Grpc.Tests
{
public partial class GrpcTests : IClassFixture<GrpcFixture<GreeterService>>
{
private GrpcFixture<GreeterService> fixture;

public GrpcTests(GrpcFixture<GreeterService> fixture)
{
this.fixture = fixture;
}

[Fact]
public void GrpcAspNetCoreInstrumentationAddsCorrectAttributes()
{
var clientLoopbackAddresses = new[] { IPAddress.Loopback.ToString(), IPAddress.IPv6Loopback.ToString() };
var uri = new Uri($"http://localhost:{this.fixture.Port}");
var spanProcessor = this.fixture.GrpcServerSpanProcessor;

var channel = GrpcChannel.ForAddress(uri);
var client = new Greeter.GreeterClient(channel);
var rs = client.SayHello(new HelloRequest());

WaitForProcessorInvocations(spanProcessor, 2);

Assert.Equal(2, spanProcessor.Invocations.Count); // begin and end was called
var span = (Activity)spanProcessor.Invocations[1].Arguments[0];

Assert.Equal(ActivityKind.Server, span.Kind);
Assert.Equal("grpc", span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeRpcSystem).Value);
Assert.Equal("greet.Greeter", span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeRpcService).Value);
Assert.Equal("SayHello", span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeRpcMethod).Value);
Assert.Contains(span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeNetPeerIp).Value, clientLoopbackAddresses);
Assert.True(!string.IsNullOrEmpty(span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeNetPeerPort).Value));
Assert.Equal(Status.Ok, span.GetStatus());

// The following are http.* attributes that are also included on the span for the gRPC invocation.
Assert.Equal($"localhost:{this.fixture.Port}", span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeHttpHost).Value);
Assert.Equal("POST", span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeHttpMethod).Value);
Assert.Equal("/greet.Greeter/SayHello", span.Tags.FirstOrDefault(i => i.Key == SpanAttributeConstants.HttpPathKey).Value);
Assert.Equal($"http://localhost:{this.fixture.Port}/greet.Greeter/SayHello", span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeHttpUrl).Value);
Assert.StartsWith("grpc-dotnet", span.Tags.FirstOrDefault(i => i.Key == SemanticConventions.AttributeHttpUserAgent).Value);

// This attribute is added by the gRPC for .NET library. There is a discussion of having the OTel instrumentation remove it.
// See: https://github.com/open-telemetry/opentelemetry-dotnet/issues/482#issuecomment-655753756
Assert.Equal($"0", span.Tags.FirstOrDefault(i => i.Key == "grpc.status_code").Value);
}

private static void WaitForProcessorInvocations(Mock<ActivityProcessor> spanProcessor, int invocationCount)
{
// We need to let End callback execute as it is executed AFTER response was returned.
// In unit tests environment there may be a lot of parallel unit tests executed, so
// giving some breezing room for the End callback to complete
Assert.True(SpinWait.SpinUntil(
() =>
{
Thread.Sleep(10);
return spanProcessor.Invocations.Count >= invocationCount;
},
TimeSpan.FromSeconds(1)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.AspNetCore\OpenTelemetry.Instrumentation.AspNetCore.csproj" />
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Grpc\OpenTelemetry.Instrumentation.Grpc.csproj" />
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Http\OpenTelemetry.Instrumentation.Http.csproj" />
<ProjectReference Include="..\..\src\OpenTelemetry\OpenTelemetry.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using Grpc.Core;
using Microsoft.Extensions.Logging;

namespace OpenTelemetry.Instrumentation.GrpcClient.Tests.Services
namespace OpenTelemetry.Instrumentation.Grpc.Tests.Services
{
public class GreeterService : Greeter.GreeterBase
{
Expand Down