All Products
Search
Document Center

Managed Service for OpenTelemetry:Use SkyWalking to report .NET application data

Last Updated:Sep 28, 2023

Before you can view the trace data of your application, you must use a client to report the trace data to the Managed Service for OpenTelemetry console. This topic describes how to use SkyWalking .NET Core SDK to report .NET application data.

Prerequisites

To obtain an endpoint of SkyWalking, perform the following steps:

  1. Log on to the Managed Service for OpenTelemetry console.

  2. In the left-side navigation pane, click Cluster Configurations. Then, click the Access point information tab.

  3. In the top navigation bar, select a region. In the Cluster Information section, turn on Show Token.

  4. In the Client section, click SkyWalking.

    Obtain an endpoint of SkyWalking in the Related Information column of the table in the lower part.

    SkyWalking接入点信息
    Note

    If your application is deployed in an Alibaba Cloud production environment, use a VPC endpoint. Otherwise, use a public endpoint.

Background information

SkyWalking is a popular application performance monitoring (APM) service developed in China. SkyWalking is designed for microservices, cloud-native architectures, and container-based architectures such as Docker, Kubernetes, and Mesos. SkyWalking is also a distributed tracing system.

Sample code

For more information about the sample code repository, see skywalking-demo at GitHub.

Use SkyWalking to instrument a .NET application

  1. Install the .NET agent.

    Go to the root directory of the .NET project and run the following commands:

    # Install the .NET agent.
    dotnet add package SkyAPM.Agent.AspNetCore
    
    # Add environment variables.
    export ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=SkyAPM.Agent.AspNetCore
    export SKYWALKING__SERVICENAME=<service-name>
  2. Configure the parameters of the .NET agent.

    Generate the skyapm.json file.

    • Method 1: Use SkyAPM.DotNet.CLI to generate the skyapm.json file.

    • dotnet tool install -g SkyAPM.DotNet.CLI
      
      # Configure environment variables. Replace /path/to with the actual path of the .dotnet directory.
      export PATH="$PATH:/path/to/.dotnet/tools/"             
      dotnet skyapm config <service-name> <endpoint>
    • Method 2: Create the skyapm.json file in the root directory of the .NET project and copy the following content to the file:

    • {
        "SkyWalking": {
          "ServiceName": <service-name>,
          "Namespace": "",
          "HeaderVersions": [
            "sw8"
          ],
          "Sampling": {
            "SamplePer3Secs": -1,            
            "Percentage": -1.0,
            "LogSqlParameterValue": false
          },
          "Logging": {
            "Level": "Information",
            "FilePath": "logs/skyapm-{Date}.log"
          },
          "Transport": {
            "Interval": 3000,
            "ProtocolVersion": "v8",
            "QueueSize": 30000,
            "BatchSize": 3000,
            "gRPC": {
              "Servers": <endpoint>,
              "Authentication": <token>,
              "Timeout": 100000,
              "ConnectTimeout": 100000,
              "ReportTimeout": 600000
            }
          }
        }
      }

    Parameter description

    • Required parameters

      • <service-name>: the application name.

      • <endpoint>: the endpoint that you obtained in the "Prerequisites" section.

      • <token>: the authentication token that you obtained in the "Prerequisites" section.

    • Optional parameters

      • SamplePer3Secs: the number of samples per three seconds.

      • Percentage: the sampling percentage. For example, set this parameter to 10 if the sampling percentage is 10%.

      • Logging: the logging information used for debugging. Level specifies the log level. FilePath specifies the path and name of the log file.

  3. Restart the .NET project.

    dotnet run
  1. View the local log entries of the .NET agent. When the .NET project runs, the skyapm-<date>.log file is generated in the logs folder of the .NET project. If the trace data fails to be reported, you can refer to the skyapm-<date>.log file for debugging.

    image.png

Appendix

You can run the following commands to build the .NET agent based on the source code:

# Download the source code.
git clone https://github.com/SkyAPM/SkyAPM-dotnet.git

# Go to the root directory.
cd SkyAPM-dotnet/

# Switch to the destination tag.
git checkout [tagname]

git submodule init
git submodule update

dotnet restore

dotnet build src/SkyApm.Transport.Grpc.Protocol
dotnet build skyapm-dotnet.sln

FAQ

When I use the dotnet-skyapm tool to create the skyapm.json file, the creation fails and the error message shown in the following figure is returned. What do I do?image.png

  • Solution 1 (recommended): The dotnet-skyapm tool is used only to generate the skyapm.json file for the skyapm-dotnet agent. You can manually create the skyapm.json file and configure relevant parameters by referring to the preceding sections.

  • Solution 2: Use dotnet 6.0.