You need to enable JavaScript to run this app.
Application Performance Management Plus

Application Performance Management Plus

Copy page
Download PDF
Integration guide
Integrate .NET applications with OpenTelemetry
Copy page
Download PDF
Integrate .NET applications with OpenTelemetry
.NET applications have different Methods for integration in various scenarios. This article describes the Actions for integrating .NET applications using OpenTelemetry. After integration, you can automatically collect trace information, automatically generate metric, and use features such as trace search, log search, and more.​
OpenTelemetry is an observability project under CNCF, aiming to provide standardized solutions in the field of observability. It addresses the standardization of data models, collection, processing, and export of observability data, and offers services independent of third-party vendors.​
If your application has already integrated the OpenTelemetry SDK, the APMPlus server side can receive data reported by OpenTelemetry. After integrating with APMPlus, you will gain RED method generation capability, multidimensional trace search, single trace search, topology generation, and more.​
tip​
To isolate production and test data, see Isolate production and test data.​
Limits​
  • There are certain restrictions when converting OpenTelemetry metrics to Prometheus metrics:​
  • Data with aggregation method set to delta is not supported. Do not modify the default aggregation configuration on the SDK side to ensure that the aggregation method on the SDK side is cumulative.​
  • Each workspace has its own data reporting credentials. To manage and isolate data using workspaces, ensure that the apmplus-opentelemetry-collector component has been upgraded to version v3.1.0 or above.​
Data reporting​
Method 1: Report directly to the APMPlus server side​
Observability data is reported directly to the APMPlus server side, supporting data reporting via grpc, http/protobuf, and other Methods.​
Method 2: Otel Collector forwarding [Recommended]​
APMPlusOpenTelemetryCollector is a data collector developed by APMPlus based on OpenTelemetryCollector. You can install the Opentelemetry Collector in the cluster for data forwarding. There are two installation Methods:​
  • Install the apmplus-opentelemetry-collector component via the VKE cluster component center using the one-click installation (also known as blank screen installation). In addition, it is recommended to install the apmplus-server-agent component at the same time to enable metric collection at the host and process levels.​
  • Manually install using the script provided on the service integration page.​
Data Integration​
Method 1: Automatic instrumentation​
  • .NET SDK 6+​
  • .NET Framework does not currently support automatic instrumentation​
  • Supported frameworks​
  1. Develop web applications using ASP.NET Core.​
  1. Create a demo application.​
​
mkdir dotnet-simple-demo​
cd dotnet-simple-demo​
dotnet new web​
​
  1. Replace the contents of the Properties/launchSettings.json file with the following configuration.​
​
{​
"$schema": "http://json.schemastore.org/launchsettings.json",​
"profiles": {​
"http": {​
"commandName": "Project",​
"dotnetRunMessages": true,​
"launchBrowser": true,​
"applicationUrl": "http://localhost:8080",​
"environmentVariables": {​
"ASPNETCORE_ENVIRONMENT": "Development"​
}​
}​
}​
}​
​
  1. Build the application.​
​
dotnet build​
​
  1. Configure automatic instrumentation for the application.​
  1. Unix-shell​
  1. Download and execute the OpenTelemetry .NET automatic instrumentation installation script.​
​
curl -L -O https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/latest/download/otel-dotnet-auto-install.sh​
​
./otel-dotnet-auto-install.sh​
​
  1. Set environment variables and run the OpenTelemetry .NET automatic instrumentation script.​
​
export OTEL_TRACES_EXPORTER=otlp \​
OTEL_METRICS_EXPORTER=otlp \​
OTEL_LOGS_EXPORTER=otlp \​
OTEL_SERVICE_NAME=<service_name> \​
OTEL_EXPORTER_OTLP_PROTOCOL=<protocol> \​
OTEL_EXPORTER_OTLP_ENDPOINT=<apmplus_endpoint> \​
OTEL_EXPORTER_OTLP_HEADERS="x-byteapm-appkey=<app_key>"​
. $HOME/.otel-dotnet-auto/instrument.sh​
​
tip​
  • <service_name> Enter the service name, which will be displayed in the APMPlus service list.​
  • <protocol> It is recommended to use grpc.​
  • <apmplus_endpoint> The address varies depending on region (Shanghai, Beijing, and so on) and network type (public, private). For details, see the APMPlus service access page to obtain the specific endpoint.​
  1. PowerShell​
  1. Download and execute the OpenTelemetry .NET automatic instrumentation installation script.​
​
$module_url = "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/latest/download/OpenTelemetry.DotNet.Auto.psm1"​
$download_path = Join-Path $env:temp "OpenTelemetry.DotNet.Auto.psm1"​
Invoke-WebRequest -Uri $module_url -OutFile $download_path -UseBasicParsing​
​
Import-Module $download_path​
Install-OpenTelemetryCore​
​
  1. Set environment variables and run the OpenTelemetry .NET automatic instrumentation script.​
​
$env:OTEL_TRACES_EXPORTER="otlp"​
$env:OTEL_METRICS_EXPORTER="otlp"​
$env:OTEL_LOGS_EXPORTER="otlp"​
$env:OTEL_EXPORTER_OTLP_PROTOCOL="<protocol>"​
$env:OTEL_EXPORTER_OTLP_ENDPOINT="<apmplus_endpoint>"​
$env:OTEL_EXPORTER_OTLP_HEADERS="x-byteapm-appkey=<app_key>"​
Register-OpenTelemetryForCurrentSession -OTelServiceName "<service_name>"​
​
tip​
  • <service_name> Enter the service name, which will be displayed in the APMPlus service list.​
  • <protocol> It is recommended to use grpc.​
  • <apmplus_endpoint> The address varies depending on region (Shanghai, Beijing, and so on) and network type (public, private). For details, see the APMPlus service access page to obtain the specific endpoint.​
  • <app_key> Enter the app_key provided by the service access console.​
  1. Run and access the application.​
  1. Run the application.​
​
dotnet run​
​
  1. Use the following command to access the application. The generated trace will be automatically uploaded to APMPlus.​
​
curl localhost:8080/​
​
Method 2: Semi-automatic instrumentation​
  • Supported versions:​
  • .NET ≥ 5.0​
  • .NET Core ≥ 2.0​
  • .NET Framework ≥ 4.6.1​
OpenTelemetry supports automatic upload of trace data for dozens of .NET frameworks. For a detailed list of .NET frameworks, see Supported Libraries.​
  1. Create an ASP.NET Core application (web application).​
Replace <your-project-name> with the actual application name.​
​
mkdir <your-project-name>​
cd <your-project-name>​
dotnet new mvc​
​
  1. Download the required OpenTelemetry dependencies for observing .NET applications.​
​
dotnet add package OpenTelemetry.Exporter.Console # 在控制台导出采集的数据​
dotnet add package OpenTelemetry.Extensions.Hosting​
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol # 以OTLP协议导出​
​
  1. Download the automatic instrumentation dependencies.​
Download the dependencies for automatic instrumentation of the ASP.NET Core framework. When the application receives an HTTP request, a Span will be automatically generated and reported. To enable automatic instrumentation for other frameworks, see Supported Libraries to download the corresponding dependencies.​
​
dotnet add package OpenTelemetry.Instrumentation.AspNetCore​
​
  1. Modify the code in the <your-project-name>/Program.cs file.​
  1. Import the required packages at the beginning of the source file.​
​
using System.Diagnostics;​
using OpenTelemetry.Exporter;​
using OpenTelemetry.Resources;​
using OpenTelemetry.Trace;​
​
  1. Add OpenTelemetry initialization code.​
  • Report using the gRPC protocol.​
  • Please replace <grpc_endpoint> and <token> in the following code with the access point information and Token obtained from the prerequisites.​
​
// ...​
builder.Services.AddOpenTelemetry()​
.WithTracing(tracerProviderBuilder =>​
tracerProviderBuilder​
.AddSource(DiagnosticsConfig.ActivitySource.Name)​
.SetResourceBuilder(OpenTelemetry.Resources.ResourceBuilder.CreateDefault()​
.AddAttributes(new Dictionary<string, object> {​
{"service.name", "<service_name>"},​
{"host.name",DiagnosticsConfig.HostName}​
}))​
.AddAspNetCoreInstrumentation()​
.AddConsoleExporter() // Export Trace data in the console (optional)​
.AddOtlpExporter(opt =>​
{​
// Report using the gRPC protocol​
opt.Endpoint = new Uri("<apmplus_endpoint>");​
opt.Headers = "x-byteapm-appkey=<app_key>";​
opt.Protocol = OtlpExportProtocol.Grpc;​
})​
);​
// ...​
​
tip​
  • <service_name> Enter the service name. It will be displayed in the service list of APMPlus.​
  • <apmplus_endpoint> The address varies depending on the region (Shanghai, Beijing, and so on) and network type (public network, private network). For details, go to the apmplus service access page to obtain the specific endpoint.​
  • <app_key> Enter the app_key provided by the service access console.​
  1. Run the following command in the terminal to start the project.​
​
dotnet run​
​
Sample response:​
Obtain the URL from the response information, for example, http://localhost:5107.​
​
Building...​
info: Microsoft.Hosting.Lifetime[14]​
Now listening on: http://localhost:5107​
info: Microsoft.Hosting.Lifetime[0]​
Application started. Press Ctrl+C to shut down.​
info: Microsoft.Hosting.Lifetime[0]​
Hosting environment: Development​
info: Microsoft.Hosting.Lifetime[0]​
Content root path: /path/to/<your-project-name>​
​
  1. Visit http://localhost:5107 in your browser. If the following page is returned, it indicates that the data has been reported to APMPlus.​
​​​
​
Last updated: 2026.06.09 16:53:29