Setelah Anda menginstrumen sebuah aplikasi menggunakan SkyWalking dan melaporkan data jejaknya ke Managed Service for OpenTelemetry, Managed Service for OpenTelemetry mulai memantau aplikasi tersebut. Anda dapat melihat serangkaian data pemantauan, seperti topologi aplikasi, jejak panggilan, transaksi pengecualian, transaksi lambat, dan analisis SQL. Topik ini menjelaskan cara menggunakan SkyWalking .NET Core SDK untuk menginstrumen aplikasi dan melaporkan datanya.
Prasyarat
Informasi latar belakang
SkyWalking adalah alat open-source untuk Pemantauan Kinerja Aplikasi (APM) yang dirancang untuk arsitektur layanan mikro, cloud-native, dan berbasis kontainer seperti Docker, Kubernetes, dan Mesos. Inti dari SkyWalking adalah sistem pelacakan terdistribusi.
Demo contoh
Untuk contoh lengkap yang berfungsi, lihat repositori SkyWalking Demo.
Instrumen aplikasi .NET dengan SkyWalking
-
Instal agen .NET.
Buka direktori root proyek Anda dan jalankan perintah berikut.
# Install the .NET Agent dotnet add package SkyAPM.Agent.AspNetCore # Add environment variables export ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=SkyAPM.Agent.AspNetCore export SKYWALKING__SERVICENAME=<service-name> -
Konfigurasikan properti agen .NET.
Buat file
skyapm.jsonmenggunakan salah satu metode berikut.-
Metode 1: Gunakan tool SkyAPM.DotNet.CLI untuk menghasilkan file konfigurasi properti.
dotnet tool install -g SkyAPM.DotNet.CLI # Set the environment variable. Replace /path/to with the path to your .dotnet/tools directory. export PATH="$PATH:/path/to/.dotnet/tools/" dotnet skyapm config <service-name> <endpoint>Metode 2: Buat file
skyapm.jsondi direktori root proyek Anda dan salin konten berikut ke dalam file tersebut.{ "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
-
Parameter wajib
-
<service-name>: Nama layanan. -
<endpoint>: Titik akhir yang diperoleh di bagian "Prasyarat". -
<token>: Token otentikasi untuk titik akhir tersebut. Dapatkan token ini seperti yang dijelaskan di bagian "Prasyarat".
-
-
Parameter opsional
-
SamplePer3Secs: Jumlah sampel yang dikumpulkan setiap tiga detik. -
Percentage: Persentase pengambilan sampel. Misalnya, untuk mengambil sampel 10% dari jejak, atur nilai ini menjadi 10. -
Logging: Mengonfigurasi logging dan debugging.Levelmenentukan tingkat log, danFilePathmenentukan lokasi serta nama file log.
-
-
-
Jalankan ulang proyek .NET Anda.
dotnet run
-
Periksa log agen lokal. Saat Anda menjalankan proyek, file
skyapm-<date>.logakan dibuat di folderlogs. Jika pelaporan data gagal, Anda dapat menggunakan file log ini untuk melakukan debug.2023-07-27 10:04:08.396 +08:00 [skywalking-net-demo] [Information] SkyApm.InstrumentStartup : Initializing ... 2023-07-27 10:04:08.477 +08:00 [skywalking-net-demo] [Information] SkyApm.Service.RegisterService : Loaded instrument service [Skyxxx] 2023-07-27 10:04:08.477 +08:00 [skywalking-net-demo] [Information] SkyApm.Service.LogReportService : Loaded instrument service [Skxxx] 2023-07-27 10:04:08.477 +08:00 [skywalking-net-demo] [Information] SkyApm.Service.PingService : Loaded instrument service [SkyApm.xxx] 2023-07-27 10:04:08.477 +08:00 [skywalking-net-demo] [Information] SkyApm.Service.SegmentReportService : Loaded instrument servicexxx 2023-07-27 10:04:08.477 +08:00 [skywalking-net-demo] [Information] SkyApm.Service.CLRStatsService : Loaded instrument service [Skyxxx] 2023-07-27 10:04:08.477 +08:00 [skywalking-net-demo] [Information] SkyApm.Sampling.SimpleCountSamplingInterceptor : Loaded instruxxx 2023-07-27 10:04:08.477 +08:00 [skywalking-net-demo] [Information] SkyApm.Transport.Grpc.ConnectService : Loaded instrument servicxxx 2023-07-27 10:04:08.486 +08:00 [skywalking-net-demo] [Information] SkyApm.Transport.Grpc.ConnectionManager : Connected server[tracixxx] 2023-07-27 10:04:08.486 +08:00 [skywalking-net-demo] [Information] SkyApm.Diagnostics.TracingDiagnosticProcessorObserver : Loaded dxxx 2023-07-27 10:04:08.486 +08:00 [skywalking-net-demo] [Information] SkyApm.InstrumentStartup : Started SkyAPM .NET Core Agent. 2023-07-27 10:04:13.512 +08:00 [skywalking-net-demo] [Information] SkyApm.Diagnostics.TracingDiagnosticProcessorObserver : Loaded dxxx 2023-07-27 10:04:13.552 +08:00 [skywalking-net-demo] [Information] SkyApm.Diagnostics.TracingDiagnosticProcessorObserver : Loaded dxxx 2023-07-27 10:04:13.605 +08:00 [skywalking-net-demo] [Information] SkyApm.Service.RegisterService : Reported Service Instance Propexxx 2023-07-27 10:04:20.525 +08:00 [skywalking-net-demo] [Information] SkyApm.Transport.Grpc.V8.SegmentReporter : Report 14 trace segmexxx 2023-07-27 10:04:20.534 +08:00 [skywalking-net-demo] [Error] SkyApm.Transport.Grpc.SegmentReporter : Report trace segment fail. Grpc.Core.RpcException: Status(StatusCode="Unimplemented", Detail="Method not found: skywalking.v3.LogReportService/collect") at SkyApm.Transport.Grpc.LoggerReporter.ReportAsync(IReadOnlyCollection`1 loggerRequests, CancellationToken cancellationToken)
Referensi
Untuk membuat agen dari kode sumber, jalankan perintah berikut.
# Download the source code
git clone https://github.com/SkyAPM/SkyAPM-dotnet.git
# Enter the root directory
cd SkyAPM-dotnet/
# Switch to the target 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
Galat dapat terjadi saat menjalankan perintah dotnet skyapm config jika versi framework .NET yang diperlukan belum diinstal.
dotnet skyapm config net-app 192.168.0.1:11800
You must install or update .NET to run this application.
App: /Users/whlongxi/.dotnet/tools/dotnet-skyapm
Architecture: arm64
Framework: 'Microsoft.NETCore.App', version '6.0.0' (arm64)
.NET location: /usr/local/share/dotnet
The following frameworks were found:
7.0.9 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.0&arch=arm64&rid=osx.13-arm64
-
Solusi 1 (Direkomendasikan): Tool
dotnet-skyapmhanya menghasilkan file konfigurasiskyapm.json. Anda dapat membuat dan mengonfigurasi file ini secara manual seperti yang dijelaskan di atas. -
Solusi 2: Gunakan .NET 6.0.

