Getting Started - open-telemetry/opentelemetry-dotnet

Getting Started with OpenTelemetry.NET

OpenTelemetry is an observability framework that helps generate and collect application telemetry data such as metrics, logs, and traces. The .NET implementation of OpenTelemetry, opentelemetry-dotnet, provides support for tracing, metrics, and logs. This guide will walk you through setting up logging, metrics, and traces using various components and options available in opentelemetry-dotnet.

Prerequisites

  • Familiarity with the .NET programming language and .NET ecosystem
  • A text editor or IDE for writing .NET code

Installation

To install OpenTelemetry.NET components, use the NuGet package manager and add the necessary packages to your .NET project. The OpenTelemetry.NET documentation provides a list of supported libraries and frameworks, including .NET Core, .NET Framework 3.5 SP1, and ASP.NET Core.

For example, to install OpenTelemetry for an ASP.NET Core application, execute the following commands:

dotnet add package OpenTelemetry
dotnet add package OpenTelemetry.Extensions.Hosting
dotnet add package OpenTelemetry.Exporter.Console
dotnet add package OpenTelemetry.Instrumentation.AspNetCore --prerelease
dotnet add package OpenTelemetry.Instrumentation.Http --prerelease

Exporters

OpenTelemetry data needs to be exported to a backend or an OpenTelemetry Collector for visualization and analysis. Opentelemetry-dotnet provides various exporters, including OpenTelemetry Protocol (OTLP), Jaeger, Zipkin, Prometheus, and vendor-specific backends.

The OpenTelemetry.NET exporters documentation explains how to set up exporters for OTLP and other common protocols.

Automatic Instrumentation

OpenTelemetry.NET offers automatic instrumentation for various libraries and frameworks. The Automatic Instrumentation documentation provides more information on using this feature.

To enable automatic instrumentation and see telemetry directly on the standard output, set the following environment variables to true before launching your application:

  • OTEL_DOTNET_AUTO_LOGS_CONSOLE_EXPORTER_ENABLED
  • OTEL_DOTNET_AUTO_METRICS_CONSOLE_EXPORTER_ENABLED
  • OTEL_DOTNET_AUTO_TRACES_CONSOLE_EXPORTER_ENABLED

Manual Instrumentation

For manual instrumentation, use the OpenTelemetry Tracing and Metrics APIs. The Manual Instrumentation documentation provides more information on using these APIs.

For example, to instrument inbound and outbound requests from an ASP.NET Core app, follow the instructions in the OpenTelemetry.NET libraries documentation.

Community and Support

OpenTelemetry is an open-source project with an active community. To learn more, connect with the community, or contribute, visit the OpenTelemetry Community page.

For additional resources and documentation, visit the following links: