OTel for .NET
In this guide, we will walk you through the process of setting up and using OpenTelemetry in .NET. You will learn how to instrument a simple .Net. application to produce traces, metrics, and logs and export them to KloudMate.
Step 1: Prerequisites
Before diving into OpenTelemetry, be sure that you have the following installed:
Step 2: Example Application
If you already have a .NET application and don't need to create one from scratch, you can directly jump to the Instrumentation part of this guide.
For this tutorial, we will be using a basic Minimal API with ASP.NET Core application. However, OpenTelemetry .Net is compatible with other web frameworks as well. Feel free to adapt the instructions to your preferred framework.
Step 3: Installation
- Set up an environment in a new directory called dotnet-simple. Run the following command within this directory.
2. Within the same directory, replace the content of Program.cswith the following code
3. In the Properties subdirectory, replace the content of launchSettings.json with the following:
4. Run the application using the following command then open http://localhost:8080/rolldice in your web browser:
Step 4: Instrumentation
To install the instrumentation packages, we will use the NuGet packages from OpenTelemetry. These packages will automatically generates telemetry data. 1. Add the packages
2. In Program.cs, replace the following lines:
With:
Step 5: Run the Instrumented App
1. Run the instrumented application
Note the output from the dotnet run.
2. From another terminal send a request using curl:
Source URL for the example application: https://opentelemetry.io/docs/instrumentation/net/getting-started/