Reporting .NET Application Data Using OpenTelemetry
Huawei Cloud APM is compatible with OpenTelemetry and can directly receive the trace data reported using the OpenTelemetry SDK or Agent. This section describes how to use OpenTelemetry to connect a .NET application to APM and report trace data.
Constraint
.NET SDK 8 or later must be used.
Environment Preparation
- Prepare .NET SDK 8.
- Run the installation command:
sudo apt-get update && sudo apt-get install -y dotnet-sdk-8.0
- Verify the environment:
dotnet --version
Demo
- Initialize the application:
dotnet new web
- Replace the content in the Program.cs file in the current directory with the following content:
using System.Globalization; var builder = WebApplication.CreateBuilder(args); var app = builder.Build(); var logger = app.Logger; int RollDice() { return Random.Shared.Next(1, 7); } string HandleRollDice(string? player) { var result = RollDice(); if (string.IsNullOrEmpty(player)) { logger.LogInformation("Anonymous player is rolling the dice: {result}", result); } else { logger.LogInformation("{player} is rolling the dice: {result}", player, result); } return result.ToString(CultureInfo.InvariantCulture); } app.MapGet("/rolldice/{player?}", HandleRollDice); app.Run(); - Replace the content in the launchSettings.json file in the Properties directory with the following content:
{ "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { "http": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "http://localhost:8080", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } } - Build and run the demo application in the directory where Program.cs is stored:
dotnet build dotnet run curl http://localhost:8080/rolldice
Non-Intrusive Access
- Install the dependencies for auto tracking:
curl -L -O https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/latest/download/otel-dotnet-auto-install.sh chmod +x otel-dotnet-auto-install.sh ./otel-dotnet-auto-install.sh
- Add environment variables:
export OTEL_TRACES_EXPORTER=otlp \ OTEL_EXPORTER_OTLP_PROTOCOL=grpc \ OTEL_METRICS_EXPORTER=none \ OTEL_LOGS_EXPORTER=none \ OTEL_SERVICE_NAME=Application.Component.Environment \ OTEL_EXPORTER_OTLP_ENDPOINT=Access address \ OTEL_EXPORTER_OTLP_HEADERS="Authentication=Authentication information" . $HOME/.otel-dotnet-auto/instrument.sh
- Run the demo application:
dotnet run & curl http://localhost:8080/rolldice

- Log in to the APM console.
- Click
on the left and choose Management & Governance > Application Performance Management. - In the navigation pane, choose Link Trace > Metrics.
- In the tree on the left, locate an environment and then go to the URL tab page to view the URL calling data.
- In the navigation pane, choose Link Trace > Tracing.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot