OpenTelemetry.Instrumentation.GrpcNetClient 1.13.0-beta.1
Grpc.Net.Client Instrumentation for OpenTelemetry
| Status | |
|---|---|
| Stability | Beta |
| Code Owners | @open-telemetry/dotnet-contrib-maintainers |
This is an Instrumentation Library which instruments Grpc.Net.Client and collects traces about outgoing gRPC requests.
[!CAUTION] This component is based on the OpenTelemetry semantic conventions for traces. These conventions are in Development, and hence, this package is a pre-release. Until a stable version is released, there can be breaking changes.
Supported .NET Versions
This package targets
NETSTANDARD2.1
and hence can be used in any .NET versions implementing NETSTANDARD2.1.
Steps to enable OpenTelemetry.Instrumentation.GrpcNetClient
Step 1: Install Package
Add a reference to the
OpenTelemetry.Instrumentation.GrpcNetClient
package. Also, add any other instrumentations & exporters you will need.
dotnet add package --prerelease OpenTelemetry.Instrumentation.GrpcNetClient
Step 2: Enable Grpc.Net.Client Instrumentation at application startup
Grpc.Net.Client instrumentation must be enabled at application startup.
The following example demonstrates adding Grpc.Net.Client instrumentation to a
console application. This example also sets up the OpenTelemetry Console
exporter and adds instrumentation for HttpClient, which requires adding the
packages
OpenTelemetry.Exporter.Console
and
OpenTelemetry.Instrumentation.Http
to the application. As Grpc.Net.Client uses HttpClient underneath, it is
recommended to enable HttpClient instrumentation as well to ensure proper
context propagation. This would cause an activity being produced for both a gRPC
call and its underlying HTTP call. This behavior can be
configured.
using OpenTelemetry.Trace;
public class Program
{
public static void Main(string[] args)
{
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation()
.AddConsoleExporter()
.Build();
}
}
For an ASP.NET Core application, adding instrumentation is typically done in
the ConfigureServices of your Startup class. Refer to documentation for
OpenTelemetry.Instrumentation.AspNetCore.
Advanced configuration
This instrumentation can be configured to change the default behavior by using
GrpcClientInstrumentationOptions.
SuppressDownstreamInstrumentation
[!CAUTION]
SuppressDownstreamInstrumentationno longer works when used in conjunction with theOpenTelemetry.Instrumentation.Httppackage version1.6.0and greater. This option may change or even be removed in a future release.
This option prevents downstream instrumentation from being invoked.
Grpc.Net.Client is built on top of HttpClient. When instrumentation for both
libraries is enabled, SuppressDownstreamInstrumentation prevents the
HttpClient instrumentation from generating an additional activity. Additionally,
since HttpClient instrumentation is normally responsible for propagating context
(ActivityContext and Baggage), Grpc.Net.Client instrumentation propagates
context when SuppressDownstreamInstrumentation is enabled.
The following example shows how to use SuppressDownstreamInstrumentation.
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddGrpcClientInstrumentation(
opt => opt.SuppressDownstreamInstrumentation = true)
.AddHttpClientInstrumentation()
.Build();
Enrich
This instrumentation library provides EnrichWithHttpRequestMessage and
EnrichWithHttpResponseMessage options that can be used to enrich the activity
with additional information from the raw HttpRequestMessage and
HttpResponseMessage objects respectively. These actions are called only when
activity.IsAllDataRequested is true. It contains the activity itself (which
can be enriched), the name of the event, and the actual raw object. The
following code snippet shows how to add additional tags using these options.
services.AddOpenTelemetry()
.WithTracing(builder => builder
.AddGrpcClientInstrumentation(options =>
{
options.EnrichWithHttpRequestMessage = (activity, httpRequestMessage) =>
{
activity.SetTag("requestVersion", httpRequestMessage.Version);
};
options.EnrichWithHttpResponseMessage = (activity, httpResponseMessage) =>
{
activity.SetTag("responseVersion", httpResponseMessage.Version);
};
});
Processor,
is the general extensibility point to add additional properties to any activity.
The Enrich option is specific to this instrumentation, and is provided to
get access to HttpRequest and HttpResponse.
References
Showing the top 20 packages that depend on OpenTelemetry.Instrumentation.GrpcNetClient.
| Packages | Downloads |
|---|---|
|
Honeycomb.OpenTelemetry
Honeycomb's OpenTelemetry SDK
|
20 |
|
Honeycomb.OpenTelemetry
Honeycomb's OpenTelemetry SDK
|
21 |
|
Honeycomb.OpenTelemetry
Honeycomb's OpenTelemetry SDK
|
22 |
|
Honeycomb.OpenTelemetry
Honeycomb's OpenTelemetry SDK
|
23 |
|
Honeycomb.OpenTelemetry
Honeycomb's OpenTelemetry SDK
|
24 |
|
Honeycomb.OpenTelemetry
Honeycomb's OpenTelemetry SDK
|
25 |
|
Honeycomb.OpenTelemetry
Honeycomb's OpenTelemetry SDK
|
26 |
|
Honeycomb.OpenTelemetry
Honeycomb's OpenTelemetry SDK
|
27 |
|
Honeycomb.OpenTelemetry
Honeycomb's OpenTelemetry SDK
|
28 |
.NET 8.0
- OpenTelemetry (>= 1.13.1 && < 2.0.0)
.NET Standard 2.0
- OpenTelemetry (>= 1.13.1 && < 2.0.0)
.NET Standard 2.1
- OpenTelemetry (>= 1.13.1 && < 2.0.0)
| Version | Downloads | Last updated |
|---|---|---|
| 1.13.0-beta.1 | 2 | 10/24/2025 |
| 1.12.0-beta.1 | 12 | 05/06/2025 |
| 1.11.0-beta.2 | 15 | 03/16/2025 |
| 1.11.0-beta.1 | 20 | 01/31/2025 |
| 1.10.0-beta.1 | 21 | 12/31/2024 |
| 1.9.0-beta.1 | 32 | 11/16/2024 |
| 1.8.0-beta.1 | 27 | 05/25/2024 |
| 1.7.0-beta.1 | 23 | 05/25/2024 |
| 1.6.0-beta.3 | 21 | 05/25/2024 |
| 1.6.0-beta.2 | 23 | 05/25/2024 |
| 1.5.1-beta.1 | 25 | 05/25/2024 |
| 1.5.0-beta.1 | 28 | 05/25/2024 |
| 1.0.0-rc9.14 | 22 | 05/25/2024 |
| 1.0.0-rc9.13 | 26 | 05/25/2024 |
| 1.0.0-rc9.12 | 23 | 05/25/2024 |
| 1.0.0-rc9.11 | 25 | 05/25/2024 |
| 1.0.0-rc9.10 | 23 | 05/25/2024 |
| 1.0.0-rc9.9 | 25 | 05/25/2024 |
| 1.0.0-rc9.8 | 27 | 05/25/2024 |
| 1.0.0-rc9.7 | 22 | 05/25/2024 |
| 1.0.0-rc9.6 | 25 | 05/25/2024 |
| 1.0.0-rc9.5 | 24 | 05/25/2024 |
| 1.0.0-rc9.4 | 25 | 05/25/2024 |
| 1.0.0-rc9.3 | 24 | 05/25/2024 |
| 1.0.0-rc9.2 | 22 | 05/25/2024 |
| 1.0.0-rc9.1 | 31 | 05/25/2024 |
| 1.0.0-rc9 | 18 | 05/25/2024 |
| 1.0.0-rc8 | 18 | 05/25/2024 |
| 1.0.0-rc7 | 23 | 05/25/2024 |
| 1.0.0-rc6 | 21 | 05/25/2024 |
| 1.0.0-rc5 | 22 | 05/25/2024 |
| 1.0.0-rc4 | 22 | 05/25/2024 |
| 1.0.0-rc3 | 21 | 05/25/2024 |
| 1.0.0-rc2 | 27 | 05/25/2024 |
| 1.0.0-rc1.1 | 24 | 05/25/2024 |
| 0.8.0-beta.1 | 25 | 05/25/2024 |
| 0.7.0-beta.1 | 27 | 05/25/2024 |
| 0.6.0-beta.1 | 31 | 05/25/2024 |
| 0.5.0-beta.2 | 23 | 05/25/2024 |