opentelemetry-dotnet/src/OpenTelemetry.Instrumentati.../README.md

2.6 KiB

Grpc.Net.Client Instrumentation for OpenTelemetry

NuGet NuGet

This is an Instrumentation Library which instruments Grpc.Net.Client and collects telemetry about outgoing gRPC requests.

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 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, which requires adding the package OpenTelemetry.Exporter.Console to the application.

using OpenTelemetry.Trace;

public class Program
{
    public static void Main(string[] args)
    {
        using Sdk.CreateTracerProviderBuilder()
            .AddGrpcClientInstrumentation()
            .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.

For an ASP.NET application, adding instrumentation is typically done in the Global.asax.cs. Refer to documentation for OpenTelemetry.Instrumentation.AspNet.

References