文章目录
-
- 集成SkyWalking实现调用链追踪
-
- [1. SkyWalking架构图](#1. SkyWalking架构图)
- [2. 代码集成SkyWalking](#2. 代码集成SkyWalking)
集成SkyWalking实现调用链追踪
1. SkyWalking架构图
Receiver是SkyWalking的入口,支持gRPC和HTTP协议。
SkyWalking内部有分析和查询两个部分
存储方面SkyWalking支持Elasticsearch和MySql,H2等数据库
2. 代码集成SkyWalking
- 包引用:SkyAPM.Agent.AspNetCore/SkyAPM.Transport.Grpc/SkyAPM.Transport.Grpc.Protocol
- 应用程序根目录放置skyapm.json文件
- 程序环境变量中添加如下代码,
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "SkyAPM.Agent.AspNetCore"
- 部署文件添加环境变量,服务地址
skywalking_hostingStartup=SkyAPM.Agent.AspNetCore
skywalking_servers=172.16.190.168:11800
- deployment.yaml中定义环境变量,读取上述环境标量的值
skyapm.json
{
"SkyWalking": {
"ServiceName": "ordering-api",
"Namespace": "",
"HeaderVersions": [
"sw6"
],
"Sampling": {
"SamplePer3Secs": -1,
"Percentage": -1.0
},
"Logging": {
"Level": "Information",
"FilePath": "logs\\skyapm-{Date}.log"
},
"Transport": {
"Interval": 3000,
"ProtocolVersion": "v6",
"QueueSize": 30000,
"BatchSize": 3000,
"gRPC": {
"Servers": "localhost:11800",
"Timeout": 10000,
"ConnectTimeout": 10000,
"ReportTimeout": 600000
}
}
}
}
默认情况下SkyWalking使用的是本地内存数据库,重启会丢失数据,线上环境建议使用Elasticsearch存储