NetCore 3.1集成SkyApm

开发环境:Net Core 3.1、webapi

发布环境:Centos7.x、Rancher2.x、Docker

 

操作步骤:

1、在应用程序中Nuget程序包:SkyAPM.Agent.AspNetCore    v0.9.0

2、在Startup中的ConfigureServices方法中添加注入

services.AddSkyApmExtensions();

3、根目录添加skyapm.json文件,内如如下:

{
  "SkyWalking": {
    "ServiceName": "Elaotech_Parking_PayGateway", //服务名称
    "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": "127.0.0.1:11800", //Skywalking服务地址,生产环境替需替换成生产skyapm发布后的地址
        "Timeout": 10000,
        "ConnectTimeout": 10000,
        "ReportTimeout": 600000
      }
    }
  }
}

4、添加Dockerfile文件,内容如下:

FROM mcr.microsoft.com/dotnet/core/runtime:3.1
WORKDIR /app
COPY . .
RUN sed -i 's/TLSv1.2/TLSv1.0/g' /etc/ssl/openssl.cnf
ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=SkyAPM.Agent.AspNetCore
ENV SKYWALKING__SERVICENAME=Elaotech_Parking_PayGateway
ENTRYPOINT ["dotnet", "Elaotech.Parking.PayGateway.dll"]

核心是里面的两个ENV变量及内容,一个是skyapm包名,一个是服务名称。

5、本地运行需在launchSettings.json文件中的environmentVariables节点下添加系统变量,内容如下:

"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "SkyAPM.Agent.AspNetCore",
"SKYWALKING__SERVICENAME": "Elaotech_Parking_PayGateway"

6、发布生产环境build打包上传,Rancher重新启动服务节点。

 

posted @ 2020-05-08 09:57  Anybt  阅读(995)  评论(9编辑  收藏  举报